|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# remote.it OEM Settings manages remote.it settings to register OEM devices |
| 4 | +# |
| 5 | +# not called directly. functions are called by connectd_control |
| 6 | +# |
| 7 | +# will store info in CONNECTD_DIR |
| 8 | +# |
| 9 | +# remot3.it, Inc. : https://remote.it |
| 10 | +# |
| 11 | + |
| 12 | +oemGetSystemId() |
| 13 | +{ |
| 14 | + |
| 15 | +cpuid=$(awk '/Serial/ {print $3}' /proc/cpuinfo | sed 's/://g') |
| 16 | + |
| 17 | +## |
| 18 | +## Override default system ID for this platform |
| 19 | +#cpuid=$(oemGetDefaultHardwareId) |
| 20 | + |
| 21 | +# check for legal value |
| 22 | +if [ ${#cpuid} -ge 1 ]; then |
| 23 | + continue |
| 24 | +else |
| 25 | + echo "" |
| 26 | + echo "ACTION: system ID is not set properly. Fix oemGetSystemId() in /etc/connectd/oem_settings " |
| 27 | +fi |
| 28 | + |
| 29 | +# return the System ID |
| 30 | +echo $cpuid |
| 31 | + |
| 32 | +} |
| 33 | + |
| 34 | +oemGetDefaultHardwareId() |
| 35 | +{ |
| 36 | + |
| 37 | +# |
| 38 | +# This method gets the hardware ID based on the default LAN MAC address |
| 39 | +# You can overide the network interface below for a custom configuration for your platform |
| 40 | + |
| 41 | +# get the default interface |
| 42 | +interface=$(oemGetInterface) |
| 43 | + |
| 44 | +## |
| 45 | +## Override the default interface - change and uncomment the assignment below |
| 46 | +## RPi interfaces: eth0, wlan0 |
| 47 | +## Ubuntu interfaces: enp3s0 wlp2s0 |
| 48 | +#interface='eth0' |
| 49 | +#interface='enp3s0' |
| 50 | + |
| 51 | +# get the adapter MAC |
| 52 | +if [ -f "/sys/class/net/$interface/address" ]; then |
| 53 | + hw_mac=$(cat /sys/class/net/$interface/address | sed 's/://g') |
| 54 | +else |
| 55 | + echo "ACTION: hardware ID is not set properly. Fix oemGetDefaultHardwareId() in /etc/connectd/oem_settings " |
| 56 | +fi |
| 57 | + |
| 58 | +echo $hw_mac |
| 59 | + |
| 60 | +} |
| 61 | + |
| 62 | +oemGetDefaultRegistrationKey() |
| 63 | +{ |
| 64 | + |
| 65 | +## |
| 66 | +## Override the default interface - change the assignment below |
| 67 | +## RPi interfaces: eth0, wlan0 |
| 68 | +## Ubuntu interfaces: enp3s0 wlp2s0 |
| 69 | + |
| 70 | +## must be set to something for your platform - default is for RPi |
| 71 | +interface='wlan0' |
| 72 | +#interface='wlp2s0' |
| 73 | + |
| 74 | +# get the adapter MAC |
| 75 | +if [ -f "/sys/class/net/$interface/address" ]; then |
| 76 | + rk_mac=$(cat /sys/class/net/$interface/address | sed 's/://g') |
| 77 | +else |
| 78 | + echo "ACTION: registration key is not set properly. Fix oemGetDefaultRegistrationKey() in /etc/connectd/oem_settings " |
| 79 | +fi |
| 80 | + |
| 81 | +echo $rk_mac |
| 82 | + |
| 83 | +} |
| 84 | + |
| 85 | +oemGetTCPServices() |
| 86 | +{ |
| 87 | + |
| 88 | + tcp=$(netstat -antp 2>/dev/null | grep 0.0.0.0: | awk '{ print $4 }' | awk -F':' '{print $2}' | xargs | sed -e 's/ /,/g') |
| 89 | + |
| 90 | + echo $tcp |
| 91 | + |
| 92 | +} |
| 93 | + |
| 94 | +oemGetOSLabel() |
| 95 | +{ |
| 96 | + |
| 97 | +# return the OS label |
| 98 | +os=$(uname -a) |
| 99 | +echo $os |
| 100 | + |
| 101 | +} |
| 102 | + |
| 103 | +oemGetInterface() |
| 104 | +{ |
| 105 | + |
| 106 | +# |
| 107 | +# This method returns the default interface use for grabbing the hardware ID MAC address. |
| 108 | +# |
| 109 | + |
| 110 | +# host we want to "reach" |
| 111 | +host=google.com |
| 112 | + |
| 113 | +# get the ip of that host (works with dns and /etc/hosts. In case we get |
| 114 | +# multiple IP addresses, we just want one of them |
| 115 | +host_ip=$(getent ahosts "$host" | awk '{print $1; exit}') |
| 116 | + |
| 117 | +# only list the interface used to reach a specific host/IP. We only want the part |
| 118 | +# between dev and src (use grep for that) |
| 119 | +interface=$(ip route get "$host_ip" | grep -Po '(?<=(dev )).*(?= src| proto)' | awk '{print $1; exit}') |
| 120 | + |
| 121 | +echo $interface |
| 122 | + |
| 123 | +} |
| 124 | + |
| 125 | +oemGetWebPath() |
| 126 | +{ |
| 127 | + |
| 128 | +# return the default web path. Override if different |
| 129 | +echo /var/www/html |
| 130 | + |
| 131 | +} |
| 132 | + |
| 133 | +# |
| 134 | +# Hook for OEM to add a function to save configuration changes |
| 135 | +# OEM must add the file in $BIN_DIR, called connectd_save_config |
| 136 | +# it must be set to be executable (chmod +x) |
| 137 | +# |
| 138 | + |
| 139 | +oemSaveConfig() |
| 140 | +{ |
| 141 | +# hook for OEM to add platform specific call to save configuration changes |
| 142 | + if [ -e "$BIN_DIR"/connectd_save_config ]; then |
| 143 | + "$BIN_DIR"/connectd_save_config |
| 144 | + fi |
| 145 | +} |
0 commit comments