Advertisement
Guest User

P.S. Script 2019

a guest
Feb 6th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 57.77 KB | None | 0 0
  1. ##
  2. ## "THE SCRIPT" is the product of many months of work and includes (if you select them):
  3. ## This version January 2019 includes changes to handle Node 8/Node Red updates on Raspbian
  4. ## (Raspberry Pi - tested on Raspbian Stretch Lite - https://downloads.raspberrypi.org/raspbian_lite_latest
  5. # but the full version would work as well)
  6. ## Many thanks to Antonio (Mr Shark) for his work on some of these changes.
  7. ##
  8. ##    Mosquitto (port 1883) with web sockets (Port 9001)
  9. ##    SQLITE ( xxx.xxx.xxx.xxx/phpliteadmin),
  10. ##    Node-Red (xxx.xxx.xxx:1880)
  11. ##    Node-Red-Dashboard (xxx.xxx.xxx.xxx:1880/ui)
  12. ##    Webmin (xxx.xxx.xxx:10000)
  13. ##    Apache (xxx.xxx.xxx)
  14. ##    mpg123
  15. ##    and Grafana (xxx.xxx.xxx:3000)
  16. ##    also web-page-based software like mc and /phpsysinfo
  17. ##    Jan 17 2019 I added nmap, netdiscover and also node-red-contrib-advanced-ping
  18. ##
  19. ## Regards - Peter Scargill  https://tech.scargill.net  - See also: BigTimer and ESP-GO
  20. ##
  21. ## IMPORTANT:-
  22. ## 1. Run ONLY as ROOT (or PI user on Raspberry Pi). If ROOT, PI user will be checked/created for you as the main
  23. ##    script must be run as pi.
  24. ##    User PI must be in the SUDO group. Other groups are added by the script.
  25. ## 2. When selecting GPIO for non-Raspberry Pi devices note - specific support for ODROID C2 only
  26. ## 3. This script could take 3+ hours on a slow Pi Zero Wifi.... steer away from midnight to avoid any updates
  27. ##    such as dietpi upgrades etc.
  28. ## 4. For non-Raspberry Pi systems, when asked by Armbian to make a new user - don't bother - the script will do it.
  29. ## 5. For Node-Red on Pi Zero,  if the serial port won't connect - look at serial port permissions in /dev/
  30. ## 6. Do not access this script as SUDO.
  31. ##
  32. ## For Log2RAM customising see this - https://github.com/azlux/log2ram
  33. ##
  34. ## See https://tech.scargill.net/orange-pi-pc-battle-of-the-pis/
  35. ##
  36. ## We cannot answer questions on board/operating system comninations we have not tested. See notes below for tested combos.
  37. ##
  38. ## 20/08/2018 Fixed Java and settings.js generation, added menu option (default: UNCHECKED) to enable/disable HW support (I2C, GPIO, Serial, etc)
  39. ## 01/05/2018 Redone InfluxDB/Grafana/Chronograf install, now works on every platform tested, and succesfully tested on Rock64+eMMc
  40. ## 05/10/2017 Added glances - use directly - glances - or as webserver glances -w
  41. ## 08/09/2017 Added name change for Node-Red flows files - and tested Roseapple Pi with DietPi successfully
  42. ## 31/08/2017 Scrapped JED as MC is much better - added rpi-clone which works a treat with NANOPI
  43. ## 30/08/2017 Changed Webmin to NOT be installed by default
  44. ## 24/08/2017 Tested Ubuntu on Odroid C2 and Roseapple Pi
  45. ## 23/08/2017 Tested on the NanoPi K2 board running Ubuntu, installs perfectly (but note that
  46. ## FriendlyArm's WiringPi i2c is currently bust)
  47. ## 18/08/2017 Modified to handle latest Raspbian Stretch - tested on RPI3
  48. ## 10/08/2017 Added "nrlog" utility for viewing and "tailing" - i.e. monitoring node-red logs in colour in
  49. ## a terminal
  50. ## 10/08/2017 Tested RPI3 - turns out the new GPIO nodes work perfectly on that - as does i2c
  51. ##  - commenting out the RPI contrib GPIO as it needs ROOT permissions!!!!!
  52. ## see https://tech.scargill.net/the-real-raspberry-pi/
  53. ## 29/07/2017 Added rule to help node-red-contrib-opi-gpio utility with various boards using GPIO. See docs
  54. ## for that node - very promising - tried various nano boards with success
  55. ## 24/07/2017 Tested on the new NanoPi Neo Plus2 - worked a treat - I2c running - lovely
  56. ## 24/07/2017 Tested on a Raspberry Pi 2 using current Jessie
  57. ## 24/07/2017 Tested NanoPi Neo Air using Ubuntu Core Xenial 4.11.2
  58. ## 30/06/2017 added LOG FILE generation, same folder and name as script + datetime + .log - by MrShark
  59. ## 26/06/2017 added support for Debian 9 (Stretch), right now only tested in VM - by MrShark
  60. ## 26/04/2017 added option for Log2Ram
  61. ## 26/04/2017 Updated NodeJS as they took the previous version off the server!!!
  62. ## 29/03/2017 Tested on NanoPi Neo2 using Armbian nightly build of 27/03/2017 - added temperature and processor checks
  63. ## 25/03/2017 Tested on NanoPi M1+, host updating added and defaults on inputs added
  64. ## 18/03/2017 Tested on NanoPi M3
  65. ## 16/03/2017 Modifications to handle experimental Android Phone setup
  66. ## 10/03/2017 Modifications to detect and run with the Raspberry Pi Zero Lite (ARM6) (not recommended, Zero is very slow)
  67. ## 30/01/2017 Minor change to let the script work on Mint Linux on a laptop (Looks like Ubuntu)
  68. ## 14/01/2017 Updated webmin and habridge installations
  69. ## 04/01/2017 Tested DietPi on Orange Pi Zero - installed perfectly - 1 hour. WIFI still iffy
  70. ## 04/07/2017 OrangePi Plus 2 - thanks to blog reader RoyG for that
  71. ## 26/12/2016 - complete re-hash for new menus
  72.  
  73. ## 02/12/2016 Tested Roseapple Pi using Armbian - for Node-Red serial, had to
  74. ## enable permissions for the serial - everything worked first time
  75. ## 16/5/2016 Tested on NanoPi M1 - (got 3 UARTS out of the M1)
  76.  
  77. ## 22/06/2016 tested on NanoPi NEO using Armbian Jessie Server
  78. ## 28/12/2016 tested in DietPi and Xenial virtual machines
  79. ## http://www.armbian.com/donate/?f=Armbian_5.20_Nanopineo_Debian_jessie_3.4.112.7z
  80. ##
  81. ## NOTE:- removed node-red-contrib-admin from Node-red setup as you can now do installs in the palette manager
  82. ## within the editor
  83. ## Note also  - the PHONE setting is experimental assuming an Android phone, rooted and set up with "Linux Deploy"
  84. ## as per the relevant blog entry on https://tech.scargill.net
  85. ##
  86. ## Typically, sitting in your home directory (/home/pi) as user Pi you might want to use NANO to install this script
  87. ## and after giving the script execute permission (sudo chmod 0744 /home/pi/script.sh)
  88. ## you could run the file as ./script.sh
  89. ##
  90. ##
  91. ## Note- on the Odroid C2 everything installed except webmin. After reboot this is what I did to get it running..
  92. ##    wget http://prdownloads.sourceforge.net/webadmin/webmin_1.850_all.deb
  93. ##    sudo dpkg --install webmin_1.850_all.deb
  94. ##    That complained about missing bits so I used...
  95. ##       sudo apt-get install -y perl libnet-ssleay-perl openssl libauthen-pam-perl
  96. ##       libpam-runtime libio-pty-perl apt-show-versions python
  97. ##    That seemed to fail and suggested I use...
  98. ##       sudo apt-get -y -f install
  99. ##    That installed the lot - working - something to do with it being 64 bits - but it works -
  100. ##    pi or root user and password and https://whatever:10000
  101. ##
  102. ## Thanks for contributions from Antonio Fragola, Aidan Ruff and others. Thank you.
  103. ##
  104. ## Node-Red security added as standard - using the ADMIN login. MQTT also has same ADMIN login.
  105. ##
  106. ## ROUTINES
  107. ## Here at the beginning, a load of useful routines - see further down
  108.  
  109. # Get time as a UNIX timestamp (seconds elapsed since Jan 1, 1970 0:00 UTC)
  110. startTime="$(date +%s)"
  111. columns=$(tput cols)
  112. user_response=""
  113.  
  114. # High Intensity
  115. IGreen='\e[0;92m'       # Green
  116. IYellow='\e[0;93m'      # Yellow
  117. IBlue='\e[0;94m'        # Blue
  118. ICyan='\e[0;96m'        # Cyan
  119. IWhite='\e[0;97m'       # White
  120.  
  121. # Bold High Intensity
  122. BIRed='\e[1;91m'        # Red
  123. BIGreen='\e[1;92m'      # Green
  124. BIYellow='\e[1;93m'     # Yellow
  125. BIPurple='\e[1;95m'     # Purple
  126. BIMagenta='\e[1;95m'    # Purple
  127. BICyan='\e[1;96m'       # Cyan
  128. BIWhite='\e[1;97m'      # White
  129.  
  130. skip=0
  131. other=0
  132.  
  133. clean_stdin()
  134. {
  135.     while read -r -t 0; do
  136.         read -n 256 -r -s
  137.     done
  138. }
  139.  
  140. # Permanent loop until both passwords are the same..
  141. function user_input {
  142.     local VARIABLE_NAME=${1}
  143.     local VARIABLE_NAME_1="A"
  144.     local VARIABLE_NAME_2="B"
  145.     while true; do
  146.         printf "${BICyan}$2: ${BIWhite}";
  147.         if [ "$3" = "hide" ] ; then
  148.             stty -echo;
  149.         fi
  150.         read VARIABLE_NAME_1;
  151.         stty echo;
  152.         if [ "$3" = "hide" ] ; then
  153.             printf "\n${BICyan}$2 (again) : ${BIWhite}";
  154.             stty -echo;
  155.             read VARIABLE_NAME_2;
  156.             stty echo;
  157.         else
  158.             VARIABLE_NAME_2=$VARIABLE_NAME_1;
  159.         fi
  160.         if [ $VARIABLE_NAME_1 != $VARIABLE_NAME_2 ] ; then
  161.             printf "\n${BIRed}Sorry, did not match!${BIWhite}\n";
  162.         else
  163.             break;
  164.         fi
  165.     done
  166.     readonly ${VARIABLE_NAME}=$VARIABLE_NAME_1;
  167.     if [ "$3" == "hide" ] ; then
  168.         printf "\n";
  169.     fi
  170. }
  171.  
  172. stopit=0
  173. other=0
  174. yes=0
  175. nohelp=0
  176. hideother=0
  177.  
  178. timecount(){
  179.     sec=30
  180.     while [ $sec -ge 0 ]; do
  181.         if [ $nohelp -eq 1 ]; then
  182.            
  183.             if [ $hideother -eq 1 ]; then
  184.                 printf "${BIPurple}Continue ${BIWhite}y${BIPurple}(es)/${BIWhite}n${BIPurple}(o)/${BIWhite}a${BIPurple}(ll)/${BIWhite}e${BIPurple}(nd)-  ${BIGreen}00:0$min:$sec${BIPurple} remaining\033[0K\r${BIWhite}"
  185.             else
  186.                 printf "${BIPurple}Continue ${BIWhite}y${BIPurple}(es)/${BIWhite}o${BIPurple}(ther)/${BIWhite}e${BIPurple}(nd)-  ${BIGreen}00:0$min:$sec${BIPurple} remaining\033[0K\r${BIWhite}"
  187.             fi
  188.         else
  189.             printf "${BIPurple}Continue ${BIWhite}y${BIPurple}(es)/${BIWhite}h${BIPurple}(elp)-  ${BIGreen}00:0$min:$sec${BIPurple} remaining\033[0K\r${BIWhite}"
  190.         fi
  191.         sec=$((sec-1))
  192.         trap '' 2
  193.         stty -echo
  194.         read -t 1 -n 1 user_response
  195.         stty echo
  196.         trap - 2
  197.         if [ -n  "$user_response" ]; then
  198.             break
  199.         fi
  200.     done
  201. }
  202.  
  203.  
  204. task_start(){
  205.     printf "\r\n"
  206.     printf "${BIGreen}%*s\n" $columns | tr ' ' -
  207.     printf "$1"
  208.     clean_stdin
  209.     skip=0
  210.     printf "\n${BIGreen}%*s${BIWhite}\n" $columns | tr ' ' -
  211.     elapsedTime="$(($(date +%s)-startTime))"
  212.     printf "Elapsed: %02d hrs %02d mins %02d secs\n" "$((elapsedTime/3600%24))" "$((elapsedTime/60%60))" "$((elapsedTime%60))"
  213.     clean_stdin
  214.     if [ "$user_response" != "a" ]; then
  215.         timecount
  216.     fi
  217.     echo -e "                                                                        \033[0K\r"
  218.     if  [ "$user_response" = "e" ]; then
  219.         printf "${BIWhite}"
  220.         exit 1
  221.     fi
  222.     if  [ "$user_response" = "n" ]; then
  223.         skip=1
  224.     fi
  225.     if  [ "$user_response" = "o" ]; then
  226.         other=1
  227.     fi
  228.     if  [ "$user_response" = "h" ]; then
  229.         stopit=1
  230.     fi
  231.     if  [ "$user_response" = "y" ]; then
  232.         yes=1
  233.     fi
  234.     if [ -n  "$2" ]; then
  235.         if [ $skip -eq 0 ]; then
  236.             printf "${BIYellow}$2${BIWhite}\n"
  237.         else
  238.             printf "${BICyan}%*s${BIWhite}\n" $columns '[SKIPPED]'
  239.         fi
  240.     fi
  241. }
  242.  
  243. task_end(){
  244.     printf "${BICyan}%*s${BIWhite}\n" $columns '[OK]'
  245. }
  246.  
  247.  
  248. # credits to DietPi
  249.  
  250. CPU_TEMP_CURRENT='Unknown'
  251. CPU_TEMP_PRINT='Unknown'
  252. ACTIVECORES=$(grep -c processor /proc/cpuinfo)
  253.  
  254. #Array to store possible locations for temp read.
  255. aFP_TEMPERATURE=(
  256.     '/sys/class/thermal/thermal_zone0/temp'
  257.     '/sys/devices/virtual/thermal/thermal_zone1/temp'
  258.     '/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input'
  259.     '/sys/class/hwmon/hwmon0/device/temp_label'
  260. )
  261.  
  262. Obtain_Cpu_Temp(){
  263.     for ((i=0; i<${#aFP_TEMPERATURE[@]}; i++))
  264.     do
  265.         if [ -f "${aFP_TEMPERATURE[$i]}" ]; then
  266.             CPU_TEMP_CURRENT=$(cat "${aFP_TEMPERATURE[$i]}")
  267.             # - Some devices (pine) provide 2 digit output, some provide a 5 digit ouput.
  268.             #       So, If the value is over 1000, we can assume it needs converting to 1'c
  269.             if (( $CPU_TEMP_CURRENT == 0 )); then
  270.                 continue
  271.             fi
  272.             if (( $CPU_TEMP_CURRENT >= 1000 )); then
  273.                 CPU_TEMP_CURRENT=$( echo -e "$CPU_TEMP_CURRENT" | awk '{print $1/1000}' | xargs printf "%0.0f" )
  274.             fi
  275.             if (( $CPU_TEMP_CURRENT >= 70 )); then
  276.                 CPU_TEMP_PRINT="\e[91mWarning: $CPU_TEMP_CURRENT'c\e[0m"
  277.                 elif (( $CPU_TEMP_CURRENT >= 60 )); then
  278.                 CPU_TEMP_PRINT="\e[38;5;202m$CPU_TEMP_CURRENT'c\e[0m"
  279.                 elif (( $CPU_TEMP_CURRENT >= 50 )); then
  280.                 CPU_TEMP_PRINT="\e[93m$CPU_TEMP_CURRENT'c\e[0m"
  281.                 elif (( $CPU_TEMP_CURRENT >= 40 )); then
  282.                 CPU_TEMP_PRINT="\e[92m$CPU_TEMP_CURRENT'c\e[0m"
  283.                 elif (( $CPU_TEMP_CURRENT >= 30 )); then
  284.                 CPU_TEMP_PRINT="\e[96m$CPU_TEMP_CURRENT'c\e[0m"
  285.             else
  286.                 CPU_TEMP_PRINT="\e[96m$CPU_TEMP_CURRENT'c\e[0m"
  287.             fi
  288.             break
  289.         fi
  290.     done
  291. }
  292.  
  293. LOGFILE=$HOME/$0-`date +%Y-%m-%d_%Hh%Mm`.log
  294.  
  295. printl() {
  296.     printf $1
  297.     echo -e $1 >> $LOGFILE
  298. }
  299.  
  300. printstatus() {
  301.     Obtain_Cpu_Temp
  302.     h=$(($SECONDS/3600));
  303.     m=$((($SECONDS/60)%60));
  304.     s=$(($SECONDS%60));
  305.     printf "\r\n${BIGreen}==\r\n== ${BIYellow}$1"
  306.     printf "\r\n${BIGreen}== ${IBlue}Total: %02dh:%02dm:%02ds Cores: $ACTIVECORES Temperature: $CPU_TEMP_PRINT \r\n${BIGreen}==${IWhite}\r\n\r\n"  $h $m $s;
  307.     echo -e "############################################################" >> $LOGFILE
  308.     echo -e $1 >> $LOGFILE
  309. }
  310.  
  311.  
  312. ############################################################################
  313. ##
  314. ## MAIN SECTION OF SCRIPT - action begins here
  315. ##
  316. #############################################################################
  317. ##
  318.  
  319. printstatus "Welcome to THE SCRIPT!"
  320.  
  321. AQUIET="-qq"
  322. NQUIET="-s"
  323.  
  324. # install sudo on devices without it
  325. [ ! -x /usr/bin/sudo ] && apt-get $AQUIET -y update > /dev/null 2>&1 && apt-get $AQUIET -y install sudo 2>&1 | tee -a $LOGFILE
  326.  
  327. # Whiptail menu may already be installed by default, on the other hand maybe not.
  328. sudo apt-get $AQUIET -y install whiptail ccze 2>&1 | tee -a $LOGFILE
  329. # Another way - Xenial should come up in upper case in $DISTRO
  330. . /etc/os-release
  331. OPSYS=${ID^^}
  332. echo -e OPSYS: $OPSYS >> $LOGFILE
  333.  
  334. printstatus "Grabbing some preliminaries..."
  335.  
  336. # test internet connection
  337. sudo chmod u+s /bin/ping
  338. if [[ "$(ping -c 1 23.1.68.60  | grep '100%' )" != "" ]]; then
  339.     printl "${IRed}!!!! No internet connection available, aborting! ${IWhite}\r\n"
  340.     exit 0
  341. fi
  342.  
  343. # install lsb_release on devices without it
  344. [ ! -x /usr/bin/lsb_release ] && apt-get $AQUIET -y update > /dev/null 2>&1 && apt-get $AQUIET -y install lsb-release 2>&1 | tee -a $LOGFILE
  345. DISTRO=$(/usr/bin/lsb_release -rs)
  346. CHECK64=$(uname -m)
  347. echo -e DISTRO: $DISTRO >> $LOGFILE
  348. echo -e CHECK64: $CHECK64 >> $LOGFILE
  349.  
  350. if [[ $OPSYS == *"UBUNTU"* ]]; then
  351.     if [ $DISTRO != "16.04" ] ; then
  352.         printl "${IRed}!!!! Wrong version of Ubuntu - not 16.04, aborting! ${IWhite}\r\n"
  353.         exit 0
  354.     fi
  355. fi
  356.  
  357. # user pi existance/creation
  358. echo -e USER: $USER >> $LOGFILE
  359. if [[ $USER != "pi" ]]; then
  360.     if [[ $USER == "root" ]]; then
  361.         printf "\r\n${ICyan}Hello ROOT... ${IWhite}"
  362.         getent passwd pi > /dev/null 2>&1
  363.         if [ $? -eq 0 ]; then
  364.             printf "${ICyan}user \"pi\" exists, please log-out as root and run script as pi.${IWhite}\r\n\r\n"
  365.             usermod pi -g sudo -G ssh -a
  366.             echo "pi ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/pi
  367.             chmod 0440 /etc/sudoers.d/pi
  368.             chmod 4755 /usr/bin/sudo           
  369.             cp $(readlink -f $0) /home/pi && chown pi.pi /home/pi/$0 && chmod 755 /home/pi/$0
  370.             chown pi.pi $LOGFILE && chmod 644 $LOGFILE && cp $LOGFILE /home/pi
  371.         else
  372.             adduser --quiet --disabled-password --shell /bin/bash --home /home/pi --gecos "User" pi
  373.             echo "pi:password" | chpasswd
  374.             usermod pi -g sudo -G ssh -a
  375.             echo "pi ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/pi
  376.             chmod 0440 /etc/sudoers.d/pi
  377.             chmod 4755 /usr/bin/sudo
  378.             printf "${ICyan}user PI created, password is \"password\". Please log-out as root and login as pi, and redo the procedure ${IWhite}\r\n\r\n"
  379.             cp $(readlink -f $0) /home/pi && chown pi.pi /home/pi/$0 && chmod 755 /home/pi/$0
  380.             chown pi.pi $LOGFILE && chmod 644 $LOGFILE && cp $LOGFILE /home/pi
  381.         fi
  382.         exit
  383.     else
  384.         printstatus "Leaving script as you are neither PI nor ROOT user."
  385.         exit
  386.     fi
  387. else
  388.     sudo touch /etc/AlreadyRun
  389. fi
  390.  
  391. if [ ! -f /etc/AlreadyRun ]; then
  392.     printstatus "Stopping IPV6 access"
  393.     echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf > /dev/null 2>&1
  394.     echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf > /dev/null 2>&1
  395.     echo "net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf > /dev/null 2>&1
  396.     sudo sysctl -p
  397.  
  398.     printstatus "Allow remote root login and speed up SSH"
  399.     sudo sed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
  400.     sudo sed -i -e 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
  401.     sudo sed -i -e 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
  402.     sudo sed -i -e 's/TCPKeepAlive yes/TCPKeepAlive no/g' /etc/ssh/sshd_config
  403.     sudo sed -i '$ a UseDNS no' /etc/ssh/sshd_config
  404.     sudo sed -i '$ a ClientAliveInterval 30' /etc/ssh/sshd_config
  405.     sudo sed -i '$ a ClientAliveCountMax 100' /etc/ssh/sshd_config
  406.     sudo /etc/init.d/ssh restart 2>&1 | tee -a $LOGFILE
  407.  
  408.     sudo update-alternatives --set newt-palette /etc/newt/palette.original 2>&1 | tee -a $LOGFILE
  409.  
  410.     # setup a progress bar
  411.     echo "Dpkg::Progress-Fancy \"1\";" | sudo tee /etc/apt/apt.conf.d/99progressbar > /dev/null
  412.     echo "APT::Color \"1\";" | sudo tee -a /etc/apt/apt.conf.d/99progressbar > /dev/null
  413.    
  414.     if [[ $OPSYS != *"RASPBIAN"* ]]; then
  415.         printstatus "Adding user Pi permissions"
  416.         for additionalgroup in cdrom games users i2c adm gpio input sudo netdev audio video dialout plugdev bluetooth ; do
  417.             getent group ${additionalgroup} | grep -w -l pi || sudo adduser pi ${additionalgroup} 2>&1 | tee -a $LOGFILE
  418.         done
  419.     fi
  420.     sudo apt-get install avahi-daemon avahi-utils -y 2>&1 | tee -a $LOGFILE
  421.     sudo sed -i -e 's/use-ipv6=yes/use-ipv6=no/g' /etc/avahi/avahi-daemon.conf
  422. else
  423.         printstatus "Script is re-running, avoiding un-necessary repeats"
  424. fi
  425.  
  426. if [[ $OPSYS == "LINUXMINT" ]]; then
  427.     OPSYS="UBUNTU"
  428. fi
  429.  
  430. if [[ $OPSYS != *"RASPBIAN"* ]] && [[ $OPSYS != *"DEBIAN"* ]] && [[ $OPSYS != *"UBUNTU"* ]] && [[ $OPSYS != *"DIETPI"* ]]; then
  431.     printl "${BIRed}By the look of it, not one of the supported operating systems - aborting${BIWhite}\r\n"; exit
  432. fi
  433.  
  434. username="user"
  435. userpass="password123"
  436.  
  437. adminname="admin"
  438. adminpass="password123"
  439.  
  440. newhostname=$(hostname)
  441.  
  442. SECONDS=0
  443.  
  444. if [[ $OPSYS == *"RASPBIAN"* ]];then
  445.     MYMENU=$(whiptail --title "Main Raspberry Pi Selection" --checklist \
  446.         "\nSelect items for your Pi as required then hit OK" 28 73 21 \
  447.         "quiet" "Quiet(er) install - untick for lots of info " ON \
  448.         "prereq" "Install general pre-requisites " ON \
  449.         "mosquitto" "Install Mosquitto" ON \
  450.         "apache" "Install Apache/PHP/SQLITE + PHPLITEADMIN " ON \
  451.         "nodenew" "Install NodeJS and NodeRed (NEW)" ON \
  452.         "nodejs" "Install NodeJS" OFF \
  453.         "nodered" "Install Node-Red" OFF \
  454.         "webmin" "Install Webmin" OFF \
  455.         "java" "Update Java" ON \
  456.         "hwsupport" "Enable support for Serial, I2C, GPIO, etc" OFF \
  457.         "wiringpi" "Wiring Pi for the GPIO utility" OFF \
  458.         "phpsysinfo" "Install PHPSYSYINFO" ON \
  459.         "modpass" "Mod USER and ADMIN passwords (password123)" ON \
  460.         "addindex" "Add an index page and some CSS" ON \
  461.         "passwords" "Update ROOT and PI user passwords" OFF \
  462.         "habridge" "Install HA-bridge on port 82" OFF \
  463.         "rpiclone" "Install RPI-Clone" ON \
  464.         "log2ram" "Install Log2RAM default 40Meg" OFF \
  465.         "grafana" "Install Grafana and InfluxDB" OFF \
  466.         "wolfram" "Remove Wolfram on a PI to save space" OFF \
  467.         "office" "Remove LibreOffice on PI to save space" OFF 3>&1 1>&2 2>&3)
  468. else
  469.     MYMENU=$(whiptail --title "Main Non-Pi Selection" --checklist \
  470.         "\nSelect items as required then hit OK" 30 73 23 \
  471.         "quiet" "Quiet(er) install - untick for lots of info " ON \
  472.         "prereq" "Install general pre-requisites" ON \
  473.         "mosquitto" "Install Mosquitto" ON \
  474.         "apache" "Install Apache/PHP/SQLITE + PHPLITEADMIN" ON \
  475.         "nodenew" "Install NodeJS and NodeRed (NEW)" ON \
  476.         "nodejs" "Install NodeJS" OFF \
  477.         "nodered" "Install Node-Red" OFF \
  478.         "webmin" "Install Webmin" OFF \
  479.         "java" "Update Java" ON \
  480.         "hwsupport" "Enable support for Serial, I2C, GPIO, etc" OFF \
  481.         "phone" "Install on Android Smartphone - see blog" OFF \
  482.         "odroid" "Install ODROID C2-specific GPIO" OFF \
  483.         "generich3" "Install GENERIC H3 GPIO (not Raspberry Pi) " OFF \
  484.         "opimonitor" "Install OPI-Monitor - H3 ONLY" OFF \
  485.         "phpsysinfo" "Install PHPSYSYINFO" ON \
  486.         "modpass" "Mod USER and ADMIN passwords (password123)" ON \
  487.         "addindex" "Add an index page and some CSS" ON \
  488.         "passwords" "Update ROOT and PI user passwords" OFF \
  489.         "habridge" "Install HA-bridge on port 82" OFF \
  490.         "rpiclone" "Install RPI-Clone" ON \
  491.         "log2ram" "Install Log2RAM default 40Meg" OFF \
  492.         "grafana" "Install Grafana and InfluxDB" OFF 3>&1 1>&2 2>&3)
  493. fi
  494.  
  495. if [[ $MYMENU != *"quiet"* ]]; then
  496.     AQUIET=""
  497.     NQUIET=""
  498. fi
  499.  
  500. if [[ $MYMENU == "" ]]; then
  501.     whiptail --title "Installation Aborted" --msgbox "Cancelled as requested." 8 78
  502.     exit
  503. fi
  504.  
  505. cd
  506. newhostname=$(whiptail --inputbox "Enter new HOST name\nLeave the default value or select something new" 8 60 $newhostname 3>&1 1>&2 2>&3)
  507.  
  508. if [[ $MYMENU == *"modpass"* ]]; then
  509.    
  510.     username=$(whiptail --inputbox "Enter a USER name (example user)\nSpecifically for Node-Red Dashboard" 8 60 $username 3>&1 1>&2 2>&3)
  511.     if [[ -z "${username// }" ]]; then
  512.         printf "No user name given - aborting\r\n"; exit
  513.     fi
  514.    
  515.     userpass=$(whiptail --passwordbox "Enter a user password" 8 60 3>&1 1>&2 2>&3)
  516.     if [[ -z "${userpass// }" ]]; then
  517.         printf "No user password given - aborting${BIWhite}\r\n"; exit
  518.     fi
  519.    
  520.     userpass2=$(whiptail --passwordbox "Confirm user password" 8 60 3>&1 1>&2 2>&3)
  521.     if  [ $userpass2 == "" ]; then
  522.         printf "${BIRed}No password confirmation given - aborting${BIWhite}\r\n"; exit
  523.     fi
  524.     if  [ $userpass != $userpass2 ]
  525.     then
  526.         printf "${BIRed}Passwords don't match - aborting${BIWhite}\r\n"; exit
  527.     fi
  528.    
  529.     adminname=$(whiptail --inputbox "Enter an ADMIN name (example admin)\nFor Node-Red and MQTT" 8 60 $adminname 3>&1 1>&2 2>&3)
  530.     if [[ -z "${adminname// }" ]]; then
  531.         printf "${BIRed}No admin name given - aborting${BIWhite}\r\n"
  532.         exit
  533.     fi
  534.    
  535.     adminpass=$(whiptail --passwordbox "Enter an admin password" 8 60 3>&1 1>&2 2>&3)
  536.     if [[ -z "${adminpass// }" ]]; then
  537.         printf "${BIRed}No user password given - aborting${BIWhite}\r\n"; exit
  538.     fi
  539.    
  540.     adminpass2=$(whiptail --passwordbox "Confirm admin password" 8 60 3>&1 1>&2 2>&3)
  541.     if  [ $adminpass2 == "" ]; then
  542.         printf "${BIRed}No password confirmation given - aborting${BIWhite}\r\n"; exit
  543.     fi
  544.     if  [ $adminpass != $adminpass2 ]; then
  545.         printf "${BIRed}Passwords don't match - aborting${BIWhite}\r\n"; exit
  546.     fi
  547. fi
  548.  
  549. if [[ $MYMENU == *"passwords"* ]]; then
  550.     echo "Update your PI password"
  551.     sudo passwd pi
  552.     echo "Update your ROOT password"
  553.     sudo passwd root
  554. fi
  555.  
  556. if [[ $MYMENU == *"phone"* ]]; then
  557.     echo "en_US.UTF-8 UTF-8" | sudo tee -a /etc/locale.gen > /dev/null
  558.     # echo "service rsyslog stop" | sudo tee -a /etc/init.d/rc.local > /dev/null
  559.     sudo update-rc.d rsyslog disable 2>&1 | tee -a $LOGFILE
  560.     sudo locale-gen 2>&1 | tee -a $LOGFILE
  561.     sudo sed -i -e 's#exit 0##g' /etc/rc.local
  562.     echo "cd /home/pi/habridge" | sudo tee -a /etc/rc.local > /dev/null
  563.     echo "[ -f /home/pi/habridge/habridge-log.txt ] && rm /home/pi/habridge/habridge-log.txt" | sudo tee -a /etc/rc.local > /dev/null
  564.     echo "nohup /usr/bin/java -jar -Dserver.port=82 -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge.jar > /home/pi/habridge/habridge-log.txt 2>&1 &" | sudo tee -a /etc/rc.local > /dev/null
  565.     echo "chmod 777 /home/pi/habridge/habridge-log.txt" | sudo tee -a /etc/rc.local > /dev/null
  566.     echo "exit 0" | sudo tee -a /etc/rc.local > /dev/null
  567. fi
  568.  
  569. if [[ $MYMENU == *"wolfram"* ]]; then
  570.     printstatus "Removing Wolfram"
  571.     sudo apt-get $AQUIET -y purge wolfram-engine 2>&1 | tee -a $LOGFILE
  572. fi
  573.  
  574. if [[ $MYMENU == *"office"* ]]; then
  575.     printstatus "Removing LibreOffice"
  576.     sudo apt-get $AQUIET -y remove --purge libreoffice* 2>&1 | tee -a $LOGFILE
  577. fi
  578.  
  579. if [[ $MYMENU == *"prereq"* ]]; then
  580.     printstatus "Installing pre-requisites (this could take some time)"
  581.     sudo apt-get $AQUIET -y autoremove 2>&1 | tee -a $LOGFILE
  582.     sudo apt-get $AQUIET  update 2>&1 | tee -a $LOGFILE
  583.     sudo apt-get $AQUIET -y upgrade 2>&1 | tee -a $LOGFILE
  584.     # fix for RPI treating PING as a root function - by Dave
  585.     sudo setcap cap_net_raw=ep /bin/ping > /dev/null 2>&1
  586.     sudo setcap cap_net_raw=ep /bin/ping6 > /dev/null 2>&1
  587.     # Prerequisite suggested by Julian and adding in python-dev - and stuff I've added for SAMBA and telnet, and Common utilities
  588.  
  589.     sudo apt-get install $AQUIET -y nmap netdiscover
  590.     sudo apt install $AQUIET -y sysfsutils
  591.     sudo apt-get install $AQUIET -y apt-utils 2>&1 | tee -a $LOGFILE # a line on its own, as on some boards caused problems on next one...
  592.     sudo apt-get install $AQUIET -y bash-completion unzip build-essential git python-serial scons libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libsqlite3-dev subversion libcurl4-openssl-dev libusb-dev python-dev cmake curl telnet usbutils gawk jq pv samba samba-common samba-common-bin winbind dosfstools parted gcc python-pip htop python-smbus mc cu mpg123 screen 2>&1 | tee -a $LOGFILE
  593.     sudo pip -q install psutil 2>&1 | tee -a $LOGFILE
  594.     sudo -H pip -q install feedparser 2>&1 | tee -a $LOGFILE
  595.     # This line to ensure name is resolved from hosts FIRST
  596.     sudo sed -i '/\[global\]/a name resolve order = hosts wins bcast' /etc/samba/smb.conf
  597.  
  598.     if [[ $MYMENU == *"hwsupport"* ]]; then
  599.         sudo apt-get install $AQUIET -y i2c-tools 2>&1 | tee -a $LOGFILE
  600.     fi
  601. fi
  602.  
  603. if [[ $MYMENU == *"mosquitto"* ]]; then
  604.     printstatus "Installing Mosquitto with Websockets"
  605.     cd
  606.     if [[ $OPSYS == *"UBUNTU"* ]]; then
  607.         sudo apt-get $AQUIET -y install mosquitto mosquitto-clients 2>&1 | tee -a $LOGFILE
  608.         [ $? -eq 0 ] && mosquitto=1 # mosquitto installed
  609.     else
  610.         if [[ $OPSYS == *"BIAN"* ]] && [[ $DISTRO == *"9."* ]]; then
  611.             printl "${IRed}!!!! Installing stock Mosquitto from Debian 9! ${IWhite}\r\n"
  612.         else
  613.             wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key -a $LOGFILE -O - | sudo apt-key add -
  614.             echo "deb http://repo.mosquitto.org/debian jessie main" |sudo tee /etc/apt/sources.list.d/mosquitto-jessie.list
  615.         fi
  616.         sudo apt-get $AQUIET -y update && sudo apt-get $AQUIET -y install mosquitto mosquitto-clients 2>&1 | tee -a $LOGFILE
  617.         [ $? -eq 0 ] && mosquitto=1 # mosquitto installed
  618.     fi
  619.     # add mosquitto mods+pass ONLY if it was installed...
  620.     if [ $mosquitto -eq 1 ]; then
  621.         sudo bash -c "echo -e \"listener 9001\nprotocol websockets\nlistener 1883\nallow_anonymous false\npassword_file /etc/mosquitto/passwords\" > /etc/mosquitto/conf.d/websockets.conf"
  622.         sudo touch /etc/mosquitto/passwords
  623.         sudo mosquitto_passwd  -b /etc/mosquitto/passwords $adminname $adminpass
  624.         if [[ $OPSYS == *"RASPBIAN"* ]]; then
  625.             echo -e "[Unit]\n\
  626. Description=Mosquitto MQTT Broker daemon\n\
  627. ConditionPathExists=/etc/mosquitto/mosquitto.conf\n\
  628. After=network.target\n\
  629. Requires=network.target\n\
  630. \n\
  631. [Service]\n\
  632. Type=forking\n\
  633. RemainAfterExit=no\n\
  634. StartLimitInterval=0\n\
  635. PIDFile=/var/run/mosquitto.pid\n\
  636. ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d\n\
  637. ExecReload=/bin/kill -HUP $MAINPID\n\
  638. Restart=on-failure\n\
  639. RestartSec=2\n\
  640. \n\
  641. [Install]\n\
  642. WantedBy=multi-user.target\n" | sudo tee /lib/systemd/system/mosquitto
  643.             sudo systemctl  start mosquitto 2>&1 | tee -a $LOGFILE
  644.             sudo systemctl enable mosquitto 2>&1 | tee -a $LOGFILE
  645.         fi
  646.     echo "alias mqttlog='tail -f /var/log/mosquitto/mosquitto.log | ccze -A'" | sudo tee -a /etc/bash.bashrc > /dev/null 2>&1
  647.     else
  648.         printl "${IRed}!!!! Mosquitto not installed! ${IWhite}\r\n"
  649.     fi
  650. fi
  651.  
  652. if [[ $MYMENU == *"wiringpi"* ]]; then
  653.     printstatus "Installing WiringPi"
  654.     cd
  655.     git clone git://git.drogon.net/wiringPi 2>&1 | tee -a $LOGFILE
  656.     # if git fails or folder does not exist, abort+report
  657.     if [ $? -eq 0 ] && [ -d wiringPi ]; then
  658.         cd ~/wiringPi
  659.         ./build 2>&1 | tee -a $LOGFILE
  660.     else
  661.         printl "${IRed}!!!! Wiringpi not installed! ${IWhite}\r\n"
  662.     fi
  663. fi
  664.  
  665. # Moved sqlite3 so that node-red sql node will install
  666. # use back facing quotes in here - no idea why.
  667. # Changed the order of installation of Apache etc to solve issues with ARMBIAN
  668. #
  669.  
  670. if [[ $MYMENU == *"apache"* ]]; then
  671.     printstatus "Installing Apache/PHP and Sqlite"
  672.     cd
  673.     sudo groupadd -f -g33 www-data
  674.    
  675.     if [[ $OPSYS != *"UBUNTU"* ]]; then
  676.         if [[ $OPSYS == *"BIAN"* ]] && [[ $DISTRO == *"9."* ]]; then
  677.             sudo apt-get $AQUIET -y install apache2 libapache2-mod-php7.0 sqlite3 php-sqlite3 php-xml php-mbstring 2>&1 | tee -a $LOGFILE
  678.         else
  679.             sudo apt-get $AQUIET -y install apache2 libapache2-mod-php5 sqlite3 php5-sqlite 2>&1 | tee -a $LOGFILE
  680.         fi
  681.         [ $? -eq 0 ] && apache=1 # apache installed
  682.     else
  683.         sudo apt-get $AQUIET -y install apache2 libapache2-mod-php7.0 sqlite3 php-sqlite3 php-xml php-mbstring 2>&1 | tee -a $LOGFILE
  684.         [ $? -eq 0 ] && apache=1 # apache installed
  685.     fi
  686.     # if apache installed and /var/www/html exists, go on...
  687.     if [ $apache -eq 1 ] && [ -d /var/www/html ]; then
  688.         cd /var/www/html
  689.         sudo mkdir phpliteadmin
  690.         cd phpliteadmin
  691.         sudo wget --no-check-certificate http://bitbucket.org/phpliteadmin/public/downloads/phpLiteAdmin_v1-9-7-1.zip -a $LOGFILE
  692.         if [ $? -eq 0 ]; then
  693.             sudo unzip phpLiteAdmin_v1-9-7-1.zip 2>&1 | tee -a $LOGFILE
  694.             sudo mv phpliteadmin.php index.php
  695.             sudo mv phpliteadmin.config.sample.php phpliteadmin.config.php
  696.             sudo rm *.zip
  697.             sudo mkdir themes
  698.             cd themes
  699.             sudo wget --no-check-certificate http://bitbucket.org/phpliteadmin/public/downloads/phpliteadmin_themes_2013-12-26.zip -a $LOGFILE
  700.             sudo unzip phpliteadmin_themes_2013-12-26.zip 2>&1 | tee -a $LOGFILE
  701.             sudo rm *.zip
  702.             sudo sed -i -e 's#\$directory = \x27.\x27;#\$directory = \x27/home/pi/dbs/\x27;#g' /var/www/html/phpliteadmin/phpliteadmin.config.php
  703.             sudo sed -i -e "s#\$password = \x27admin\x27;#\$password = \x27$adminpass\x27;#g" /var/www/html/phpliteadmin/phpliteadmin.config.php
  704.             sudo sed -i -e "s#\$subdirectories = false;#\$subdirectories = true;#g" /var/www/html/phpliteadmin/phpliteadmin.config.php
  705.             cd
  706.         else
  707.             printl "${IRed}!!!! PHPLITEADMIN not installed! ${IWhite}\r\n"
  708.             cd ; rm -rf /var/www/html/phpliteadmin
  709.         fi
  710.        
  711.         mkdir dbs
  712.         sqlite3 /home/pi/dbs/iot.db << EOF
  713.         CREATE TABLE IF NOT EXISTS \`pinDescription\` (
  714.          \`pinID\` INTEGER PRIMARY KEY NOT NULL,
  715.          \`pinNumber\` varchar(2) NOT NULL,
  716.          \`pinDescription\` varchar(255) NOT NULL
  717.         );
  718.         CREATE TABLE IF NOT EXISTS \`pinDirection\` (
  719.          \`pinID\` INTEGER PRIMARY KEY NOT NULL,
  720.          \`pinNumber\` varchar(2) NOT NULL,
  721.          \`pinDirection\` varchar(3) NOT NULL
  722.         );
  723.         CREATE TABLE IF NOT EXISTS \`pinStatus\` (
  724.          \`pinID\` INTEGER PRIMARY KEY NOT NULL,
  725.          \`pinNumber\` varchar(2)  NOT NULL,
  726.          \`pinStatus\` varchar(1) NOT NULL
  727.         );
  728.         CREATE TABLE IF NOT EXISTS \`users\` (
  729.          \`userID\` INTEGER PRIMARY KEY NOT NULL,
  730.          \`username\` varchar(28) NOT NULL,
  731.          \`password\` varchar(64) NOT NULL,
  732.          \`salt\` varchar(8) NOT NULL
  733.         );
  734.         CREATE TABLE IF NOT EXISTS \`device_list\` (
  735.          \`device_name\` varchar(80) NOT NULL DEFAULT '',
  736.          \`device_description\` varchar(80) DEFAULT NULL,
  737.          \`device_attribute\` varchar(80) DEFAULT NULL,
  738.          \`logins\` int(11) DEFAULT NULL,
  739.          \`creation_date\` datetime DEFAULT NULL,
  740.          \`last_update\` datetime DEFAULT NULL,
  741.          PRIMARY KEY (\`device_name\`)
  742.         );
  743.  
  744.         CREATE TABLE IF NOT EXISTS \`readings\` (
  745.          \`recnum\` INTEGER PRIMARY KEY,
  746.          \`location\` varchar(20),
  747.          \`value\` int(11) NOT NULL,
  748.          \`logged\` timestamp not NULL DEFAULT CURRENT_TIMESTAMP ,
  749.          \`device_name\` varchar(40) not null,
  750.          \`topic\` varchar(40) not null
  751.         );
  752.  
  753.  
  754.         CREATE TABLE IF NOT EXISTS \`pins\` (
  755.          \`gpio0\` int(11) NOT NULL DEFAULT '0',
  756.          \`gpio1\` int(11) NOT NULL DEFAULT '0',
  757.          \`gpio2\` int(11) NOT NULL DEFAULT '0',
  758.          \`gpio3\` int(11) NOT NULL DEFAULT '0'
  759.         );
  760.         INSERT INTO PINS VALUES(0,0,0,0);
  761.         CREATE TABLE IF NOT EXISTS \`temperature_record\` (
  762.          \`device_name\` varchar(64) NOT NULL,
  763.          \`rec_num\` INTEGER PRIMARY KEY,
  764.          \`temperature\` float NOT NULL,
  765.          \`date_time\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
  766.         );
  767.         CREATE TABLE IF NOT EXISTS \`Device\` (
  768.          \`DeviceID\` INTEGER PRIMARY KEY,
  769.          \`DeviceName\` TEXT NOT NULL
  770.         );
  771.         CREATE TABLE IF NOT EXISTS \`DeviceData\` (
  772.          \`DataID\` INTEGER PRIMARY KEY,
  773.         DeviceID INTEGER,
  774.          \`DataName\` TEXT, FOREIGN KEY(DeviceID ) REFERENCES Device(DeviceID)
  775.         );
  776.         CREATE TABLE IF NOT EXISTS \`Data\` (
  777.         SequenceID INTEGER PRIMARY KEY,
  778.          \`DeviceID\` INTEGER NOT NULL,
  779.          \`DataID\` INTEGER NOT NULL,
  780.          \`DataValue\` NUMERIC NOT NULL,
  781.          \`epoch\` NUMERIC NOT NULL,
  782.          \`timestamp\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP , FOREIGN KEY(DataID, DeviceID ) REFERENCES DeviceData(DAtaID, DeviceID )
  783.         );
  784. EOF
  785.        
  786.         cd
  787.         chmod 777 /home/pi/dbs
  788.         chmod 666 /home/pi/dbs/iot.db
  789.         cd
  790.     else
  791.         printl "${IRed}!!!! Apache+PHP+SQLITE+PHPLITEADMIN NOT INSTALLED! ${IWhite}\r\n"
  792.     fi
  793. fi
  794.  
  795. if [[ $MYMENU == *"nodenew"* ]]; then
  796.     printstatus "Installing NodeJS and NodeRed"
  797.     bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
  798.     cd && sudo cp /var/log/nodered-install.log . && sudo chown pi.pi ./nodered-install.log && cd ~/.node-red/
  799.     printstatus "Installing Nodes (could take some time)"
  800.  
  801.     for addonnodes in moment node-red-contrib-config node-red-contrib-grove node-red-contrib-diode node-red-contrib-bigtimer \
  802.     node-red-contrib-esplogin node-red-contrib-timeout node-red-node-openweathermap node-red-node-google node-red-contrib-advanced-ping node-red-node-sqlite node-red-node-emoncms node-red-node-geofence node-red-contrib-moment node-red-contrib-particle \
  803.     node-red-contrib-web-worldmap node-red-contrib-sqldbs node-red-contrib-ramp-thermostat node-red-contrib-graphs \
  804.     node-red-contrib-isonline node-red-node-ping node-red-node-random node-red-node-smooth node-red-contrib-npm node-red-node-arduino \
  805.     node-red-contrib-file-function node-red-contrib-boolean-logic node-red-contrib-blynk-ws node-red-contrib-telegrambot \
  806.     node-red-dashboard node-red-node-darksky node-red-contrib-owntracks node-red-contrib-alexa-local node-red-contrib-heater-controller ; do
  807.         printstatus "Installing node \"${addonnodes}\""
  808.         npm $NQUIET install --save ${addonnodes} 2>&1 | tee -a $LOGFILE
  809.     done
  810.    
  811.     printstatus "Installing node \"node-red-node-sqlite\""
  812.     npm $NQUIET install --unsafe-perm node-red-node-sqlite 2>&1 | tee -a $LOGFILE
  813.     if [[ $MYMENU == *"hwsupport"* ]]; then
  814.     printstatus "Installing node \"i2c-bus\""
  815.         npm $NQUIET install i2c-bus 2>&1 | tee -a $LOGFILE
  816.     fi
  817.     printstatus "Installing node \"bcryptjs\""
  818.     sudo npm $NQUIET install bcryptjs 2>&1 | tee -a $LOGFILE
  819.  
  820.     if [[ $MYMENU == *"hwsupport"* ]]; then
  821.         ## this last bit of code is to ensure that node-red-contrib-opi-gpio can gain access to port bits!!
  822.         getent group gpio || sudo groupadd gpio 2>&1 | tee -a $LOGFILE
  823.         getent group gpio | grep -w -l pi || sudo adduser pi gpio 2>&1 | tee -a $LOGFILE
  824.         [ ! -f /etc/udev/rules.d/99-com.rules ] && echo "KERNEL==\"gpio*\", RUN=\"/bin/sh -c 'chgrp -R gpio /sys/%p /sys/class/gpio && chmod -R g+w /sys/%p /sys/class/gpio'\"" | sudo tee -a /etc/udev/rules.d/99-com.rules > /dev/null
  825.        
  826.         if [[ $OPSYS == *"RASPBIAN"* ]]; then
  827.             sudo sed -i -e 's#exit 0#chmod 777 /dev/ttyAMA0\nexit 0#g' /etc/rc.local
  828.             sudo apt-get -y install python{,3}-rpi.gpio 2>&1 | tee -a $LOGFILE
  829.         else
  830.             if [[ $MYMENU == *"generich3"* ]]; then
  831.                 npm $NQUIET install node-red-contrib-opi-gpio 2>&1 | tee -a $LOGFILE
  832.             fi
  833.         fi
  834.         sudo sed -i -e 's#exit 0#chmod 777 /dev/ttyS*\nexit 0#g' /etc/rc.local
  835.     fi
  836.            
  837.     cd ~/.node-red/
  838.     sudo wget -a $LOGFILE $AQUIET http://tech.scargill.net/iot/settings.txt -O settings.js
  839.  
  840.     echo " "
  841.     bcryptadminpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $adminpass)
  842.     bcryptuserpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $userpass)
  843.     # echo Encrypted password: $bcryptpass
  844.     cp settings.js settings.js.bak-pre-crypt
  845.  
  846.     sed -i -e "s#\/\/adminAuth#adminAuth#" /home/pi/.node-red/settings.js
  847.     sed -i -e "s#\/\/httpNodeAuth#httpNodeAuth#" /home/pi/.node-red/settings.js
  848.     sed -i -e "s#NRUSERNAMEA#$adminname#" /home/pi/.node-red/settings.js
  849.     sed -i -e "s#NRPASSWORDA#$bcryptadminpass#" /home/pi/.node-red/settings.js
  850.     sed -i -e "s#NRUSERNAMEU#$username#" /home/pi/.node-red/settings.js
  851.     sed -i -e "s#NRPASSWORDU#$bcryptuserpass#" /home/pi/.node-red/settings.js
  852.     if [[ $MYMENU == *"hwsupport"* ]]; then
  853.         sed -i -e "s#\/\/var i2c#var i2c#" /home/pi/.node-red/settings.js
  854.         sed -i -e "s#\/\/i2c#i2c#" /home/pi/.node-red/settings.js
  855.     fi
  856.     sudo systemctl enable nodered.service 2>&1 | tee -a $LOGFILE
  857.     ## add a nice little command line utility (nrlog) for showing and tailing Node-Red scripts in colour
  858.     echo "alias nrlog='sudo journalctl -f -n 50 -u nodered -o cat | ccze -A'" | sudo tee -a /etc/bash.bashrc > /dev/null 2>&1
  859. fi
  860.  
  861. if [[ $MYMENU == *"nodejs"* ]]; then
  862.     printstatus "Installing NodeJS"
  863.     LATESTNODE="v6.10.0"
  864.     #LATESTNODE="v8.15.0"
  865.     if [[ $(uname -m) == *"armv6"* ]]; then
  866.         printstatus "Installing ARM6 version"
  867.         wget --no-check-certificate https://nodejs.org/dist/$LATESTNODE/node-$LATESTNODE-linux-armv6l.tar.xz -a $LOGFILE
  868.         [ $? -eq 0 ] && nodejs=1
  869.         pv node-$LATESTNODE-linux-armv6l.tar.xz | tar -xJf -
  870.         cd node-$LATESTNODE-linux-armv6l
  871.         sudo cp -R * /usr/local/
  872.         rm -f node-$LATESTNODE-linux-armv6l.tar.xz
  873.     else
  874.         if [[ $CHECK64 == *"aarch64"* ]]; then
  875.             printstatus "Installing ARM64 version"
  876.             wget --no-check-certificate https://nodejs.org/dist/$LATESTNODE/node-$LATESTNODE-linux-arm64.tar.xz -a $LOGFILE
  877.             [ $? -eq 0 ] && nodejs=1
  878.             pv node-$LATESTNODE-linux-arm64.tar.xz | tar -xJf -
  879.             cd node-$LATESTNODE-linux-arm64
  880.             sudo cp -R * /usr/local/
  881.             rm -f node-$LATESTNODE-linux-arm64.tar.xz
  882.         else
  883.             sudo apt-get $AQUIET -y remove --purge nodejs nodejs-legacy npm  2>&1 | tee -a $LOGFILE
  884.             sudo apt-get $AQUIET -y autoremove 2>&1 | tee -a $LOGFILE
  885.             curl -sL https://deb.nodesource.com/setup_6.x > nodesetup.sh
  886.             #curl -sL https://deb.nodesource.com/setup_8.x > nodesetup.sh
  887.             sudo bash nodesetup.sh 2>&1 | tee -a $LOGFILE
  888.             sudo apt-get $AQUIET -y install nodejs 2>&1 | tee -a $LOGFILE
  889.             sudo apt-get $AQUIET -y install npm 2>&1 | tee -a $LOGFILE
  890.             sudo npm $NQUIET install npm@latest -g 2>&1 | tee -a $LOGFILE
  891.  #           sudo apt-get $AQUIET -y remove --purge npm 2>&1 | tee -a $LOGFILE
  892.  #           sudo apt-get $AQUIET -y autoremove 2>&1 | tee -a $LOGFILE
  893.             sudo ln -sf /usr/local/bin/npm /usr/bin
  894.            [ $? -eq 0 ] && nodejs=1
  895.         fi
  896.     fi
  897.     if [ $nodejs -ne 1 ]; then
  898.         printl "${IRed}!!!! NodeJS not installed! ${IWhite}\r\n"
  899.     fi
  900. fi
  901.  
  902. if [[ $MYMENU == *"nodered"* ]]; then
  903.     #sudo npm cache clean
  904.     printstatus "Installing Node-Red"
  905.     # if nodejs does not exist, abort node-red install
  906.     if [ -f /usr/bin/node ] || [ -f /usr/local/bin/node ]; then
  907.         # prevent double additions to settings.js if it exists and is already modified
  908.         if [ $(grep public ~/.node-red/settings.js 2> /dev/null | wc -l) -ne 1 ]; then
  909.             # sudo npm $NQUIET install -g npm node-gyp node-pre-gyp 2>&1 | tee -a $LOGFILE
  910.             sudo npm $NQUIET install -g --unsafe-perm node-red 2>&1 | tee -a $LOGFILE
  911.             if [[ $MYMENU == *"phone"* ]]; then
  912.                 sudo wget -a $LOGFILE -O /etc/init.d/nodered https://gist.githubusercontent.com/bigmonkeyboy/9962293/raw/0fe19671b1aef8e56cbcb20f6677173f8495e539/nodered
  913.                 sudo chmod 755 /etc/init.d/nodered && sudo update-rc.d nodered defaults 2>&1 | tee -a $LOGFILE
  914.             else
  915.                 echo | openssl s_client -showcerts -servername raw.githubusercontent.com -connect raw.githubusercontent.com:443 2>/dev/null | openssl x509 -inform pem -noout -text > /dev/null 2>&1
  916.                 [[ $? -ne 0 ]] && echo 151.101.128.133 raw.githubusercontent.com | sudo tee -a /etc/hosts
  917.                 sudo wget -a $LOGFILE --no-check-certificate https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service -O /lib/systemd/system/nodered.service
  918.                 sudo wget -a $LOGFILE --no-check-certificate https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start -O /usr/bin/node-red-start
  919.                 sudo wget -a $LOGFILE --no-check-certificate https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop -O /usr/bin/node-red-stop
  920.                 #sudo sed -i -e 's#=pi#=%USER#g' /lib/systemd/system/nodered.service
  921.                 sudo chmod +x /usr/bin/node-red-st*
  922.                 sudo systemctl daemon-reload 2>&1 | tee -a $LOGFILE
  923.             fi
  924.            
  925.             cd
  926.             mkdir .node-red
  927.             cd .node-red
  928.             printstatus "Installing Nodes (could take some time)"
  929.             npm $NQUIET install moment node-red-contrib-config node-red-contrib-grove node-red-contrib-diode node-red-contrib-bigtimer \
  930.             node-red-contrib-esplogin node-red-contrib-timeout node-red-node-openweathermap node-red-node-google \
  931.             node-red-node-emoncms node-red-node-geofence node-red-contrib-moment node-red-contrib-particle \
  932.             node-red-contrib-web-worldmap node-red-contrib-sqldbs node-red-contrib-ramp-thermostat node-red-contrib-graphs \
  933.             node-red-contrib-isonline node-red-node-ping node-red-node-random node-red-node-smooth node-red-contrib-npm node-red-node-arduino \
  934.             node-red-contrib-file-function node-red-contrib-boolean-logic node-red-contrib-blynk-ws node-red-contrib-telegrambot \
  935.             node-red-dashboard node-red-node-darksky node-red-contrib-owntracks node-red-contrib-alexa-local node-red-contrib-heater-controller 2>&1 | tee -a $LOGFILE
  936.     npm $NQUIET install --unsafe-perm node-red-node-sqlite 2>&1 | tee -a $LOGFILE
  937.     if [[ $MYMENU == *"hwsupport"* ]]; then
  938.             npm $NQUIET install node-red-node-serialport i2c-bus 2>&1 | tee -a $LOGFILE
  939.     fi
  940.             sudo npm $NQUIET install bcryptjs 2>&1 | tee -a $LOGFILE
  941.  
  942.     if [[ $MYMENU == *"hwsupport"* ]]; then
  943.             ## this last bit of code is to ensure that node-red-contrib-opi-gpio can gain access to port bits!!
  944.             getent group gpio || sudo groupadd gpio 2>&1 | tee -a $LOGFILE
  945.             getent group gpio | grep -w -l pi || sudo adduser pi gpio 2>&1 | tee -a $LOGFILE
  946.             [ ! -f /etc/udev/rules.d/99-com.rules ] && echo "KERNEL==\"gpio*\", RUN=\"/bin/sh -c 'chgrp -R gpio /sys/%p /sys/class/gpio && chmod -R g+w /sys/%p /sys/class/gpio'\"" | sudo tee -a /etc/udev/rules.d/99-com.rules > /dev/null
  947.            
  948.             if [[ $OPSYS == *"RASPBIAN"* ]]; then
  949.                 sudo sed -i -e 's#exit 0#chmod 777 /dev/ttyAMA0\nexit 0#g' /etc/rc.local
  950.                 sudo apt-get -y install python{,3}-rpi.gpio 2>&1 | tee -a $LOGFILE
  951.                 #npm $NQUIET install node-red-contrib-gpio 2>&1 | tee -a $LOGFILE
  952.                 #npm $NQUIET install raspi-io 2>&1 | tee -a $LOGFILE
  953.             else
  954.                 if [[ $MYMENU == *"generich3"* ]]; then
  955.                     npm $NQUIET install node-red-contrib-opi-gpio 2>&1 | tee -a $LOGFILE
  956.                 fi
  957.             fi
  958.         sudo sed -i -e 's#exit 0#chmod 777 /dev/ttyS*\nexit 0#g' /etc/rc.local
  959.     fi
  960.            
  961.             cd ~/.node-red/
  962.             sudo wget -a $LOGFILE $AQUIET http://tech.scargill.net/iot/settings.txt -O settings.js
  963.  
  964.             #sudo service nodered start 2>&1 | tee -a $LOGFILE
  965.             #while [ ! -f settings.js ] ; do sudo sleep 1 ; done
  966.             #sudo service nodered stop  2>&1 | tee -a $LOGFILE
  967.             echo " "
  968.             bcryptadminpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $adminpass)
  969.             bcryptuserpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $userpass)
  970.             # echo Encrypted password: $bcryptpass
  971.             cp settings.js settings.js.bak-pre-crypt
  972.  
  973.             sed -i -e "s#\/\/adminAuth#adminAuth#" /home/pi/.node-red/settings.js
  974.             sed -i -e "s#\/\/httpNodeAuth#httpNodeAuth#" /home/pi/.node-red/settings.js
  975.             sed -i -e "s#NRUSERNAMEA#$adminname#" /home/pi/.node-red/settings.js
  976.             sed -i -e "s#NRPASSWORDA#$bcryptadminpass#" /home/pi/.node-red/settings.js
  977.             sed -i -e "s#NRUSERNAMEU#$username#" /home/pi/.node-red/settings.js
  978.             sed -i -e "s#NRPASSWORDU#$bcryptuserpass#" /home/pi/.node-red/settings.js
  979.     if [[ $MYMENU == *"hwsupport"* ]]; then
  980.             sed -i -e "s#\/\/var i2c#var i2c#" /home/pi/.node-red/settings.js
  981.             sed -i -e "s#\/\/i2c#i2c#" /home/pi/.node-red/settings.js
  982.     fi
  983.  
  984.             #datetimestamp=`date +%Y-%m-%d_%Hh%Mm`
  985.             #cd ~/.node-red
  986.             # this will add the TOP piece of code for non-vol variables in settings.js
  987.             #gawk -i inplace -v INPLACE_SUFFIX=-$datetimestamp '!found && /module.exports/ { print " var mySettings;\n try {\n mySettings = require(\"/home/pi/.node-red/redvars.js\");\n } catch(err) {\n mySettings = {};\n }\n"; found=1 } 1' settings.js
  988.            
  989.             #sudo sed -i -e 's#functionGlobalContext: {#\/\/ functionGlobalContext: {#g' settings.js
  990.             #sudo sed -i -e 's#\s\s\s\s\},#    \/\/ },#g' settings.js
  991.             #sudo sed -i -e 's#^\}#,#g' settings.js
  992.             #sudo echo " " > tmpfile
  993.             #sudo echo "    httpStatic: '/home/pi/.node-red/public'," >> tmpfile
  994.             #sudo echo "    functionGlobalContext: {" >> tmpfile
  995.             #sudo echo "        os:require('os')," >> tmpfile
  996.             #sudo echo "        moment:require('moment'), " >> tmpfile
  997.             #sudo echo "        fs:require('fs'), " >> tmpfile
  998.             #sudo echo "        i2c:require('i2c-bus'), " >> tmpfile
  999.             #sudo echo "        mySettings:mySettings " >> tmpfile
  1000.             #sudo echo "    }," >> tmpfile
  1001.             #sudo echo " " >> tmpfile
  1002.             #sudo echo "    adminAuth: {" >> tmpfile
  1003.             #sudo echo "        type: \"credentials\"," >> tmpfile
  1004.             #sudo echo "        users: [{" >> tmpfile
  1005.             #sudo echo "            username: \"$adminname\"," >> tmpfile
  1006.             #sudo echo "            password: \"$bcryptadminpass\"," >> tmpfile
  1007.             #sudo echo "            permissions: \"*\"" >> tmpfile
  1008.             #sudo echo "        }]" >> tmpfile
  1009.             #sudo echo "    }," >> tmpfile
  1010.             #sudo echo " " >> tmpfile
  1011.             #sudo echo "    httpNodeAuth: {user:\"$username\", pass:\"$bcryptuserpass\"}" >> tmpfile
  1012.             #sudo echo "}" >> tmpfile
  1013.             #sudo cat tmpfile >> settings.js
  1014.             #sudo rm -f tmpfile
  1015.         else
  1016.             printl "${IRed}!!!! Settings.JS already present and modified, skipping! ${IWhite}\r\n"
  1017.         fi
  1018.         #sed -i -e 's#\/\/\s*var fs = require("fs");#var fs = require("fs");\nvar i2c = require("i2c-bus");#' /home/pi/.node-red/settings.js
  1019.         ## The next two lines are new (Sept 2017) and change the flows files to non-host-specific names - good for copying
  1020.         #sed -i -e 's#\/\/flowFile#flowFile#' /home/pi/.node-red/settings.js
  1021.         #sed -i -e 's#\/\/flowFilePretty#flowFilePretty#' /home/pi/.node-red/settings.js
  1022.         #sed -i -e 's#\/\/ Customising#},\n\n    \/\/ Customising#' /home/pi/.node-red/settings.js
  1023.         if [[ $MYMENU == *"phone"* ]]; then
  1024.             cd && sudo mv /etc/init.d/sendsigs .
  1025.         else
  1026.             sudo systemctl enable nodered.service 2>&1 | tee -a $LOGFILE
  1027.         fi
  1028.         ## add a nice little command line utility (nrlog) for showing and tailing Node-Red scripts in colour
  1029.         echo "alias nrlog='sudo journalctl -f -n 50 -u nodered -o cat | ccze -A'" | sudo tee -a /etc/bash.bashrc > /dev/null 2>&1
  1030.     else
  1031.         printl "${IRed}!!!! Node-Red not installed! ${IWhite}\r\n"
  1032.     fi
  1033. fi
  1034.  
  1035. if [[ $MYMENU == *"hwsupport"* ]]; then
  1036.     if [[ $OPSYS != *"RASPBIAN"* ]]; then
  1037.         if [[ $MYMENU == *"odroid"* ]]; then
  1038.             printstatus "Installing Odroid GPIO"
  1039.             git clone https://github.com/hardkernel/wiringPi.git 2>&1 | tee -a $LOGFILE
  1040.             cd wiringPi
  1041.             ./build 2>&1 | tee -a $LOGFILE
  1042.             sudo chmod a+s /usr/local/bin/gpio
  1043.         fi
  1044.         if [[ $MYMENU == *"generich3"* ]]; then
  1045.             printstatus "Installing H3 GPIO"
  1046.             # Install NanoPi H3 based IO library
  1047.             git clone https://github.com/zhaolei/WiringOP.git -b h3 2>&1 | tee -a $LOGFILE
  1048.             cd WiringOP
  1049.             chmod +x ./build
  1050.             sudo ./build 2>&1 | tee -a $LOGFILE
  1051.             cd
  1052.         fi
  1053.     fi
  1054. fi
  1055.  
  1056. if [[ $MYMENU == *"webmin"* ]]; then
  1057.     printstatus "Installing Webmin at port 10000 (could take some time)"
  1058.     #cd
  1059.     #mkdir webmin
  1060.     #cd webmin
  1061.     #wget --no-check-certificate http://prdownloads.sourceforge.net/webadmin/webmin-1.831.tar.gz
  1062.     #sudo gunzip -q webmin-1.831.tar.gz
  1063.     #tar -xf webmin-1.831.tar
  1064.     #sudo rm *.tar
  1065.     #cd webmin-1.831
  1066.     #sudo ./setup.sh /usr/local/Webmin
  1067.     wget -a $LOGFILE http://www.webmin.com/jcameron-key.asc -O - | sudo apt-key add -
  1068.     echo "deb http://download.webmin.com/download/repository sarge contrib" | sudo tee /etc/apt/sources.list.d/webmin.list > /dev/null
  1069.     sudo apt-get $AQUIET -y update 2>&1 | tee -a $LOGFILE
  1070.     sudo apt-get $AQUIET -y install webmin 2>&1 | tee -a $LOGFILE
  1071.     # http vs https: if you want unsecure http access on port 10000 instead of https, uncomment next line
  1072.     sudo sed -i -e 's#ssl=1#ssl=0#g' /etc/webmin/miniserv.conf
  1073. fi
  1074.  
  1075. #
  1076. # This works a treat on the NanoPi NEO using H3 and Armbian - should not do any harm on other systems as it's not installed!
  1077. #
  1078. if [[ $MYMENU == *"opimonitor"* ]]; then
  1079.     printstatus "Installing Armbian Monitor"
  1080.     sudo armbianmonitor -r 2>&1 | tee -a $LOGFILE
  1081. fi
  1082.  
  1083. if [[ $MYMENU == *"habridge"* ]]; then
  1084.     printstatus "Installing HA-Bridge on port 82"
  1085.     #sudo sed -i -e 's#80#81#g' /etc/apache2/ports.conf
  1086.     #sudo sed -i -e 's#80#81#g' /etc/apache2/sites-enabled/000-default.conf
  1087.     #sudo service apache2 restart
  1088.     ## now to install HA-Bridge on port 82 and get it running from power up.
  1089.     cd ~
  1090.     mkdir habridge
  1091.     cd habridge
  1092.     #wget https://github.com/bwssytems/ha-bridge/releases/download/v3.5.1/ha-bridge-3.5.1.jar -O ~/habridge/ha-bridge.jar
  1093.     curl -s https://api.github.com/repos/bwssytems/ha-bridge/releases/latest | jq --raw-output '.assets[0] | .browser_download_url' | wget -a $LOGFILE -i - -O ~/habridge/ha-bridge.jar
  1094.     echo -e "[Unit]\n\
  1095. Description=HA Bridge\n\
  1096. Wants=network.target\n\
  1097. After=network.target\n\
  1098. \n\
  1099. [Service]\n\
  1100. Type=simple\n\
  1101. ExecStart=/usr/bin/java -jar -Dserver.port=82 -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge.jar\n\
  1102. \n\
  1103. [Install]\n\
  1104.    WantedBy=multi-user.target\n" | sudo tee /lib/systemd/system/habridge.service
  1105.     sudo systemctl  start habridge.service 2>&1 | tee -a $LOGFILE
  1106.     sudo systemctl enable habridge.service 2>&1 | tee -a $LOGFILE
  1107. fi
  1108.  
  1109. if [[ $MYMENU == *"java"* ]]; then
  1110.     printstatus "Installing/Updating Java"
  1111.     #if [[ $OPSYS == *"BIAN"* ]] && [[ $DISTRO == *"9."* ]]; then
  1112.         sudo apt-get $AQUIET -y install software-properties-common dirmngr 2>&1 | tee -a $LOGFILE
  1113.     #fi
  1114.     echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
  1115.     echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
  1116.     sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 2>&1 | tee -a $LOGFILE
  1117.     sudo apt-get $AQUIET update 2>&1 | tee -a $LOGFILE
  1118.     echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
  1119.     echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
  1120.     sudo apt-get $AQUIET -y install oracle-java8-installer 2>&1 | tee -a $LOGFILE
  1121. fi
  1122.  
  1123. if [[ $MYMENU == *"phpsysinfo"* ]]; then
  1124.     printstatus "Installing PHPSysInfo"
  1125.     #   sudo apt-get $AQUIET -y install phpsysinfo
  1126.     #   sudo ln -s /usr/share/phpsysinfo /var/www/html
  1127.     if [ -d /var/www/html ]; then
  1128.         cd /var/www/html
  1129.         sudo git clone https://github.com/phpsysinfo/phpsysinfo.git 2>&1 | tee -a $LOGFILE
  1130.         sudo cp /var/www/html/phpsysinfo/phpsysinfo.ini.new /var/www/html/phpsysinfo/phpsysinfo.ini
  1131.     else
  1132.         printl "${IRed}!!!! Apache+PHP not installed! ${IWhite}\r\n"
  1133.     fi
  1134. fi
  1135.  
  1136. # you may want to use these on a Pi or elsewhere to force either a graphical or command line environment
  1137. #sudo systemctl set-default multi-user.target
  1138. #sudo systemctl set-default graphical.target
  1139.  
  1140. if [[ $MYMENU == *"rpiclone"* ]]; then
  1141.     printstatus "Installing RPI-Clone"
  1142.     cd
  1143.     sudo git clone https://github.com/billw2/rpi-clone.git
  1144.     cd rpi-clone
  1145.     sudo cp rpi-clone /usr/local/sbin
  1146.     cd
  1147.     sudo rm -r rpi-clone
  1148. fi
  1149.  
  1150. if [[ $MYMENU == *"log2ram"* ]]; then
  1151.     printstatus "Installing Log2Ram"
  1152.     cd
  1153.     git clone https://github.com/azlux/log2ram.git 2>&1 | tee -a $LOGFILE
  1154.     cd log2ram
  1155.     chmod +x install.sh
  1156.     sudo ./install.sh 2>&1 | tee -a $LOGFILE
  1157.     cd
  1158. fi
  1159.  
  1160. # Drop in an index file and css for a menu page
  1161. if [[ $MYMENU == *"addindex"* ]]; then
  1162.     printstatus "Adding index page and CSS"
  1163.     if [ -d /var/www/html ]; then
  1164.         sudo wget -a $LOGFILE $AQUIET http://www.scargill.net/iot/index.html -O /var/www/html/index.html
  1165.         sudo wget -a $LOGFILE $AQUIET http://www.scargill.net/iot/reset.css -O /var/www/html/reset.css
  1166.     else
  1167.         printl "${IRed}!!!! Apache+PHP not installed! ${IWhite}\r\n"
  1168.     fi
  1169. fi
  1170.  
  1171. if [[ $MYMENU == *"grafana"* ]]; then
  1172.     printstatus "Installing Grafana and Influxdb"
  1173.     cd
  1174.     sudo apt-get $AQUIET -y update 2>&1 | tee -a $LOGFILE
  1175.     sudo apt-get $AQUIET install -y apt-transport-https curl 2>&1 | tee -a $LOGFILE
  1176.     curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
  1177.     test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list
  1178.     test $VERSION_ID = "9" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list
  1179.     test $VERSION_ID = "16.04" && echo "deb https://repos.influxdata.com/ubuntu xenial stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list
  1180.     curl -sL https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
  1181.     curl -sL https://packagecloud.io/gpg.key | sudo apt-key add -
  1182.     [[ $OPSYS == *"BIAN"* ]] && [[ $(uname -m) == *"armv6"* ]] && echo "deb https://dl.bintray.com/fg2it/deb-rpi-1b jessie main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
  1183.     [[ $OPSYS == *"BIAN"* ]] && [[ $(uname -m) == *"armv7l"* ]] && echo "deb https://dl.bintray.com/fg2it/deb jessie main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
  1184.     [[ $OPSYS == *"UBUNTU"* ]] && [[ $(uname -m) == *"aarch64"* ]] && echo "deb https://dl.bintray.com/fg2it/deb-arm64 stretch main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
  1185.     [[ $OPSYS == *"UBUNTU"* ]] && [[ $(uname -m) != *"aarch64"* ]] && echo "deb https://packagecloud.io/grafana/testing/debian/ stretch main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
  1186.     sudo apt-get $AQUIET -y remove --purge grafana grafana-data 2>&1 | tee -a $LOGFILE
  1187.     sudo rm -rf /var/log/grafana /etc/grafana
  1188.     sudo apt-get $AQUIET -y autoremove 2>&1 | tee -a $LOGFILE
  1189.     sudo apt-get $AQUIET -y update 2>&1 | tee -a $LOGFILE
  1190.     sudo apt-get install $AQUIET -y influxdb grafana chronograf 2>&1 | tee -a $LOGFILE
  1191.     [ $? -eq 0 ] && grafana=1 # grafana installed
  1192.     if [ $grafana -eq 1 ]; then
  1193.         #sudo sed -i -e 's/.*auth-enabled = false/  auth-enabled = true/g' /etc/influxdb/influxdb.conf
  1194.         sudo systemctl daemon-reload 2>&1 | tee -a $LOGFILE
  1195.         sudo systemctl enable influxdb 2>&1 | tee -a $LOGFILE
  1196.         sudo systemctl start influxdb 2>&1 | tee -a $LOGFILE
  1197.         sudo systemctl enable grafana-server 2>&1 | tee -a $LOGFILE
  1198.         sudo systemctl start grafana-server 2>&1 | tee -a $LOGFILE
  1199.         sudo systemctl enable chronograf 2>&1 | tee -a $LOGFILE
  1200.         sudo systemctl start chronograf 2>&1 | tee -a $LOGFILE
  1201.     else
  1202.         printl "${IRed}!!!! GRAFANA AND INFLUXDB NOT INSTALLED! ${IWhite}\r\n"
  1203.     fi
  1204. fi
  1205.  
  1206. sudo rm -rf /var/cache/apt/archives/apt-fast
  1207. sudo apt-get $AQUIET -y clean 2>&1 | tee -a $LOGFILE
  1208.  
  1209. myip=$(hostname -I)
  1210. thehostname=$(hostname)
  1211. echo $newhostname | sudo tee /etc/hostname > /dev/null 2>&1
  1212. sudo sed -i '/^127.0.1.1/ d' /etc/hosts > /dev/null 2>&1
  1213. echo 127.0.1.1 $newhostname | sudo tee -a /etc/hosts > /dev/null 2>&1
  1214. sudo /etc/init.d/hostname.sh > /dev/null 2>&1
  1215.  
  1216. printstatus "Installing Glances"
  1217. sudo apt-get -y install python{,3}-setuptools 2>&1 | tee -a $LOGFILE
  1218. sudo pip install glances 2>&1 | tee -a $LOGFILE
  1219. sudo pip install bottle 2>&1 | tee -a $LOGFILE
  1220.  
  1221. printstatus "All done."
  1222. printf "${BIGreen}== ${BIYELLOW}When complete, remove the script from the /home/pi directory.\r\n"
  1223. printf "${BIGreen}==\r\n"
  1224. printf "${BIGreen}== ${BIPurple}Current IP: %s${BIWhite}\r\n" "$myip"
  1225. printf "${BIGreen}== ${BIPurple}Existing Hostname: %s  New Hostname: %s${BIWhite}\r\n\r\n" "$thehostname" "$newhostname"
  1226. echo -e Current IP: $myip  Hostname: $thehostname >> $LOGFILE
  1227. echo -e Hostname: $newhostname >> $LOGFILE
  1228. echo -e NPM: $(npm -v) >> $LOGFILE
  1229. echo -e PHP: $(php -v) >> $LOGFILE
  1230. echo -e NODE: $(node -v) >> $LOGFILE
  1231. echo -e MQTT: $(/usr/sbin/mosquitto --help | grep version) >> $LOGFILE
  1232. sudo grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* 2>&1 >> $LOGFILE
  1233. echo "alias space='df -h|grep -v udev|grep -v tmpfs|grep -v run'" | sudo tee -a /etc/bash.bashrc > /dev/null 2>&1
  1234. printstatus  "ALL DONE - PLEASE REBOOT NOW THEN TEST"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement