Advertisement
Guest User

Untitled

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