summarylogtreecommitdiffstats
path: root/oem.sh
blob: 840efbd10d6173403a58f2111d43a87572a2d9ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh

METADATA_URL=http://169.254.169.254/latest/meta-data

r3_logger() {
  logger -t remoteit "$@"
}

r3_get_architecture() {
  if [ -n "$R3_ARCHITECTURE" ]; then
    echo $R3_ARCHITECTURE
  else
    uname -m
  fi
}

r3_is_ec2() {
  curl -s -f -m 1 $METADATA_URL > /dev/null
  echo $?
}

isEc2=$(r3_is_ec2)

r3_get_name() {
  if [ -n "$R3_DEVICE_NAME" ]; then
    echo $R3_DEVICE_NAME
  elif [ "$isEc2" -eq 0 ]; then
    curl -s $METADATA_URL/instance-id | sed -e 's/-//g'
  else
    cat /proc/sys/kernel/hostname
  fi
}

r3_get_macaddr() {
  if [ "$isEc2" -eq 0 ]; then
    curl -s $METADATA_URL/mac
  else
    ip link show up | grep ether | head -n 1 | awk '{print $2}'
  fi
}

r3_get_model() {
  if [ "$isEc2" -eq 0 ]; then
    curl -s $METADATA_URL/instance-type | sed -e 's/\.//g'
  elif [ -r /sys/devices/virtual/dmi/id/product_family ]; then
    cat /sys/devices/virtual/dmi/id/product_family
  else
    echo NOT_DETECTED
  fi
}

r3_get_serial() {
  if [ "$isEc2" -eq 0 ]; then
    curl -s $METADATA_URL/instance-id | sed -e 's/-//g'
  elif [ -r /sys/devices/virtual/dmi/id/product_serial ]; then
    cat /sys/devices/virtual/dmi/id/product_serial
  else
    echo NOT_DETECTED
  fi
}

r3_get_identity() {
  r3_get_macaddr
}

r3_get_manufacturer() {
  echo 34304
}

r3_get_platform() {
  if [ -n "$R3_PLATFORM_CODE" ]; then
    platformcode=$R3_PLATFORM_CODE
    echo $platformcode
  elif [ "$isEc2" -eq 0 ]; then
    echo 1185
  else
    echo 769
  fi
}

r3_get_metadata() {
  jq -n \
    --arg version "$VERSION" \
    --arg installDir "$REMOTEIT_DIR" \
    --arg macAddress "$(r3_get_macaddr)" \
    --arg model "$(r3_get_model)" \
    --arg serialNum "$(r3_get_serial)" \
    '{$version, $installDir, $macAddress, $model, $serialNum}'
}