#!/bin/sh # Color settings for echo messages blue='\e[1;36m' # Blue color green='\e[1;32m' # Green color yellow='\e[1;33m' # Yellow color red='\e[1;31m' # Red color NC='\e[0m' # No color is_pi () { grep -q "^model name\s*:\s*ARMv" /proc/cpuinfo return $? } is_pione() { if grep -q "^Revision\s*:\s*00[0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo; then return 0 elif grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[0-36][0-9a-fA-F]$" /proc/cpuinfo ; then return 0 else return 1 fi } is_pitwo() { grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]04[0-9a-fA-F]$" /proc/cpuinfo return $? } is_pizero() { grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[9cC][0-9a-fA-F]$" /proc/cpuinfo return $? } get_pi_type() { if is_pione; then echo 1 elif is_pitwo; then echo 2 else echo 0 fi } openPortVersion() { version=$(openport --version) version=$(echo $version | grep '.' | awk -F'.' '{print $1}') if [ "$version" -gt 0 ] 2>/dev/null; then return 1 else version=$(openport version) version=$(echo $version | grep '.' | awk -F'.' '{print $1}') if [ "$version" -gt 0 ] 2>/dev/null; then return 2 else return 0 fi fi } calc_wt_size() { # NOTE: it's tempting to redirect stderr to /dev/null, so supress error # output from tput. However in this case, tput detects neither stdout or # stderr is a tty and so only gives default 80, 24 values WT_HEIGHT=17 WT_WIDTH=$(tput cols) if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then WT_WIDTH=80 fi if [ "$WT_WIDTH" -gt 178 ]; then WT_WIDTH=120 fi WT_MENU_HEIGHT=$(($WT_HEIGHT-7)) } do_about() { whiptail --msgbox "\ This tool provides a way to install, upgrade and configure the DINGO device. It can be run at any time.\ " 10 70 1 } do_firstUpgradeDINGOStack() { whiptail --msgbox "\ First upgrade the DINGO-Stack.\ " 10 70 1 } do_notImplemented() { whiptail --msgbox "\ Not yet implemented.\ " 10 70 1 } is_dingoStackInstalled() { if [ ! -f /etc/profile.d/dingo.sh ]; then # Can not install networking or LCD, because they use files # that only exist when DINGO stack is installed. whiptail --msgbox "\ First install the required DINGO-Stack.\ " 10 70 1 return 1 fi return 0 } do_finish() { exit 0 } do_reboot() { #disable_raspi_config_at_boot #if [ $ASK_TO_REBOOT -eq 1 ]; then whiptail --yesno "Would you like to reboot now?" 20 60 2 if [ $? -eq 0 ]; then # yes sync reboot fi #fi exit 0 } do_installBACnetTools() { echo -e "${blue}GoIoT: Install BACnet tools...${NC}" DIRECTORY="/opt/GoIoT" if [ -d "$DIRECTORY" ]; then cd /opt/GoIoT/ DIRECTORY="/opt/GoIoT/bacnet-tools" if [ ! -d "$DIRECTORY" ]; then sudo mkdir /opt/GoIoT/bacnet-tools fi cd bacnet-tools sudo wget --timestamping ftp://dingo:dingdong@82.221.35.195/RPI/bacnet-tools/bacnet-tools-bin.tar.gz sudo tar -xf bacnet-tools-bin.tar.gz echo -e "${blue}GoIoT: Install BACnet tools. Finished.${NC}" else echo -e "${red}GoIoT: Install BACnet tools. /opt/GoIoT/ does not exist.${NC}" fi } do_installDingoStackAPT() { do_checkDingoRepositories #{ #echo 0 #echo "Install DINGO-Stack..." echo -e "${blue}GoIoT: Install DINGO-Stack...${NC}" # Install DINGO-Stack sudo apt-get -y install dingo-stack #echo 25 # Sleep 5 seconds, so the DINGO-Stack has time todo its first setup. sleep 5 # Temporary solution. Should be part of package sudo apt-get -y install i2c-tools #echo 50 # When installing, things are added to /etc/rc.local # Also add 1-wire sudo grep -q -F '/etc/init.d/owserver' /etc/rc.local || sudo sed -i -e '$i #/etc/init.d/owserver start\n' /etc/rc.local # And BACNET-IFACE sudo grep -q -F 'export BACNET_IFACE=' /etc/rc.local || sudo sed -i -e '$i #export BACNET_IFACE=br0\n' /etc/rc.local # Add to dingo.sh to resolv Buster-issue sudo grep -q -F 'export OPENSSL_CONF=' /etc/profile.d/dingo.sh || sudo sed -i -e '$i export OPENSSL_CONF=/etc/ssl/\n' /etc/profile.d/dingo.sh # Add logrotate for /opt/GoIoT/DinGo/dingo.log # Check if logrotate file exists for DINGO-Stack FILE="/etc/logrotate.d/dingo-stack" if [ ! -f "$FILE" ]; then # Then download the file cd /etc/logrotate.d wget -N "http://apps.control2net.com/apt/misc/RPI/configfiles/etc/logrotate.d/dingo-stack" fi # Do some cleanup. Remove all backup files sudo cp -p /etc/logrotate.d/dingo-stack.* /opt/GoIoT/backup 2>/dev/null sudo rm -f /etc/logrotate.d/dingo-stack.* # Check if upload script exists FILE="/opt/GoIoT/DinGo/bin/general/rn_upload_last_log.sh" if [ ! -f "$FILE" ]; then # Then download the file cd /opt/GoIoT/DinGo/bin/general wget -N "http://apps.control2net.com/apt/misc/RPI/configfiles/general/rn_upload_last_log.sh" sudo chmod +x rn_upload_last_log.sh fi # Add hourly schedule to crontab. Check if schedule exists. If not then add it. sudo grep -q -F 'logrotate.d/dingo-stack' /etc/crontab || sudo sed -i -e '$i \35 * * * * root logrotate /etc/logrotate.d/dingo-stack\n' /etc/crontab #echo "Install DINGO-Stack. Finished." echo -e "${blue}GoIoT: Install DINGO-Stack. Finished.${NC}" #} | whiptail --title "Install DINGO Stack" --gauge "Please wait while installing" 6 60 0 } do_installDingoStackFTP() { echo -e "${blue}GoIoT: Do FTP upgrade...${NC}" sudo curl -s http://apps.control2net.com/apt/ftp-upgrade.txt | sudo bash /dev/stdin # dingo-config, should be available after this update. # We can add a symbolic link to /usr/bin for dingo-config, then it will be possible # to call dingo-config with sudo from everywhere. sudo ln -s /opt/GoIoT/DinGo/bin/dingo-config /usr/bin/dingo-config # Add to dingo.sh to resolv Buster-issue sudo grep -q -F 'export OPENSSL_CONF=' /etc/profile.d/dingo.sh || sudo sed -i -e '$i export OPENSSL_CONF=/etc/ssl/\n' /etc/profile.d/dingo.sh # Add logrotate for /opt/GoIoT/DinGo/dingo.log # Check if logrotate file exists for DINGO-Stack FILE="/etc/logrotate.d/dingo-stack" if [ ! -f "$FILE" ]; then # Then download the file cd /etc/logrotate.d wget -N "http://apps.control2net.com/apt/misc/RPI/configfiles/etc/logrotate.d/dingo-stack" fi # Do some cleanup. Remove all backup files sudo cp -p /etc/logrotate.d/dingo-stack.* /opt/GoIoT/backup 2>/dev/null sudo rm -f /etc/logrotate.d/dingo-stack.* # Check if upload script exists FILE="/opt/GoIoT/DinGo/bin/general/rn_upload_last_log.sh" if [ ! -f "$FILE" ]; then # Then download the file cd /opt/GoIoT/DinGo/bin/general wget -N "http://apps.control2net.com/apt/misc/RPI/configfiles/general/rn_upload_last_log.sh" sudo chmod +x rn_upload_last_log.sh fi # Add hourly schedule to crontab. Check if schedule exists. If not then add it. sudo grep -q -F 'logrotate.d/dingo-stack' /etc/crontab || sudo sed -i -e '$i \35 * * * * root logrotate /etc/logrotate.d/dingo-stack\n' /etc/crontab echo -e "${blue}GoIoT: Do FTP upgrade. Finished.${NC}" } do_setupWireless() { { sleep 1 echo 100 } | whiptail --gauge "Scanning..." 6 60 50 value="" states=$(sudo /opt/GoIoT/DinGo/bin/wifi/rn_check_wifi_states.sh) for SPLIT in $states;do SSID=$(echo "$SPLIT" | cut -d';' -f3) STRENGTH=$(echo "$SPLIT" | cut -d';' -f6) STRENGTH="Strength:$STRENGTH%" SECURE=$(echo "$SPLIT" | cut -d';' -f7) CONNECTED=$(echo "$SPLIT" | cut -d';' -f8) if [ "$CONNECTED" = "NOTCONNECTED" ]; then CONNECTED="Not_connected" else CONNECTED="Connected" fi IP=$(echo "$SPLIT" | cut -d';' -f9) if [ "$IP" = "None" ]; then IP="No_IP" else IP="$IP" fi value="$value $SSID $STRENGTH,$SECURE,$CONNECTED,$IP" done OPTION=$(whiptail --title "Wifi networks" --menu "Choose network to edit" 30 80 8 $value 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then s=$(echo $states | grep $OPTION | cut -d';' -f7) do_editWifiNetwork $OPTION $s fi #sudo /opt/GoIoT/DinGo/bin/dingo-set-internet-interface-wireless } do_editWifiNetwork() { SSID=$1 SSID_lower=`sudo echo "$SSID" | sed -e 's/\(.*\)/\L\1/'` # Check if SSID is already configured if grep -qF "$SSID" /etc/wpa_supplicant/wpa_supplicant.conf; then foundSSID=0 pass="" priority="" for i in $(cat < /etc/wpa_supplicant/wpa_supplicant.conf); do if [ "$i" = "}" ] && [ "$foundSSID" = 1 ]; then break fi key="" value="" key=$(echo "$i" | awk -F'=' '{print $1}') value=$(echo "$i" | awk -F'=' '{print $2}') if [ "$key" = "ssid" ]; then tmpssid=$(echo "$value" | tr -d '"') if [ "$tmpssid" = "$SSID" ]; then foundSSID=1 fi fi if [ "$key" = "psk" ] && [ "$foundSSID" = 1 ]; then pass=$(echo "$value" | tr -d '"') fi if [ "$key" = "priority" ] && [ "$foundSSID" = 1 ]; then priority=$(echo "$value") fi done if [ -z "$pass" ]; then whiptail --msgbox "\ Something is wrong. Password is empty. Go to /etc/wpa_supplicant/wpa_supplicant.conf for manual editing.\ " 10 70 1 else # Ask for password msg="Edit password:" KEY=$(whiptail --title "Wifi password" --inputbox "$msg" 10 70 "$pass" 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ -z "$priority" ]; then # Only save password sudo sed -i "/$SSID/,/}/ {s/psk=.*/psk=\"$KEY\"/}" /etc/wpa_supplicant/wpa_supplicant.conf else # Ask for priority msg="Edit priority:" PRIO=$(whiptail --title "Wifi priority" --inputbox "$msg" 10 70 "$priority" 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Save password and priority sudo sed -i "/$SSID/,/}/ {s/psk=.*/psk=\"$KEY\"/}" /etc/wpa_supplicant/wpa_supplicant.conf sudo sed -i "/$SSID/,/}/ {s/priority=.*/priority=$PRIO/}" /etc/wpa_supplicant/wpa_supplicant.conf fi fi fi fi else # Secure if [ "$2" = "Secure" ]; then # Ask for password msg="Enter password:" KEY=$(whiptail --title "Wifi password" --passwordbox "$msg" 10 70 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for priority msg="The priority of a network when selecting among multiple networks;a higher value means a network is more desirable.\nEnter priority:" PRIO=$(whiptail --title "Wifi priority" --inputbox "$msg" 10 70 0 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo echo 'network={' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo 'ssid="'"$SSID"'"' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo '#key_mgmt=NONE' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo 'psk="'"$KEY"'"' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo "priority=$PRIO" >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo 'id_str="'"$SSID_lower"'"' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo '}' >> /etc/wpa_supplicant/wpa_supplicant.conf fi fi # Unsecure else # Ask for priority msg="The priority of a network when selecting among multiple networks;a higher value means a network is more desirable.\nEnter priority:" PRIO=$(whiptail --title "Wifi priority" --inputbox "$msg" 10 70 0 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo echo 'network={' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo 'ssid="'"$SSID"'"' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo 'key_mgmt=NONE' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo '#psk=""' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo "priority=$PRIO" >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo 'id_str="'"$SSID_lower"'"' >> /etc/wpa_supplicant/wpa_supplicant.conf sudo echo '}' >> /etc/wpa_supplicant/wpa_supplicant.conf fi fi fi } do_setupModem() { exists=`grep -F 'gpio=4=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=4=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=4=op,dl' >> /boot/config.txt" fi exists=`grep -F 'gpio=5=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=5=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=5=op,dl' >> /boot/config.txt" fi exists=`grep -F 'gpio=6=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=6=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=6=op,dl' >> /boot/config.txt" fi # Ask for protocol P=`sed -n -e 's/^\\s*PROTOCOL=//p' $DINGO_SCRIPTS/modem/rn_ppp0.conf | tr -d '\n' | tr -d '\r'` PPP=OFF QMI=OFF if [ -z "$P" ]; then PPP=ON else if [ "$P" = "PPP" ]; then PPP=ON else QMI=ON fi fi msg="Choose protocol:" PROTOCOL=$(whiptail --title "Protocol" --radiolist \ "$msg" 15 60 4 \ "PPP" "Point-to-Point Protocol" $PPP \ "QMI" "Qualcomm MSM Interface" $QMI 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ "$PROTOCOL" = "PPP" ]; then sudo bash -c "[ -f /etc/profile.d/dingo.sh ] && . /etc/profile.d/dingo.sh && grep -q PROTOCOL= $DINGO_SCRIPTS/modem/rn_ppp0.conf && sed 's/^PROTOCOL=.*/PROTOCOL=PPP/' -i $DINGO_SCRIPTS/modem/rn_ppp0.conf || echo \"PROTOCOL=PPP\" >> $DINGO_SCRIPTS/modem/rn_ppp0.conf" else sudo bash -c "[ -f /etc/profile.d/dingo.sh ] && . /etc/profile.d/dingo.sh && grep -q PROTOCOL= $DINGO_SCRIPTS/modem/rn_ppp0.conf && sudo sed 's/^PROTOCOL=.*/PROTOCOL=QMI/' -i $DINGO_SCRIPTS/modem/rn_ppp0.conf || sudo echo \"PROTOCOL=QMI\" >> $DINGO_SCRIPTS/modem/rn_ppp0.conf" fi fi # Ask for APN APN=`sudo cat /etc/wvdial.conf | grep "Init3" | awk -F',' '{print $3}' | tr -d '"'` msg="Edit APN:" APN=$(whiptail --title "Modem APN" --inputbox "$msg" 10 70 $APN 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/Init3.*/Init3 = AT+CGDCONT=1,"IP","'"$APN"'"/' /etc/wvdial.conf FILE="/etc/qmi-network.conf" if [ -f "$FILE" ]; then sudo sed -i 's/APN=.*/APN='"$APN"'/' /etc/qmi-network.conf fi fi # Ask for PIN PIN=`sudo cat /etc/wvdial.conf | grep "AT+CPIN=" | awk -F'=' '{print $3}' | tr -d '"'` msg="Edit PIN:" PIN=$(whiptail --title "Modem PIN" --inputbox "$msg" 10 70 $PIN 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/Init1 = AT+CPIN=.*/Init1 = AT+CPIN="'"$PIN"'"/' /etc/wvdial.conf fi # Ask for username USER=`sudo cat /etc/wvdial.conf | grep "^Username = " | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit User:" USER=$(whiptail --title "Modem user" --inputbox "$msg" 10 70 $USER 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/^Username =.*/Username = '"$USER"'/' /etc/wvdial.conf FILE="/etc/qmi-network.conf" if [ -f "$FILE" ]; then sudo sed -i 's/APN_USER=.*/APN_USER='"$USER"'/' /etc/qmi-network.conf fi fi # Ask for password PASS=`sudo cat /etc/wvdial.conf | grep "^Password = " | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Pass:" PASS=$(whiptail --title "Modem password" --inputbox "$msg" 10 70 $PASS 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/^Password =.*/Password = '"$PASS"'/' /etc/wvdial.conf FILE="/etc/qmi-network.conf" if [ -f "$FILE" ]; then sudo sed -i 's/APN_PASS=.*/APN_PASS='"$PASS"'/' /etc/qmi-network.conf fi fi # Ask for phone PHONE=`sudo cat /etc/wvdial.conf | grep "^Phone = " | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Phone:" PHONE=$(whiptail --title "Modem phone" --inputbox "$msg" 10 70 $PHONE 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/^Phone =.*/Phone = '"$PHONE"'/' /etc/wvdial.conf fi # Ask for primary ping PPING=`sudo cat /opt/GoIoT/DinGo/bin/modem/rn_ppp0.conf | grep "PRIMARY_PING_ADDRESS" | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Primary ping:" PPING=$(whiptail --title "Modem primary ping" --inputbox "$msg" 10 70 $PPING 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/PRIMARY_PING_ADDRESS.*/PRIMARY_PING_ADDRESS='"$PPING"'/' /opt/GoIoT/DinGo/bin/modem/rn_ppp0.conf fi # Ask for secondary ping SPING=`sudo cat /opt/GoIoT/DinGo/bin/modem/rn_ppp0.conf | grep "SECONDARY_PING_ADDRESS" | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Secondary ping:" SPING=$(whiptail --title "Modem secondary ping" --inputbox "$msg" 10 70 $SPING 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/SECONDARY_PING_ADDRESS.*/SECONDARY_PING_ADDRESS='"$SPING"'/' /opt/GoIoT/DinGo/bin/modem/rn_ppp0.conf fi } do_setupDDNS() { # Ask for DDNS service provider SERVICE=`sudo cat /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf | grep "SERVICEPROVIDER" | awk -F'=' '{print $2}' | tr -d ' '` ZERO=OFF ONE=OFF TWO=OFF THREE=OFF if [ "$SERVICE" = "0" ]; then ZERO=ON fi if [ "$SERVICE" = "1" ]; then ONE=ON fi if [ "$SERVICE" = "2" ]; then TWO=ON fi if [ "$SERVICE" = "3" ]; then THREE=ON fi msg="Choose service provider:" SERVICE=$(whiptail --title "Service provider" --radiolist \ "$msg" 15 60 4 \ "0" "Standard DDNS (use nsupdate)" $ZERO \ "1" "dyndns (dyndns.com)" $ONE \ "2" "33222 (3322.org)" $TWO \ "3" "No-ip (no-ip.com)" $THREE 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/SERVICEPROVIDER.*/SERVICEPROVIDER='"$SERVICE"'/' /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf if [ "$SERVICE" != "0" ]; then # Ask for Hostname HOST=`sudo cat /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf | grep "HOST" | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Hostname:" HOST=$(whiptail --title "DDNS hostname" --inputbox "$msg" 10 70 $HOST 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/HOST.*/HOST='"$HOST"'/' /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf fi # Ask for username USER=`sudo cat /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf | grep "USERNAME" | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Username:" USER=$(whiptail --title "DDNS user" --inputbox "$msg" 10 70 $USER 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/USERNAME.*/USERNAME='"$USER"'/' /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf fi # Ask for password PASS=`sudo cat /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf | grep "PASSWORD" | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Password:" PASS=$(whiptail --title "DDNS password" --inputbox "$msg" 10 70 $PASS 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/PASSWORD.*/PASSWORD='"$PASS"'/' /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf fi else # Ask for server SERVER=`sudo cat /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf | grep "DNSSERVER" | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Server:" SERVER=$(whiptail --title "DDNS server" --inputbox "$msg" 10 70 $SERVER 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/DNSSERVER.*/DNSSERVER='"$SERVER"'/' /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf fi # Ask for Hostname HOST=`sudo cat /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf | grep "HOST" | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Hostname:" HOST=$(whiptail --title "DDNS hostname" --inputbox "$msg" 10 70 $HOST 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/HOST.*/HOST='"$HOST"'/' /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf fi # Ask for zone ZONE=`sudo cat /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf | grep "ZONE" | awk -F'=' '{print $2}' | tr -d ' '` msg="Edit Zone name:" ZONE=$(whiptail --title "DDNS zone name" --inputbox "$msg" 10 70 $ZONE 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/ZONE.*/ZONE='"$ZONE"'/' /opt/GoIoT/DinGo/bin/ddns/rn_ddns.conf fi fi fi } do_setupEthernet() { I=`sudo cat /etc/network/interfaces | grep "^iface eth0 inet dhcp"` DHCP=OFF STATIC=OFF if [ -z "$I" ]; then STATIC=ON else DHCP=ON fi msg="Choose between DHCP or static:" ADDRESSING=$(whiptail --title "IP addressing" --radiolist \ "$msg" 15 60 4 \ "DHCP" "Automatically choose an IP" $DHCP \ "Static" "Set an dedicated IP" $STATIC 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ "$ADDRESSING" = "DHCP" ]; then content="# [CONFIGSTART=ETHERNET]\nauto eth0\nallow-hotplug eth0\niface eth0 inet dhcp\n#iface eth0 inet static\n#address 192.168.1.10\n#netmask 255.255.255.0\n#gateway 192.168.1.254\n# [CONFIGEND=ETHERNET]" sudo sed -i "/CONFIGSTART=ETHERNET]/,/CONFIGEND=ETHERNET]/c$content" /etc/network/interfaces else # Ask for static IP IP=`sudo cat /etc/network/interfaces | grep address | head -1 | awk -F' ' '{print $2}' | tr -d ' '` msg="Edit Static IP:" IP=$(whiptail --title "Ethernet static IP" --inputbox "$msg" 10 70 $IP 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for netmask MASK=`sudo cat /etc/network/interfaces | grep netmask | head -1 | awk -F' ' '{print $2}' | tr -d ' '` msg="Edit Netmask:" MASK=$(whiptail --title "Ethernet netmask" --inputbox "$msg" 10 70 $MASK 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for gateway GATEWAY=`sudo cat /etc/network/interfaces | grep gateway | head -1 | awk -F' ' '{print $2}' | tr -d ' '` msg="Edit Gateway:" GATEWAY=$(whiptail --title "Ethernet gateway" --inputbox "$msg" 10 70 $GATEWAY 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then content="# [CONFIGSTART=ETHERNET]\nauto eth0\nallow-hotplug eth0\n#iface eth0 inet dhcp\niface eth0 inet static\naddress $IP\nnetmask $MASK\ngateway $GATEWAY\n# [CONFIGEND=ETHERNET]" sudo sed -i "/CONFIGSTART=ETHERNET]/,/CONFIGEND=ETHERNET]/c$content" /etc/network/interfaces fi fi fi fi fi } do_setupEthernet2() { I=`sudo cat /etc/network/interfaces | awk '/CONFIGSTART=ETHERNET2/,EOF' | grep "^iface eth1 inet dhcp"` DHCP=OFF STATIC=OFF if [ -z "$I" ]; then STATIC=ON else DHCP=ON fi msg="Choose between DHCP or static:" ADDRESSING=$(whiptail --title "IP addressing" --radiolist \ "$msg" 15 60 4 \ "DHCP" "Automatically choose an IP" $DHCP \ "Static" "Set an dedicated IP" $STATIC 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ "$ADDRESSING" = "DHCP" ]; then content="# [CONFIGSTART=ETHERNET2]\nauto eth1\nallow-hotplug eth1\niface eth1 inet dhcp\n#iface eth1 inet static\n#address 192.168.2.10\n#netmask 255.255.255.0\n#gateway 192.168.2.254\n# [CONFIGEND=ETHERNET2]" sudo sed -i "/CONFIGSTART=ETHERNET2/,/CONFIGEND=ETHERNET2/c$content" /etc/network/interfaces else # Ask for static IP IP=`sudo cat /etc/network/interfaces | awk '/CONFIGSTART=ETHERNET2/,EOF' | grep address | head -1 | awk -F' ' '{print $2}' | tr -d ' '` msg="Edit Static IP:" IP=$(whiptail --title "Ethernet 2 static IP" --inputbox "$msg" 10 70 $IP 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for netmask MASK=`sudo cat /etc/network/interfaces | awk '/CONFIGSTART=ETHERNET2/,EOF' | grep netmask | head -1 | awk -F' ' '{print $2}' | tr -d ' '` msg="Edit Netmask:" MASK=$(whiptail --title "Ethernet 2 netmask" --inputbox "$msg" 10 70 $MASK 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for gateway GATEWAY=`sudo cat /etc/network/interfaces | awk '/CONFIGSTART=ETHERNET2/,EOF' | grep gateway | head -1 | awk -F' ' '{print $2}' | tr -d ' '` msg="Edit Gateway:" GATEWAY=$(whiptail --title "Ethernet 2 gateway" --inputbox "$msg" 10 70 $GATEWAY 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then content="# [CONFIGSTART=ETHERNET2]\nauto eth1\nallow-hotplug eth1\n#iface eth1 inet dhcp\niface eth1 inet static\naddress $IP\nnetmask $MASK\ngateway $GATEWAY\n# [CONFIGEND=ETHERNET2]" sudo sed -i "/CONFIGSTART=ETHERNET2/,/CONFIGEND=ETHERNET2/c$content" /etc/network/interfaces fi fi fi fi fi } do_installDingoStackNetworkingAPT() { # If DINGO-Stack is not installed, then do not continue is_dingoStackInstalled if [ $? = 1 ]; then return 0 fi do_checkDingoRepositories echo -e "${blue}GoIoT: Install DINGO-Stack network setup...${NC}" # When the networking is installed, it will replace the /etc/rc.local completely. # This can be a problem, so before installing, lets try and find what states the lines # regarding the DINGO project are in and save them temporarly. # (1-wire, self-signed certificate, splash for LCD, BACNET-IFACE) STATE_OneWire=$(sudo grep -F '/etc/init.d/owserver' /etc/rc.local | head -c1) STATE_Certificate=$(sudo grep -F '$DINGO_SCRIPTS/ssl/rn_auto_create_self_signed_for_ip.sh' /etc/rc.local | head -c1) STATE_Splash=$(sudo grep -F '/Adafruit_Python_SSD1306/examples/DEMO/splash.sh' /etc/rc.local | head -c1) STATE_BACnet=$(sudo grep -F 'export BACNET_IFACE=' /etc/rc.local | head -c1) # Install DINGO networking setup sudo apt-get -y install dingo-stack-networking # These packages need to be installed to use the QMI-protocol sudo apt-get -y install libqmi-utils udhcpc if [ ! -f "/etc/qmi-network.conf" ]; then sudo wget -P /etc --timestamping ftp://dingo:dingdong@82.221.35.195/RPI/rootfs/configfiles/etc/qmi-network.conf fi exists=`grep -F 'gpio=4=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=4=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=4=op,dl' >> /boot/config.txt" fi exists=`grep -F 'gpio=5=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=5=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=5=op,dl' >> /boot/config.txt" fi exists=`grep -F 'gpio=6=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=6=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=6=op,dl' >> /boot/config.txt" fi # TODO: # Return the states of the lines in /etc/rc.local if [ ! -z "$STATE_OneWire" ]; then if [ "$STATE_OneWire" != "#" ]; then sudo sed -i '/owserver/s/^#//g' /etc/rc.local fi fi if [ ! -z "$STATE_Certificate" ]; then if [ "$STATE_Certificate" != "#" ]; then sudo sed -i '/rn_auto_create_self_signed_for_ip.sh/s/^#//g' /etc/rc.local fi fi if [ ! -z "$STATE_Splash" ]; then if [ "$STATE_Splash" != "#" ]; then sudo sed -i '/Adafruit_Python_SSD1306/s/^#//g' /etc/rc.local fi fi if [ ! -z "$STATE_BACnet" ]; then if [ "$STATE_BACnet" != "#" ]; then sudo sed -i '/BACNET_IFACE/s/^#//g' /etc/rc.local fi fi # The installation of the networking, is by default setup to use Ethernet. # There is the possibility that a wireless setup is already configured and used as primary. # To prevent the install from destroying the current connection, we will ask the user, # what his primary connection is (Ethernet or wireless). ETHERNET=ON WIRELESS=OFF if is_pizero; then ETHERNET=OFF WIRELESS=ON fi msg="What is your current primary Internet connection?" CONNECTION=$(whiptail --title "Current Internet connection" --radiolist \ "$msg" 15 60 4 \ "Ethernet" "Connection via Ethernet (wire)" $ETHERNET \ "Wireless" "Connection via wifi" $WIRELESS 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ "$CONNECTION" = "Wireless" ]; then # Set Internet interface to WIRELESS echo -e "${blue}GoIoT: Set Internet interface to: Wireless.${NC}" sudo sed -i 's/INTERNET_INTERFACE.*/INTERNET_INTERFACE=WIRELESS/' /opt/GoIoT/DinGo/bin/network/rn_network.conf # Comment lines in /etc/network/interfaces sudo sed -i '/CONFIGSTART=HOSTAPD/,/CONFIGEND=HOSTAPD/ {s/^#*/#/}' /etc/network/interfaces # Uncomment lines in /etc/network/interfaces sudo sed -i '/CONFIGSTART=WIFIROAMING/,/CONFIGEND=WIFIROAMING/ {/CONFIGSTART=WIFIROAMING/p; /CONFIGSTART=WIFIROAMING/d; /CONFIGEND=WIFIROAMING/p; /CONFIGEND=WIFIROAMING/d; s/^#//'} /etc/network/interfaces # Change to wpa-roam do_changeToWpaRoam fi fi echo -e "${blue}GoIoT: Install DINGO-Stack network setup. Finished.${NC}" } do_upgradeDingoStackNetworkingAPT() { do_checkDingoRepositories echo -e "${blue}GoIoT: Install DINGO-Stack network setup...${NC}" # Install DINGO networking setup sudo apt-get -y install dingo-stack-networking #These packages need to be installed to use the QMI-protocol sudo apt-get -y install libqmi-utils udhcpc if [ ! -f "/etc/qmi-network.conf" ]; then sudo wget -P /etc --timestamping ftp://dingo:dingdong@82.221.35.195/RPI/rootfs/configfiles/etc/qmi-network.conf fi exists=`grep -F 'gpio=4=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=4=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=4=op,dl' >> /boot/config.txt" fi exists=`grep -F 'gpio=5=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=5=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=5=op,dl' >> /boot/config.txt" fi exists=`grep -F 'gpio=6=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=6=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=6=op,dl' >> /boot/config.txt" fi echo -e "${blue}GoIoT: Install DINGO-Stack network setup. Finished.${NC}" } do_changeToWpaRoam() { sudo sed -i 's/wpa-conf/wpa-roam/g' /etc/network/interfaces } do_changeToWpaConf() { sudo sed -i 's/wpa-roam/wpa-conf/g' /etc/network/interfaces } do_setInternetInterface() { # What is current interface internet_interface=`sed -n -e 's/^\s*INTERNET_INTERFACE=//p' /opt/GoIoT/DinGo/bin/network/rn_network.conf` E_STATUS=OFF E2_STATUS=OFF W_STATUS=OFF M_STATUS=OFF if [ "$internet_interface" = "ETHERNET" ]; then E_STATUS=ON fi if [ "$internet_interface" = "ETHERNET2" ]; then E2_STATUS=ON fi if [ "$internet_interface" = "WIRELESS" ]; then W_STATUS=ON fi if [ "$internet_interface" = "MODEM" ]; then M_STATUS=ON fi msg="Is is important to choose the right interface, in regards to Internet routing.\nReboot is needed to change routing. \nChoose Internet interface:" INTERFACES=$(whiptail --title "Internet interface" --radiolist \ "$msg" 15 60 4 \ "Ethernet" "Internet is on Ethernet" $E_STATUS \ "Ethernet2" "Internet is on Ethernet 2" $E2_STATUS \ "Wireless" "Internet is on wireless" $W_STATUS \ "Modem" "Internet is on modem" $M_STATUS 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Turn off router echo -e "${blue}GoIoT: Turn off router.${NC}" sudo sed -i 's/ROUTER=.*/ROUTER=false/' /opt/GoIoT/DinGo/bin/network/rn_network.conf if [ "$INTERFACES" = "Ethernet" ]; then # Set Internet interface to ETHERNET echo -e "${blue}GoIoT: Set Internet interface to: Ethernet.${NC}" sudo sed -i 's/INTERNET_INTERFACE.*/INTERNET_INTERFACE=ETHERNET/' /opt/GoIoT/DinGo/bin/network/rn_network.conf fi if [ "$INTERFACES" = "Ethernet2" ]; then # Set Internet interface to ETHERNET2 echo -e "${blue}GoIoT: Set Internet interface to: Ethernet 2.${NC}" sudo sed -i 's/INTERNET_INTERFACE.*/INTERNET_INTERFACE=ETHERNET2/' /opt/GoIoT/DinGo/bin/network/rn_network.conf fi if [ "$INTERFACES" = "Wireless" ]; then # Set Internet interface to WIRELESS echo -e "${blue}GoIoT: Set Internet interface to: Wireless.${NC}" sudo sed -i 's/INTERNET_INTERFACE.*/INTERNET_INTERFACE=WIRELESS/' /opt/GoIoT/DinGo/bin/network/rn_network.conf # Comment lines in /etc/network/interfaces sudo sed -i '/CONFIGSTART=HOSTAPD/,/CONFIGEND=HOSTAPD/ {s/^#*/#/}' /etc/network/interfaces # Uncomment lines in /etc/network/interfaces sudo sed -i '/CONFIGSTART=WIFIROAMING/,/CONFIGEND=WIFIROAMING/ {/CONFIGSTART=WIFIROAMING/p; /CONFIGSTART=WIFIROAMING/d; /CONFIGEND=WIFIROAMING/p; /CONFIGEND=WIFIROAMING/d; s/^#//'} /etc/network/interfaces fi if [ "$INTERFACES" = "Modem" ]; then # Set Internet interface to MODEM echo -e "${blue}GoIoT: Set Internet interface to: Modem.${NC}" sudo sed -i 's/INTERNET_INTERFACE.*/INTERNET_INTERFACE=MODEM/' /opt/GoIoT/DinGo/bin/network/rn_network.conf # Activate modem checker sudo sed -i '/rn_check_ppp0.sh/ s/^#//' /etc/crontab else # Deactivate modem checker sudo sed -i '/rn_check_ppp0.sh/ {s/^#*/#/}' /etc/crontab fi fi } do_installDingoStackNetworkingFTP() { # If DINGO-Stack is not installed, then do not continue is_dingoStackInstalled if [ $? = 1 ]; then return 0 fi # These packages need to be installed to use the QMI-protocol: sudo apt-get -y install libqmi-utils udhcpc if [ ! -f "/etc/qmi-network.conf" ]; then sudo wget -P /etc --timestamping ftp://dingo:dingdong@82.221.35.195/RPI/rootfs/configfiles/etc/qmi-network.conf fi exists=`grep -F 'gpio=4=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=4=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=4=op,dl' >> /boot/config.txt" fi exists=`grep -F 'gpio=5=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=5=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=5=op,dl' >> /boot/config.txt" fi exists=`grep -F 'gpio=6=op,dl' /boot/config.txt` if [ -z "$exists" ] then echo -e "${blue}GoIoT: Add gpio=6=op,dl to /boot/config.txt...${NC}" sudo bash -c "echo '# Regarding GSM Modem' >> /boot/config.txt" sudo bash -c "echo 'gpio=6=op,dl' >> /boot/config.txt" fi # Check if script exists file="/opt/GoIoT/DinGo/bin/ftp-upgrade-networking.sh" if [ -f "$file" ]; then echo -e "${blue}GoIoT: Do FTP upgrade...${NC}" sudo /opt/GoIoT/DinGo/bin/ftp-upgrade-networking.sh echo -e "${blue}GoIoT: Do FTP upgrade. Finished.${NC}" else do_firstUpgradeDINGOStack fi } do_installDingoStackAdafruitAPT() { # If the DINGO-Stack is not installed, then do not continue is_dingoStackInstalled if [ $? = 1 ]; then return 0 fi do_checkDingoRepositories echo -e "${blue}GoIoT: Install DINGO-Stack LCD setup...${NC}" # Setup i2c-0 sudo grep -q -F 'dtparam=i2c_vc=on' /boot/config.txt || sudo sed -i -e '$i \dtparam=i2c_vc=on\n' /boot/config.txt set +e # Difference between Stretch and Buster version=$(cat /etc/os-release | grep VERSION_ID= | cut -d'"' -f2) # If version is newer than stretch if [ "$version" -gt "9" ]; then sudo apt-get -y install python-pil else sudo apt-get -y install python-imaging fi # Install LCD package sudo apt-get -y install dingo-stack-adafruit # Check if not successful if [ $? != 0 ]; then set -e echo -e "${red}GoIoT: Problems with LCD setup. Do workaround...${NC}" # Temporary work around bug in Adafruit package. # https://github.com/adafruit/Adafruit_Python_SSD1306/issues/22 sudo rm -r /Adafruit_Python_SSD1306/ # Then install the LCD package again sudo apt-get -y install dingo-stack-adafruit else set -e fi # Add splash line to /etc/rc.local, if not already there. sudo grep -q -F '[ -f /etc/profile.d/dingo.sh ] && . /etc/profile.d/dingo.sh' /etc/rc.local || sudo sed -i -e '$i \[ -f /etc/profile.d/dingo.sh ] && . /etc/profile.d/dingo.sh\n' /etc/rc.local # Runs now as a service # sudo grep -q -F 'Adafruit_Python_SSD1306' /etc/rc.local || sudo sed -i -e '$i \sudo /Adafruit_Python_SSD1306/examples/DEMO/splash.sh &\n' /etc/rc.local echo -e "${blue}GoIoT: Install DINGO-Stack LCD setup. Finished.${NC}" } do_installDingoStackAdafruitFTP() { # If DINGO-Stack is not installed, then do not continue is_dingoStackInstalled if [ $? = 1 ]; then return 0 fi # Difference between Stretch and Buster version=$(cat /etc/os-release | grep VERSION_ID= | cut -d'"' -f2) # If version is newer than stretch if [ "$version" -gt "9" ]; then sudo apt-get -y install python-pil else sudo apt-get -y install python-imaging fi # Check if script exists file="/opt/GoIoT/DinGo/bin/ftp-upgrade-adafruit.sh" if [ -f "$file" ]; then echo -e "${blue}GoIoT: Do FTP upgrade...${NC}" sudo /opt/GoIoT/DinGo/bin/ftp-upgrade-adafruit.sh echo -e "${blue}GoIoT: Do FTP upgrade. Finished.${NC}" else do_firstUpgradeDINGOStack fi } do_upgradeDebug() { # Check if script exists file="/opt/GoIoT/DinGo/bin/ftp-debug-upgrade.sh" if [ -f "$file" ]; then echo -e "${blue}GoIoT: Do FTP debug-upgrade...${NC}" sudo /opt/GoIoT/DinGo/bin/ftp-debug-upgrade.sh echo -e "${blue}GoIoT: Do FTP debug-upgrade. Finished.${NC}" else do_firstUpgradeDINGOStack fi } do_installFTPClient() { echo -e "${blue}GoIoT: Install FTP client...${NC}" sudo apt-get install ftp; echo -e "${blue}GoIoT: Install FTP client. Finished.${NC}" } do_installOpenPort() { echo -e "${blue}GoIoT: Install Openport...${NC}" file="latest.deb" if [ -f "$file" ]; then echo -e "${blue}GoIoT: Remove old package first...${NC}" sudo rm latest.deb* fi sudo wget https://openport.io/download/arm/latest.deb sudo dpkg -i latest.deb echo -e "${blue}GoIoT: Install Openport. Finished.${NC}" whiptail --yesno "Do you want to register the device to OpenPort?" 20 60 2 if [ $? -eq 0 ]; then # yes do_registerOpenPort fi } do_stopOpenPort() { # Disable the Openport checker in /etc/crontab (comment) STATUS=`cat /etc/crontab | grep rn_check_openport.sh | grep "#"` if [ "$STATUS" = "" ]; then echo -e "${blue}GoIoT: Disable OpenPort checker.${NC}" sudo sed -i '/rn_check_openport.sh/s/^/#/g' /etc/crontab fi echo -e "${blue}GoIoT: Stop and disable OpenPort system service...${NC}" sudo systemctl stop openport.service sudo systemctl disable openport.service echo -e "${blue}GoIoT: Service stopped and disabled.${NC}" echo -e "${blue}GoIoT: Stop all OpenPort shares (can take some time)...${NC}" openPortVersion if [ $? = 1 ]; then sudo openport -K sudo openport -K else sudo openport kill-all sudo openport kill-all fi echo -e "${blue}GoIoT: All OpenPort shares stopped.${NC}" } do_registerOpenPort() { # Ask for open port reg. key msg="The registration will open ports 22 and 80.\nTo open more ports use this command: sudo openport portno -R -d\nEnter the OpenPort reg. key:" KEY=$(whiptail --title "OpenPort reg. key" --inputbox "$msg" 10 70 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then echo -e "${blue}GoIoT: Start OpenPort registration...${NC}" DIRECTORY="~/.openport" if [ -d "$DIRECTORY" ]; then echo -e "${blue}GoIoT: OpenPort generate new key...${NC}" sudo ssh-keygen -f ~/.openport/id_rsa -N '' # Difference between Stretch and Buster version=$(cat /etc/os-release | grep VERSION_ID= | cut -d'"' -f2) # If version is newer than stretch if [ "$version" -gt "9" ]; then sudo ssh-keygen -p -m PEM -f ~/.openport/id_rsa -N '' fi fi DIRECTORY="/root/.openport" if [ -d "$DIRECTORY" ]; then echo -e "${blue}GoIoT: OpenPort generate new key...sudo${NC}" sudo ssh-keygen -f /root/.openport/id_rsa -N '' # Difference between Stretch and Buster version=$(cat /etc/os-release | grep VERSION_ID= | cut -d'"' -f2) # If version is newer than stretch if [ "$version" -gt "9" ]; then sudo ssh-keygen -p -m PEM -f ~/.openport/id_rsa -N '' fi fi HOSTNAME=`sudo cat /etc/hostname` openPortVersion if [ $? = 1 ]; then sudo openport --register-key "$KEY" --name "$HOSTNAME" else sudo openport register-key "$KEY" --name "$HOSTNAME" fi # Open ports sudo openport 22 -R -d --keep-alive 300 sudo openport 80 -R -d --keep-alive 300 echo -e "${blue}GoIoT: Activate OpenPort checker...sudo${NC}" exists=`grep -F 'rn_check_openport.sh' /etc/crontab` if [ -z "$exists" ] then sudo bash -c "echo '10 * * * * root /opt/GoIoT/DinGo/bin/network/rn_check_openport.sh' >> /etc/crontab" else sudo sed -i '/rn_check_openport.sh/ s/^#//' /etc/crontab fi echo -e "${blue}GoIoT: Start OpenPort registration. Finished.${NC}" fi } do_installHardwareClock() { echo -e "${blue}GoIoT: Setup hardware clock...${NC}" # Remove the fake clock sudo apt-get -y purge fake-hwclock # Setup hardware clock sudo grep -q -F 'dtoverlay=i2c-rtc,ds1339' /boot/config.txt || sudo sed -i -e '$i \dtoverlay=i2c-rtc,ds1339\n' /boot/config.txt sudo grep -q -F 'rtc-ds1339' /etc/modules || sudo sed -i -e '$i \rtc-ds1339\n' /etc/modules # Create default adjtime file sudo echo '0.000000 0 0.000000 0 UTC' > /etc/adjtime echo -e "${blue}GoIoT: Setup hardware clock. Finished.${NC}" } do_checkDingoRepositories() { if grep -qF "http://apps.control2net.com/apt/" /etc/apt/sources.list; then dummy="" else # Allow DINGO repositories echo -e "${blue}GoIoT: Setup repositories...${NC}" sudo curl -s http://apps.control2net.com/apt/apt.txt | sudo bash /dev/stdin echo -e "${blue}GoIoT: Setup repositories. Finish.${NC}" fi } do_installGuided() { whiptail --yesno "It is recommended to start by changing the password, hostname and enable SSH. This can be done by going back and into raspi-config.\nContinue to next step?" 20 60 2 if [ $? -eq 0 ]; then # yes do_i2cAndSpiConfig whiptail --yesno "Do you want to install DINGO-Stack?" 20 60 2 if [ $? -eq 0 ]; then # yes do_installDingoStackAPT do_installDingoStackFTP fi whiptail --yesno "Do you want to install DINGO-Stack networking?" 20 60 2 if [ $? -eq 0 ]; then # yes do_installDingoStackNetworkingAPT whiptail --yesno "Do you want to set Internet interface?" 20 60 2 if [ $? -eq 0 ]; then # yes do_setInternetInterface fi fi whiptail --yesno "Do you want to install DINGO-Stack LCD?" 20 60 2 if [ $? -eq 0 ]; then # yes do_installDingoStackAdafruitAPT do_installDingoStackAdafruitFTP fi whiptail --yesno "Do you want to setup hardware clock?" 20 60 2 if [ $? -eq 0 ]; then # yes do_installHardwareClock fi whiptail --yesno "Do you want to install FTP client?" 20 60 2 if [ $? -eq 0 ]; then # yes do_installFTPClient fi whiptail --yesno "Do you want to install OpenPort?" 20 60 2 if [ $? -eq 0 ]; then # yes do_installOpenPort fi whiptail --yesno "Do you want to install BACnet tools?" 20 60 2 if [ $? -eq 0 ]; then # yes do_installBACnetTools fi fi } do_installSoftware() { calc_wt_size while true; do FUN=$(whiptail --title "DINGO Configuration Tool (dingo-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Install software" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ "1 Install wizard" "Complete install guide" \ "2 Install DINGO-Stack" "Install via apt-get" \ "3 Install DINGO-Stack networking" "Install via apt-get" \ "4 Install DINGO-Stack LCD" "Install via apt-get" \ "5 Install DINGO-Stack" "Install via FTP (not recommended)" \ "6 Install DINGO-Stack networking" "Install via FTP (not recommended)" \ "7 Install DINGO-Stack LCD" "Install via FTP (not recommended)" \ "8 Install FTP client" "Install via apt-get" \ "9 Install OpenPort" "Download from Internet" \ "10 Install BACnet tools" "Install/upgrade via FTP" \ 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$FUN" in 1\ *) do_installGuided ;; 2\ *) do_installDingoStackAPT ;; 3\ *) do_installDingoStackNetworkingAPT ;; 4\ *) do_installDingoStackAdafruitAPT ;; 5\ *) do_installDingoStackFTP ;; 6\ *) do_installDingoStackNetworkingFTP ;; 7\ *) do_installDingoStackAdafruitFTP ;; 8\ *) do_installFTPClient ;; 9\ *) do_installOpenPort ;; 10\ *) do_installBACnetTools ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else exit 1 fi done } do_upgradeSoftware() { calc_wt_size while true; do FUN=$(whiptail --title "DINGO Configuration Tool (dingo-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Upgrade software" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ "1 Upgrade DINGO-Stack" "Upgrade via FTP (recommended)" \ "2 Upgrade DINGO-Stack networking" "Upgrade via FTP (recommended)" \ "3 Upgrade DINGO-Stack LCD" "Upgrade via FTP (recommended)" \ "4 Upgrade DINGO-Stack" "Upgrade via apt-get" \ "5 Upgrade DINGO-Stack networking" "Upgrade via apt-get" \ "6 Upgrade DINGO-Stack LCD" "Upgrade via apt-get" \ "7 Upgrade debug" "Download latest unstable binaries via FTP" \ 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$FUN" in 1\ *) do_installDingoStackFTP ;; 2\ *) do_installDingoStackNetworkingFTP ;; 3\ *) do_installDingoStackAdafruitFTP ;; 4\ *) do_installDingoStackAPT ;; 5\ *) do_upgradeDingoStackNetworkingAPT ;; 6\ *) do_installDingoStackAdafruitAPT ;; 7\ *) do_upgradeDebug ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else exit 1 fi done } do_wirelessStaticIP() { # Default: not enabled DEFAULT=--defaultno # Check if file exists file="/etc/network/interfaces.d/dingo_wifi_static_ip" if [ -f "$file" ]; then # Default is enabled DEFAULT=0 fi whiptail --yesno "Would you like to use static IP for wireless setup?" $DEFAULT 20 60 2 RET=$? if [ $RET = 0 ]; then # Check if interfaces contains the source directory STATUS=`sudo cat /etc/network/interfaces | grep interfaces.d` if [ "$STATUS" = "" ]; then # Add the source directory sudo sed -i '2isource-directory /etc/network/interfaces.d' /etc/network/interfaces fi address="" netmask="" gateway="" ssid="" psk="" # Does the file exists already if [ -f "$file" ]; then address=$(cat /etc/network/interfaces.d/dingo_wifi_static_ip | grep address | awk -F' ' '{print $2}' | tr -d ' ') netmask=$(cat /etc/network/interfaces.d/dingo_wifi_static_ip | grep netmask | awk -F' ' '{print $2}' | tr -d ' ') gateway=$(cat /etc/network/interfaces.d/dingo_wifi_static_ip | grep gateway | awk -F' ' '{print $2}' | tr -d ' ') ssid=$(cat /etc/network/interfaces.d/dingo_wifi_static_ip | grep wpa-essid | awk -F' ' '{print $2}' | tr -d ' ') psk=$(cat /etc/network/interfaces.d/dingo_wifi_static_ip | grep wpa-psk | awk -F' ' '{print $2}' | tr -d ' ') msg="Edit SSID:" ssid=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$ssid" 3>&1 1>&2 2>&3) msg="Edit passphrase:" psk=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$psk" 3>&1 1>&2 2>&3) msg="Edit IP address:" address=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$address" 3>&1 1>&2 2>&3) msg="Edit netmask:" netmask=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$netmask" 3>&1 1>&2 2>&3) msg="Edit gateway:" gateway=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$gateway" 3>&1 1>&2 2>&3) else msg="SSID:" ssid=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$ssid" 3>&1 1>&2 2>&3) msg="Passphrase:" psk=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$psk" 3>&1 1>&2 2>&3) msg="IP address:" address=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$address" 3>&1 1>&2 2>&3) msg="Netmask:" netmask=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$netmask" 3>&1 1>&2 2>&3) msg="Gateway:" gateway=$(whiptail --title "Static IP for wireless setup" --inputbox "$msg" 10 70 "$gateway" 3>&1 1>&2 2>&3) fi # Add to the file sudo echo "auto wlan0" > /etc/network/interfaces.d/dingo_wifi_static_ip sudo echo "iface wlan0 inet static" >> /etc/network/interfaces.d/dingo_wifi_static_ip sudo echo "address $address" >> /etc/network/interfaces.d/dingo_wifi_static_ip sudo echo "netmask $netmask" >> /etc/network/interfaces.d/dingo_wifi_static_ip sudo echo "gateway $gateway" >> /etc/network/interfaces.d/dingo_wifi_static_ip sudo echo "wpa-essid $ssid" >> /etc/network/interfaces.d/dingo_wifi_static_ip sudo echo "wpa-psk $psk" >> /etc/network/interfaces.d/dingo_wifi_static_ip # Disable wifi roaming sudo sed -i '/CONFIGSTART=WIFIROAMING/,/CONFIGEND=WIFIROAMING/ {s/^#*/#/}' /etc/network/interfaces STATUS=enabled else # If file exists if [ -f "$file" ]; then # Remove static IP file sudo rm /etc/network/interfaces.d/dingo_wifi_static_ip # Enable wifi roaming router=`sed -n -e 's/^\s*ROUTER=//p' /opt/GoIoT/DinGo/bin/network/rn_network.conf` if [ "$router" = "false" ]; then sudo sed -i '/CONFIGSTART=WIFIROAMING/,/CONFIGEND=WIFIROAMING/ {/CONFIGSTART=WIFIROAMING/p; /CONFIGSTART=WIFIROAMING/d; /CONFIGEND=WIFIROAMING/p; /CONFIGEND=WIFIROAMING/d; s/^#//'} /etc/network/interfaces fi fi STATUS=disabled fi whiptail --msgbox "Static IP for wireless setup is $STATUS. Reboot to take effect." 20 60 1 } do_networkSetup() { calc_wt_size while true; do FUN=$(whiptail --title "DINGO Configuration Tool (dingo-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Network setup" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ "1 Set Internet interface" "Set the Internet connected interface" \ "2 Configure wireless setup" "Scan for networks" \ "3 Wireless static IP" "Enable/disable static IP for wireless setup" \ "4 Configure modem setup" "Configure wvdial settings and more" \ "5 Configure Ethernet setup" "Configure Ethernet interface" \ "6 Configure Ethernet 2 setup" "Configure Ethernet 2 interface" \ "7 Configure router setup" "Turn device into router" \ "8 Configure DDNS setup" "Configure Dynamic DNS setup" \ "9 Restart network setup" "Restarts all interfaces and router" \ "10 Activate Ethernet 2 port" "Activates the second Ethernet port" \ "11 Deactivate Ethernet 2 port" "Deactivates the second Ethernet port" 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$FUN" in 1\ *) do_setInternetInterface ;; 2\ *) do_setupWireless ;; 3\ *) do_wirelessStaticIP ;; 4\ *) do_setupModem ;; 5\ *) do_setupEthernet ;; 6\ *) do_setupEthernet2 ;; 7\ *) do_routerSetup ;; 8\ *) do_setupDDNS ;; 9\ *) do_restartNetwork ;; 10\ *) do_activateEthernet2 ;; 11\ *) do_deactivateEthernet2 ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else exit 1 fi done } do_restartNetwork() { sudo /opt/GoIoT/DinGo/bin/network/rn_restart_router.sh sudo ifup eth0 } do_activateEthernet2() { exists=`grep -F 'dtoverlay=enc28j60,int_pin=25,speed=12000000' /boot/config.txt` if [ -z "$exists" ] then sudo bash -c "echo '' >> /boot/config.txt" sudo bash -c "echo '# Enable second ethernet port according to page chapter 2.51 \"Second Ethernet\"' >> /boot/config.txt" sudo bash -c "echo 'dtoverlay=enc28j60,int_pin=25,speed=12000000' >> /boot/config.txt" else sudo sed -i '/dtoverlay=enc28j60,int_pin=25,speed=12000000/ s/^#//' /boot/config.txt fi exists=`grep -F '# [CONFIGSTART=ETHERNET2]' /etc/network/interfaces` if [ -z "$exists" ] then content="# [CONFIGEND=ETHERNET]\n# [CONFIGSTART=ETHERNET2]\nauto eth1\nallow-hotplug eth1\niface eth1 inet dhcp\n#iface eth1 inet static\n#address 192.168.2.10\n#netmask 255.255.255.0\n#gateway 192.168.2.254\n# [CONFIGEND=ETHERNET2]" sudo sed -i "/CONFIGEND=ETHERNET/c$content" /etc/network/interfaces fi } do_deactivateEthernet2() { exists=`grep -F 'dtoverlay=enc28j60,int_pin=25,speed=12000000' /boot/config.txt` if [ ! -z "$exists" ] then sudo sed -i '/^dtoverlay=enc28j60,int_pin=25,speed=12000000/s/^/#/' /boot/config.txt fi } do_setRouterOnOff() { # What is current router router=`sed -n -e 's/^\s*ROUTER=//p' /opt/GoIoT/DinGo/bin/network/rn_network.conf` R_ON=OFF R_OFF=OFF if [ "$router" = "true" ]; then R_ON=ON else R_OFF=ON fi msg="Turn router on or off:" routerChoose=$(whiptail --title "Router" --radiolist \ "$msg" 15 60 4 \ "On" "Turn router on" $R_ON \ "Off" "Turn router off" $R_OFF 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ "$routerChoose" = "On" ]; then sudo sed -i 's/ROUTER=.*/ROUTER=true/' /opt/GoIoT/DinGo/bin/network/rn_network.conf else sudo sed -i 's/ROUTER=.*/ROUTER=false/' /opt/GoIoT/DinGo/bin/network/rn_network.conf fi fi } do_setLanInterface() { # What is current interface lan=`sed -n -e 's/^\s*LAN_INTERFACE=//p' /opt/GoIoT/DinGo/bin/network/rn_network.conf` E_STATUS=OFF E2_STATUS=OFF W_STATUS=OFF B_STATUS=OFF if [ "$lan" = "ETHERNET" ]; then E_STATUS=ON fi if [ "$lan" = "ETHERNET2" ]; then E2_STATUS=ON fi if [ "$lan" = "WIRELESS" ]; then W_STATUS=ON fi if [ "$lan" = "BOTH" ]; then B_STATUS=ON fi msg="Choose LAN interface:" INTERFACES=$(whiptail --title "LAN interface" --radiolist \ "$msg" 15 60 4 \ "Ethernet" "LAN is on Ethernet" $E_STATUS \ "Ethernet2" "LAN is on Ethernet 2" $E2_STATUS \ "Wireless" "LAN is on wireless" $W_STATUS \ "Both" "LAN is on both Ethernet and wireless" $B_STATUS 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ "$INTERFACES" = "Ethernet" ]; then # Set LAN interface to ETHERNET echo -e "${blue}GoIoT: Set LAN interface to: Ethernet.${NC}" sudo sed -i 's/LAN_INTERFACE.*/LAN_INTERFACE=ETHERNET/' /opt/GoIoT/DinGo/bin/network/rn_network.conf sudo sed -i "3s/.*/interface eth0/" /etc/udhcpd.conf fi if [ "$INTERFACES" = "Ethernet2" ]; then # Set LAN interface to ETHERNET2 echo -e "${blue}GoIoT: Set LAN interface to: Ethernet 2.${NC}" sudo sed -i 's/LAN_INTERFACE.*/LAN_INTERFACE=ETHERNET2/' /opt/GoIoT/DinGo/bin/network/rn_network.conf sudo sed -i "3s/.*/interface eth1/" /etc/udhcpd.conf fi if [ "$INTERFACES" = "Wireless" ]; then # Set LAN interface to WIRELESS echo -e "${blue}GoIoT: Set LAN interface to: Wireless.${NC}" sudo sed -i 's/LAN_INTERFACE.*/LAN_INTERFACE=WIRELESS/' /opt/GoIoT/DinGo/bin/network/rn_network.conf sudo sed -i "3s/.*/interface wlan0/" /etc/udhcpd.conf # Comment lines in /etc/network/interfaces sudo sed -i '/CONFIGSTART=WIFIROAMING/,/CONFIGEND=WIFIROAMING/ {s/^#*/#/}' /etc/network/interfaces # Uncomment lines in /etc/network/interfaces sudo sed -i '/CONFIGSTART=HOSTAPD/,/CONFIGEND=HOSTAPD/ {/CONFIGSTART=HOSTAPD/p; /CONFIGSTART=HOSTAPD/d; /CONFIGEND=HOSTAPD/p; /CONFIGEND=HOSTAPD/d; s/^#//'} /etc/network/interfaces fi if [ "$INTERFACES" = "Both" ]; then # Set LAN interface to MODEM echo -e "${blue}GoIoT: Set LAN interface to: Both.${NC}" sudo sed -i 's/LAN_INTERFACE.*/LAN_INTERFACE=BOTH/' /opt/GoIoT/DinGo/bin/network/rn_network.conf sudo sed -i "3s/.*/interface br0/" /etc/udhcpd.conf # Comment lines in /etc/network/interfaces sudo sed -i '/CONFIGSTART=WIFIROAMING/,/CONFIGEND=WIFIROAMING/ {s/^#*/#/}' /etc/network/interfaces # Uncomment lines in /etc/network/interfaces sudo sed -i '/CONFIGSTART=HOSTAPD/,/CONFIGEND=HOSTAPD/ {/CONFIGSTART=HOSTAPD/p; /CONFIGSTART=HOSTAPD/d; /CONFIGEND=HOSTAPD/p; /CONFIGEND=HOSTAPD/d; s/^#//'} /etc/network/interfaces fi fi } do_setRouterIp() { # Ask for router IP IP=`sed -n '/CONFIGSTART=HOSTAPD/,/CONFIGEND=HOSTAPD/p' /etc/network/interfaces | grep address | head -1 | awk -F' ' '{print $2}' | tr -d ' '` msg="Edit Router IP:" NIP=$(whiptail --title "Router IP" --inputbox "$msg" 10 70 $IP 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for netmask MASK=`sed -n '/CONFIGSTART=HOSTAPD/,/CONFIGEND=HOSTAPD/p' /etc/network/interfaces | grep netmask | head -1 | awk -F' ' '{print $2}' | tr -d ' '` msg="Edit Netmask:" NMASK=$(whiptail --title "Router netmask" --inputbox "$msg" 10 70 $MASK 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i '/CONFIGSTART=HOSTAPD/,/CONFIGEND=HOSTAPD/ {'s/$IP/$NIP/g'}' /etc/network/interfaces sudo sed -i '/CONFIGSTART=HOSTAPD/,/CONFIGEND=HOSTAPD/ {'s/$MASK/$NMASK/g'}' /etc/network/interfaces sudo sed -i 's/opt router.*/opt router '"$NIP"'/' /etc/udhcpd.conf sudo sed -i 's/opt subnet.*/opt subnet '"$NMASK"'/' /etc/udhcpd.conf fi fi } do_setAccessPoint() { # Ask for SSID SSID=`sudo cat /etc/hostapd/hostapd.conf | grep ssid | awk -F'=' '{print $2}'` msg="Edit Access point SSID:" SSID=$(whiptail --title "Access point" --inputbox "$msg" 10 70 $SSID 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/ssid=.*/ssid='"$SSID"'/' /etc/hostapd/hostapd.conf fi # Ask for Passphrase PASS=`sudo cat /etc/hostapd/hostapd.conf | grep wpa_passphrase | awk -F'=' '{print $2}'` msg="Edit Access point passphrase:" PASS=$(whiptail --title "Access point" --inputbox "$msg" 10 70 $PASS 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/wpa_passphrase=.*/wpa_passphrase='"$PASS"'/' /etc/hostapd/hostapd.conf fi } do_setDhcpServer() { # Ask for start address START=`sudo cat /etc/udhcpd.conf | grep start | awk -F' ' '{print $2}'` msg="Edit Start address:" START=$(whiptail --title "DHCP server" --inputbox "$msg" 10 70 $START 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/start.*/start '"$START"'/' /etc/udhcpd.conf fi # Ask for end address END=`sudo cat /etc/udhcpd.conf | grep end | awk -F' ' '{print $2}'` msg="Edit End address:" END=$(whiptail --title "DHCP server" --inputbox "$msg" 10 70 $END 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/end.*/end '"$END"'/' /etc/udhcpd.conf fi # Ask for DNS DNS1=`sudo cat /etc/udhcpd.conf | grep dns | awk -F' ' '{print $3}'` DNS2=`sudo cat /etc/udhcpd.conf | grep dns | awk -F' ' '{print $4}'` msg="Edit DNS 1:" DNS1=$(whiptail --title "DHCP server" --inputbox "$msg" 10 70 $DNS1 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/opt dns.*/opt dns '"$DNS1"' '"$DNS2"'/' /etc/udhcpd.conf fi msg="Edit DNS 2:" DNS2=$(whiptail --title "DHCP server" --inputbox "$msg" 10 70 $DNS2 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/opt dns.*/opt dns '"$DNS1"' '"$DNS2"'/' /etc/udhcpd.conf fi } do_portForwarding() { value="" ports=$(sudo cat /opt/GoIoT/DinGo/bin/portforward/rn_portforward.conf) for SPLIT in $ports;do lport=$(echo "$SPLIT" | awk -F'=' '{print $1}') ip=$(echo "$SPLIT" | awk -F'=' '{print $2}' | awk -F',' '{print $1}') rport=$(echo "$SPLIT" | awk -F'=' '{print $2}' | awk -F',' '{print $2}') value="$value $lport To:$ip,On:$rport" done value="$value [Add] ..." OPTION=$(whiptail --title "Port forwarding" --menu "[Local port] To:[remote IP] On:[remote port]\nChoose rule to edit" 30 70 8 $value 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ "$OPTION" = "[Add]" ]; then # Ask for local port LPORT="" msg="Local port:" LPORT=$(whiptail --title "Port forwarding" --inputbox "$msg" 10 70 $LPORT 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for remote IP IP="" msg="Remote IP:" IP=$(whiptail --title "Port forwarding" --inputbox "$msg" 10 70 $IP 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for remote port RPORT="" msg="Remote port:" RPORT=$(whiptail --title "Port forwarding" --inputbox "$msg" 10 70 $RPORT 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo echo "$LPORT=$IP,$RPORT" >> /opt/GoIoT/DinGo/bin/portforward/rn_portforward.conf fi fi fi else whiptail --yesno "Edit port forwarding rule?" 20 60 2 if [ $? -eq 0 ]; then # yes # Ask for remote IP IP=`sudo cat /opt/GoIoT/DinGo/bin/portforward/rn_portforward.conf | grep "$OPTION="| awk -F'=' '{print $2}' | awk -F',' '{print $1}'` msg="Remote IP:" IP=$(whiptail --title "Port forwarding" --inputbox "$msg" 10 70 $IP 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for remote port RPORT=`sudo cat /opt/GoIoT/DinGo/bin/portforward/rn_portforward.conf | grep "$OPTION="| awk -F'=' '{print $2}' | awk -F',' '{print $2}'` msg="Remote port:" RPORT=$(whiptail --title "Port forwarding" --inputbox "$msg" 10 70 $RPORT 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/'"$OPTION"'=.*/'"$OPTION"'='"$IP"','"$RPORT"'/' /opt/GoIoT/DinGo/bin/portforward/rn_portforward.conf fi fi else whiptail --yesno "Delete port forwarding rule?" 20 60 2 if [ $? -eq 0 ]; then # yes sudo sed -i '/'"$OPTION"'=.*/d' /opt/GoIoT/DinGo/bin/portforward/rn_portforward.conf fi fi fi fi } do_IpToMac() { value="" leases=$(sudo cat /etc/udhcpd.conf | grep static_lease | tr ' ' ';') for SPLIT in $leases;do MAC=$(echo "$SPLIT" | awk -F';' '{print $2}') IP=$(echo "$SPLIT" | awk -F';' '{print $3}') value="$value $MAC Assign:$IP" done value="$value [Add] ..." OPTION=$(whiptail --title "IP to MAC (DHCP server)" --menu "[Remote MAC address] Assign:[IP]\nChoose rule to edit" 30 70 8 $value 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ "$OPTION" = "[Add]" ]; then # Ask for MAC MAC="" msg="MAC address:" MAC=$(whiptail --title "IP to MAC (DHCP server)" --inputbox "$msg" 10 70 $MAC 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then # Ask for IP IP="" msg="IP:" IP=$(whiptail --title "IP to MAC (DHCP server)" --inputbox "$msg" 10 70 $IP 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo echo "static_lease $MAC $IP" >> /etc/udhcpd.conf fi fi else whiptail --yesno "Edit IP to MAC rule?" 20 60 2 if [ $? -eq 0 ]; then # yes # Ask for IP IP=`sudo cat /etc/udhcpd.conf | grep "$OPTION" | awk -F' ' '{print $3}'` msg="IP:" IP=$(whiptail --title "IP to MAC (DHCP server)" --inputbox "$msg" 10 70 $IP 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/static_lease '"$OPTION"'.*/static_lease '"$OPTION"' '"$IP"'/' /etc/udhcpd.conf fi else whiptail --yesno "Delete IP to MAC rule?" 20 60 2 if [ $? -eq 0 ]; then # yes sudo sed -i '/'"$OPTION"'.*/d' /etc/udhcpd.conf fi fi fi fi } do_routerSetup() { calc_wt_size while true; do FUN=$(whiptail --title "DINGO Configuration Tool (dingo-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Router setup" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ "1 Set router On/Off" "Turn router On or Off" \ "2 Set LAN interface" "Set the interface for the private network" \ "3 Set router IP" "Set the IP of the router" \ "4 Configure access point" "Configure a HotSpot" \ "5 Configure DHCP server" "DHCP server settings" \ "6 Configure port forwarding" "Do port forwarding" \ "7 Configure IP to MAC" "Assign IP to MAC-address" 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$FUN" in 1\ *) do_setRouterOnOff ;; 2\ *) do_setLanInterface ;; 3\ *) do_setRouterIp ;; 4\ *) do_setAccessPoint ;; 5\ *) do_setDhcpServer ;; 6\ *) do_portForwarding ;; 7\ *) do_IpToMac ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else exit 1 fi done } do_setupLCD() { calc_wt_size while true; do FUN=$(whiptail --title "DINGO Configuration Tool (dingo-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "LCD setup" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ "1 Change LCD items" "What items should be displayed" \ "2 Change blank screen sleep" "How long should the blank screen sleep" \ "3 Change item screen sleep" "How long should the items be displayed" 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$FUN" in 1\ *) do_setupLcdItems ;; 2\ *) do_blankScreenSleep ;; 3\ *) do_itemScreenSleep ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else exit 1 fi done } do_blankScreenSleep() { # Ask for blank screen sleep sec. SLEEP=`sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep blank_sleep | awk -F'=' '{print $2}' | tr -d ' '` msg="Sleep sec.:" SLEEP=$(whiptail --title "Blank screen sleep" --inputbox "$msg" 10 70 $SLEEP 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/blank_sleep=.*/blank_sleep='"$SLEEP"'/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi } do_itemScreenSleep() { # Ask for item screen sleep sec. SLEEP=`sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep display_sleep | awk -F'=' '{print $2}' | tr -d ' '` msg="Display sec.:" SLEEP=$(whiptail --title "Item screen display" --inputbox "$msg" 10 70 $SLEEP 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo sed -i 's/display_sleep=.*/display_sleep='"$SLEEP"'/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi } do_setupLcdItems() { LOGO_S=OFF INTERNET_S=OFF IP_S=OFF KERNEL_S=OFF OSV_S=OFF OSRD_S=OFF MODEL_S=OFF DINGOV_S=OFF HOSTNAME_S=OFF GPRS_S=OFF WIFI_S=OFF DISK_S=OFF MEM_S=OFF CPU_S=OFF UPTIME_S=OFF TEMP_S=OFF NPLC_S=OFF if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep logo_enabled=1) ]; then LOGO_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep internet_interface_enabled=1) ]; then INTERNET_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep ip_address_enabled=1) ]; then IP_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep kernel_version_enabled=1) ]; then KERNEL_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep os_version_enabled=1) ]; then OSV_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep os_release_date_enabled=1) ]; then OSRD_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep computer_model_enabled=1) ]; then MODEL_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep dingo_stack_version_enabled=1) ]; then DINGOV_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep hostname_enabled=1) ]; then HOSTNAME_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep gprs_signal_strength_enabled=1) ]; then GPRS_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep wireless_signal_strength_enabled=1) ]; then WIFI_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep disk_space_enabled=1) ]; then DISK_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep memory_usage_enabled=1) ]; then MEM_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep cpu_usage_enabled=1) ]; then CPU_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep uptime_enabled=1) ]; then UPTIME_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep internal_temp_enabled=1) ]; then TEMP_S=ON fi if [ ! -z $(sudo cat /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf | grep nplc_enabled=1) ]; then NPLC_S=ON fi SECTIONS=$(whiptail --title "LCD items" --checklist \ "Choose items" 25 70 17 \ "Logo" "Display logo" $LOGO_S \ "Internet-interface" "Display Internet interface" $INTERNET_S \ "IP-address" "Display IP addresses" $IP_S \ "Kernel-version" "Display kernel version" $KERNEL_S \ "OS-version" "Display OS version" $OSV_S \ "Release-date" "Display OS release date" $OSRD_S \ "Computer-model" "Display computer model" $MODEL_S \ "DINGO-Stack-version" "Display DINGO-Stack version" $DINGOV_S \ "Hostname" "Display hostname" $HOSTNAME_S \ "GPRS" "Display GPRS signal strength" $GPRS_S \ "Wifi" "Display wireless signal strength" $WIFI_S \ "Disk" "Display disk usage" $DISK_S \ "Memory" "Display memory usage" $MEM_S \ "CPU" "Display CPU usage" $CPU_S \ "Uptime" "Display uptime info." $UPTIME_S \ "Temperature" "Display internal temperature" $TEMP_S \ "NPLC" "Display NPLC items" $NPLC_S 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then SECTIONS=$(echo $SECTIONS | tr '"' ';' | tr ' ' ';') if [ ! -z $(echo "$SECTIONS" | grep "Logo") ]; then sudo sed -i 's/logo_enabled=.*/logo_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/logo_enabled=.*/logo_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Internet-interface") ]; then sudo sed -i 's/internet_interface_enabled=.*/internet_interface_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/internet_interface_enabled=.*/internet_interface_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "IP-address") ]; then sudo sed -i 's/ip_address_enabled=.*/ip_address_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/ip_address_enabled=.*/ip_address_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Kernel-version") ]; then sudo sed -i 's/kernel_version_enabled=.*/kernel_version_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/kernel_version_enabled=.*/kernel_version_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "OS-versionn") ]; then sudo sed -i 's/os_version_enabled=.*/os_version_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/os_version_enabled=.*/os_version_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Release-date") ]; then sudo sed -i 's/os_release_date_enabled=.*/os_release_date_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/os_release_date_enabled=.*/os_release_date_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Computer-model") ]; then sudo sed -i 's/computer_model_enabled=.*/computer_model_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/computer_model_enabled=.*/computer_model_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "DINGO-Stack-version") ]; then sudo sed -i 's/dingo_stack_version_enabled=.*/dingo_stack_version_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/dingo_stack_version_enabled=.*/dingo_stack_version_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Hostname") ]; then sudo sed -i 's/hostname_enabled=.*/hostname_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/hostname_enabled=.*/hostname_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "GPRS") ]; then sudo sed -i 's/gprs_signal_strength_enabled=.*/gprs_signal_strength_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/gprs_signal_strength_enabled=.*/gprs_signal_strength_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Wifi") ]; then sudo sed -i 's/wireless_signal_strength_enabled=.*/wireless_signal_strength_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/wireless_signal_strength_enabled=.*/wireless_signal_strength_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Disk") ]; then sudo sed -i 's/disk_space_enabled=.*/disk_space_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/disk_space_enabled=.*/disk_space_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Memory") ]; then sudo sed -i 's/memory_usage_enabled=.*/memory_usage_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/memory_usage_enabled=.*/memory_usage_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "CPU") ]; then sudo sed -i 's/cpu_usage_enabled=.*/cpu_usage_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/cpu_usage_enabled=.*/cpu_usage_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Uptime") ]; then sudo sed -i 's/uptime_enabled=.*/uptime_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/uptime_enabled=.*/uptime_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "Temperature") ]; then sudo sed -i 's/internal_temp_enabled=.*/internal_temp_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/internal_temp_enabled=.*/internal_temp_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi if [ ! -z $(echo "$SECTIONS" | grep "NPLC") ]; then sudo sed -i 's/nplc_enabled=.*/nplc_enabled=1/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf else sudo sed -i 's/nplc_enabled=.*/nplc_enabled=0/' /Adafruit_Python_SSD1306/examples/DEMO/carousel.conf fi fi } do_i2cAndSpiConfig() { I2C0_S=OFF I2C1_S=OFF SPI_S=OFF if grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*i2c(_arm)?(=(on|true|yes|1))?(,.*)?$" /boot/config.txt; then I2C1_S=ON fi if grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*i2c(_vc)?(=(on|true|yes|1))?(,.*)?$" /boot/config.txt; then I2C0_S=ON fi if grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*spi(=(on|true|yes|1))?(,.*)?$" /boot/config.txt; then SPI_S=ON fi SECTIONS=$(whiptail --title "I2C and SPI configuration" --checklist \ "Enabling the I2C and SPI configuration is important for the DINGO-Stack, LED board and LCD display." 25 70 17 \ "I2C1" "Required for LED board and otherwise recommended " $I2C1_S \ "I2C0" "Required for LED board" $I2C0_S \ "SPI" "Required for LCD display" $SPI_S 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then SECTIONS=$(echo $SECTIONS | tr '"' ';' | tr ' ' ';') if [ ! -z $(echo "$SECTIONS" | grep "I2C0") ]; then sudo bash raspi-config nonint set_config_var dtparam=i2c_vc on /boot/config.txt else sudo bash raspi-config nonint set_config_var dtparam=i2c_vc off /boot/config.txt fi if [ ! -z $(echo "$SECTIONS" | grep "I2C1") ]; then sudo bash raspi-config nonint do_i2c 0 else sudo bash raspi-config nonint do_i2c 1 fi if [ ! -z $(echo "$SECTIONS" | grep "SPI") ]; then sudo bash raspi-config nonint do_spi 0 else sudo bash raspi-config nonint do_spi 1 fi fi } get_hostname() { cat /etc/hostname | tr -d " \t\n\r" } do_hostname() { whiptail --msgbox "\ Please note: RFCs mandate that a hostname's labels \ may contain only the ASCII letters 'a' through 'z' (case-insensitive), the digits '0' through '9', and the hyphen. Hostname labels cannot begin or end with a hyphen. No other symbols, punctuation characters, or blank spaces are permitted.\ " 20 70 1 CURRENT_HOSTNAME=`cat /etc/hostname | tr -d " \t\n\r"` NEW_HOSTNAME=$(whiptail --inputbox "Please enter a hostname" 20 60 "$CURRENT_HOSTNAME" 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then sudo hostnamectl set-hostname "$NEW_HOSTNAME" sudo sed -i '/127.0.1.1/c\127.0.1.1 '"$NEW_HOSTNAME" /etc/hosts fi } do_wpaMode() { WPAMODE=`sudo cat /etc/network/interfaces | grep wpa_supplicant.conf | awk -F' ' '{print $1}' | tr -d ' ' | tr -d '#'` CONF=OFF ROAM=OFF if [ "$WPAMODE" = "wpa-conf" ]; then CONF=ON fi if [ "$WPAMODE" = "wpa-roam" ]; then ROAM=ON fi msg="Choose WPA mode:" WPAMODE=$(whiptail --title "Wireless wpasupplicant" --radiolist \ "$msg" 15 60 4 \ "0" "Managed mode" $CONF \ "1" "Roaming" $ROAM 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then if [ "$WPAMODE" = "0" ]; then do_changeToWpaConf else do_changeToWpaRoam fi fi } do_openportConfig() { # Default: not enabled DEFAULT=--defaultno exists=`grep -F 'rn_check_openport.sh' /etc/crontab` if [ -z "$exists" ] then # Does not exist, so we add it, but disabled sudo bash -c "echo '#10 * * * * root /opt/GoIoT/DinGo/bin/network/rn_check_openport.sh' >> /etc/crontab" else STATUS=`cat /etc/crontab | grep rn_check_openport.sh | grep "#"` if [ "$STATUS" = "" ]; then # Default is enabled DEFAULT=0 fi fi whiptail --yesno "Would you like to enable Openport checker?" $DEFAULT 20 60 2 RET=$? if [ $RET = 0 ]; then # Activate the Openport checker in /etc/crontab (uncomment) sudo sed -i '/rn_check_openport.sh/s/^#//g' /etc/crontab STATUS=enabled else # Disable the Openport checker in /etc/crontab (comment) STATUS=`cat /etc/crontab | grep rn_check_openport.sh | grep "#"` if [ "$STATUS" = "" ]; then sudo sed -i '/rn_check_openport.sh/s/^/#/g' /etc/crontab fi STATUS=disabled fi whiptail --msgbox "Openport checker is now $STATUS" 20 60 1 } do_enableOneWireServer() { # Default: not enabled DEFAULT=--defaultno STATUS=`cat /etc/rc.local | grep owserver | grep "#"` if [ "$STATUS" = "" ]; then # Default is enabled DEFAULT=0 fi whiptail --yesno "Would you like to enable 1-Wire server?" $DEFAULT 20 60 2 RET=$? if [ $RET = 0 ]; then # Activate the owserver in rc.local (uncomment) sudo sed -i '/owserver/s/^#//g' /etc/rc.local whiptail --yesno "The 1-Wire server will start at next boot. Would you like to start it now?" 20 60 2 if [ $? -eq 0 ]; then # yes sudo /etc/init.d/owserver start fi STATUS=enabled else # Disable the owserver in rc.local (comment) STATUS=`cat /etc/rc.local | grep owserver | grep "#"` if [ "$STATUS" = "" ]; then sudo sed -i '/owserver/s/^/#/g' /etc/rc.local fi whiptail --yesno "The 1-Wire server will NOT start at next boot. Would you like to stop it now?" 20 60 2 if [ $? -eq 0 ]; then # yes sudo /etc/init.d/owserver stop fi STATUS=disabled fi whiptail --msgbox "1-Wire server is $STATUS" 20 60 1 } do_updatelogrotate() { # Check if logrotate file exists for DINGO-Stack echo "Check logrotate file..." FILE="/etc/logrotate.d/dingo-stack" if [ ! -f "$FILE" ]; then # Then download the file echo "Download logrotate file..." cd /etc/logrotate.d wget -N "http://apps.control2net.com/apt/misc/RPI/configfiles/etc/logrotate.d/dingo-stack" fi # Do some cleanup. Remove all backup files echo "Cleanup backup files..." sudo cp -p /etc/logrotate.d/dingo-stack.* /opt/GoIoT/backup 2>/dev/null sudo rm -f /etc/logrotate.d/dingo-stack.* # Check if upload script exists echo "Check upload script..." FILE="/opt/GoIoT/DinGo/bin/general/rn_upload_last_log.sh" if [ ! -f "$FILE" ]; then # Then download the file echo "Download upload script..." cd /opt/GoIoT/DinGo/bin/general wget -N "http://apps.control2net.com/apt/misc/RPI/configfiles/general/rn_upload_last_log.sh" sudo chmod +x rn_upload_last_log.sh fi # Do database update # Check if table exists. If it does, then check if records exists. If it does not, then add it. # Add hourly schedule to crontab # Check if schedule exists. If not then add it. echo "Set hourly schedule..." sudo grep -q -F 'logrotate.d/dingo-stack' /etc/crontab || sudo sed -i -e '$i \35 * * * * root logrotate /etc/logrotate.d/dingo-stack\n' /etc/crontab echo "Finished." } do_advancedOptions() { calc_wt_size while true; do FUN=$(whiptail --title "DINGO Configuration Tool (dingo-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Advanced options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ "1 Licenses" "Not implemented" \ "2 Configure LCD display" "What should be displayed and more" \ "3 Configure hardware clock" "Remove fake clock and setup HW clock" \ "4 OpenPort options" "Options for OpenPort" \ "5 Set hostname" "Set the hostname of the device" \ "6 Set WPA mode" "Wireless wpasupplicant conf." \ "7 1-Wire server" "Enable/disable one-wire server at startup" \ "8 I2C and SPI config." "Enable/disable I2C and SPI" \ "9 Logrotate DINGO log." "Activate and update logrotate" \ 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$FUN" in 1\ *) do_notImplemented ;; 2\ *) do_setupLCD ;; 3\ *) do_installHardwareClock ;; 4\ *) do_openportOptions ;; 5\ *) do_hostname ;; 6\ *) do_wpaMode ;; 7\ *) do_enableOneWireServer ;; 8\ *) do_i2cAndSpiConfig ;; 9\ *) do_updatelogrotate ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else exit 1 fi done } do_openportOptions() { calc_wt_size while true; do FUN=$(whiptail --title "DINGO Configuration Tool (dingo-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "OpenPort options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ "1 Install OpenPort" "Download and install latest" \ "2 OpenPort registration" "Register the OpenPort setup" \ "3 OpenPort checker config." "Enable/disable OpenPort checker" \ "4 Stop OpenPort" "Stops and disables the OpenPort service" \ 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$FUN" in 1\ *) do_installOpenPort ;; 2\ *) do_registerOpenPort ;; 3\ *) do_openportConfig ;; 4\ *) do_stopOpenPort ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else exit 1 fi done } do_uptime() { msg=$(sudo uptime) whiptail --title "Uptime" --msgbox "$msg" 10 70 } do_memoryUsage() { msg=$(sudo free -h) # /proc/meminfo whiptail --title "Memory usage" --msgbox "$msg" 10 100 } do_diskUsage() { msg=$(sudo df -BMB) whiptail --title "Disk usage" --msgbox "$msg" 20 70 } do_tempCheck() { current=$(/opt/vc/bin/vcgencmd measure_temp | awk -F'=' '{print $2}' | tr -d "'C") allTime="" file="/Adafruit_Python_SSD1306/examples/DEMO/all_time_max_temp.dat" if [ -f "$file" ]; then allTime=$(cat /Adafruit_Python_SSD1306/examples/DEMO/all_time_max_temp.dat | awk -F'=' '{print $2}') fi msg="Now: $current C'\nAll time max: $allTime C'\n" whiptail --title "Temperature" --msgbox "$msg" 20 70 } do_timeAndDate() { msg=$(sudo timedatectl) whiptail --title "Date and time" --msgbox "$msg" 10 70 } do_systemHealth() { calc_wt_size while true; do FUN=$(whiptail --title "DINGO Configuration Tool (dingo-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "System health" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ "1 Uptime and CPU load" "Show uptime for device" \ "2 Memory usage" "Show memory usage" \ "3 Disk usage" "Show disk usage" \ "4 Temperature" "Check temperature" \ "5 Date and time" "Show date and time on the device" \ 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then return 0 elif [ $RET -eq 0 ]; then case "$FUN" in 1\ *) do_uptime ;; 2\ *) do_memoryUsage ;; 3\ *) do_diskUsage ;; 4\ *) do_tempCheck ;; 5\ *) do_timeAndDate ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else exit 1 fi done } INTERACTIVE=True if [ "$INTERACTIVE" = True ]; then #if is_pi && ! mountpoint -q /boot; then # whiptail --msgbox "The boot partition is not mounted - cannot configure. Note that raspi-config is intended for use on Raspbian only and cannot be guaranteed to work on other operating systems." 20 60 1 # exit 1 #fi #[ -e $CONFIG ] || touch $CONFIG calc_wt_size while true; do FUN=$(whiptail --title "DINGO Configuration Tool (dingo-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \ "1 Install software" "Install the DINGO-Stack and other software" \ "2 Upgrade software" "Upgrade the DINGO-Stack and other software" \ "3 Network setup" "Configure the DINGO-Stack networking setup" \ "4 Advanced settings" "Other configuration" \ "5 System health" "System checkup" \ "6 About dingo-config" "Information about this configuration tool" \ "7 raspi-config" "Shortcut to the Raspberry Pi configuration tool" \ "8 Reboot" "Reboot device" 3>&1 1>&2 2>&3) RET=$? if [ $RET -eq 1 ]; then do_finish elif [ $RET -eq 0 ]; then case "$FUN" in 1\ *) do_installSoftware ;; 2\ *) do_upgradeSoftware ;; 3\ *) do_networkSetup ;; 4\ *) do_advancedOptions ;; 5\ *) do_systemHealth ;; 6\ *) do_about ;; 7\ *) sudo raspi-config ;; 8\ *) do_reboot ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else exit 1 fi done fi