4 if [ "$#" -eq 0 ] || [ "$1" == "-h" ]; then
5 echo "Device registration utility for Sentinel system"
6 echo "This is a simple script that register a new device"
7 echo "into /etc/config/dhcp and /etc/hostapd-psk"
8 echo "Copyright (c) 2015-2017, Rahmadi Trimananda <rtrimana@uci.edu> PLRG@UCIrvine"
11 echo " ./register_device.sh [-h]"
12 echo " ./register_device.sh [-a <mac-address> <ip-address> <key> <device-name>]"
13 echo " ./register_device.sh [-l]"
16 echo " -h show this usage"
17 echo " -a adding device by putting MAC address, desired IP address, key, and device name (optional)"
18 echo " -l show list of devices registered"
21 elif [ "$1" == "-a" ]; then
23 if [ "$2" == "" ] || [ "$3" == "" ] || [ "$4" == "" ]; then
24 echo "Empty or incomplete parameters! Please run ./register_device.sh -h for usage."
32 echo "$MAC $IP $KEY $5" >> devices.dat
34 # Insert into /etc/hostapd-psk
35 echo "$MAC $KEY" >> /etc/hostapd-psk
37 # Insert into /etc/config/dhcp
38 echo "" >> /etc/config/dhcp
39 if [ "$5" != "" ]; then # If device-name is not empty
40 echo "# $5" >> /etc/config/dhcp
42 echo "config host" >> /etc/config/dhcp
43 echo " option ip '$IP'" >> /etc/config/dhcp
44 echo " option mac '$MAC'" >> /etc/config/dhcp
46 if [ "$5" != "" ]; then # If device-name is not empty
47 echo " option name '$5'" >> /etc/config/dhcp
52 elif [ "$1" == "-l" ]; then
53 # Print list of devices
54 echo "List of devices"
57 echo "/etc/hostapd-psk"
60 echo "Unknown option. Please run ./register_device.sh -h for usage."