Adding a simple script to register a new device (MAC, IP, key, and device name)
authorrtrimana <rtrimana@uci.edu>
Wed, 5 Apr 2017 16:04:43 +0000 (09:04 -0700)
committerrtrimana <rtrimana@uci.edu>
Wed, 5 Apr 2017 16:04:43 +0000 (09:04 -0700)
benchmarks/other/OpenWrt/README [new file with mode: 0644]
benchmarks/other/OpenWrt/devices.dat [new file with mode: 0644]
benchmarks/other/OpenWrt/register_device.sh [new file with mode: 0755]

diff --git a/benchmarks/other/OpenWrt/README b/benchmarks/other/OpenWrt/README
new file mode 100644 (file)
index 0000000..129e2f3
--- /dev/null
@@ -0,0 +1,19 @@
+Device registration utility for Sentinel system
+This is a simple script that register a new device
+into /etc/config/dhcp and /etc/hostapd-psk
+Copyright (c) 2015-2017, Rahmadi Trimananda <rtrimana@uci.edu> PLRG@UCIrvine
+
+Usage:
+       ./register_device.sh [-h]
+       ./register_device.sh [-a <mac-address> <ip-address> <key> <device-name>]
+       ./register_device.sh [-l]
+
+Options:
+       -h      show this usage
+       -a      adding device by putting MAC address, desired IP address, key, and device name (optional)
+       -l      show list of devices registered
+
+
+Notes:
+- This simple script now only adds device information (no delete feature)
+- Meant to ease the setup process (mimicking production environment)
diff --git a/benchmarks/other/OpenWrt/devices.dat b/benchmarks/other/OpenWrt/devices.dat
new file mode 100644 (file)
index 0000000..ffea2e2
--- /dev/null
@@ -0,0 +1,2 @@
+12:32:34:45:56:67      192.168.2.123   mydevice
+12:32:34:45:56:67      192.168.2.123   mydevice
diff --git a/benchmarks/other/OpenWrt/register_device.sh b/benchmarks/other/OpenWrt/register_device.sh
new file mode 100755 (executable)
index 0000000..193381b
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# Print usage
+if [ "$#" -eq 0 ] || [ "$1" == "-h" ]; then
+       echo "Device registration utility for Sentinel system"
+       echo "This is a simple script that register a new device"
+       echo "into /etc/config/dhcp and /etc/hostapd-psk"
+       echo "Copyright (c) 2015-2017, Rahmadi Trimananda <rtrimana@uci.edu> PLRG@UCIrvine"
+       echo ""
+       echo "Usage:"
+       echo "  ./register_device.sh [-h]"
+       echo "  ./register_device.sh [-a <mac-address> <ip-address> <key> <device-name>]"
+       echo "  ./register_device.sh [-l]"
+       echo ""
+       echo "Options:"
+       echo "  -h      show this usage"
+       echo "  -a      adding device by putting MAC address, desired IP address, key, and device name (optional)"
+       echo "  -l      show list of devices registered"
+       echo ""
+
+elif [ "$1" == "-a" ]; then
+
+       if [ "$2" == "" ] || [ "$3" == "" ] || [ "$4" == "" ]; then
+               echo "Empty or incomplete parameters! Please run ./register_device.sh -h for usage."
+       else
+               # Add a new device
+               MAC=$2
+               IP=$3
+               KEY=$4
+
+               # Keep a local log
+               echo "$MAC      $IP     $KEY    $5" >> devices.dat
+
+               # Insert into /etc/hostapd-psk
+               echo "$MAC $KEY" >> /etc/hostapd-psk
+
+               # Insert into /etc/config/dhcp
+               echo "" >> /etc/config/dhcp
+               if [ "$5" != "" ]; then # If device-name is not empty
+                       echo "# $5" >> /etc/config/dhcp
+               fi
+               echo "config host" >> /etc/config/dhcp
+               echo "  option ip '$IP'" >> /etc/config/dhcp
+               echo "  option mac '$MAC'" >> /etc/config/dhcp
+
+               if [ "$5" != "" ]; then # If device-name is not empty
+                       echo "  option name '$5'" >> /etc/config/dhcp
+               fi
+               echo "Device added!"
+       fi
+                                                 
+elif [ "$1" == "-l" ]; then
+       # Print list of devices
+       echo "List of devices"
+       cat devices.dat
+       echo ""
+       echo "/etc/hostapd-psk"
+       cat /etc/hostapd-psk
+else
+       echo "Unknown option. Please run ./register_device.sh -h for usage."
+fi
+