Advertisement
Guest User

Untitled

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