Guest User

Untitled

a guest
Jul 20th, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 60.97 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" ON \
  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" ON \
  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.         "opimonitor" "Install OPI-Monitor - H3 ONLY" OFF \
  501.         "phpsysinfo" "Install PHPSYSYINFO" ON \
  502.         "modpass" "Mod USER and ADMIN passwords (password123)" ON \
  503.         "addindex" "Add an index page and some CSS" ON \
  504.         "passwords" "Update ROOT and PI user passwords" OFF \
  505.         "habridge" "Install HA-bridge on port 82" OFF \
  506.         "rpiclone" "Install RPI-Clone" ON \
  507.         "log2ram" "Install Log2RAM default 40Meg" OFF \
  508.         "grafana" "Install Grafana and InfluxDB" OFF 3>&1 1>&2 2>&3)
  509. fi
  510.  
  511. if [[ $MYMENU != *"quiet"* ]]; then
  512.     AQUIET=""
  513.     NQUIET=""
  514. fi
  515.  
  516. if [[ $MYMENU == "" ]]; then
  517.     whiptail --title "Installation Aborted" --msgbox "Cancelled as requested." 8 78
  518.     exit
  519. fi
  520.  
  521. cd
  522. newhostname=$(whiptail --inputbox "Enter new HOST name\nLeave the default value or select something new" 8 60 $newhostname 3>&1 1>&2 2>&3)
  523.  
  524. if [[ $MYMENU == *"modpass"* ]]; then
  525.    
  526.     username=$(whiptail --inputbox "Enter a USER name (example user)\nSpecifically for Node-Red Dashboard" 8 60 $username 3>&1 1>&2 2>&3)
  527.     if [[ -z "${username// }" ]]; then
  528.         printf "No user name given - aborting\r\n"; exit
  529.     fi
  530.    
  531.     userpass=$(whiptail --passwordbox "Enter a user password" 8 60 3>&1 1>&2 2>&3)
  532.     if [[ -z "${userpass// }" ]]; then
  533.         printf "No user password given - aborting${BIWhite}\r\n"; exit
  534.     fi
  535.    
  536.     userpass2=$(whiptail --passwordbox "Confirm user password" 8 60 3>&1 1>&2 2>&3)
  537.     if  [ $userpass2 == "" ]; then
  538.         printf "${BIRed}No password confirmation given - aborting${BIWhite}\r\n"; exit
  539.     fi
  540.     if  [ $userpass != $userpass2 ]
  541.     then
  542.         printf "${BIRed}Passwords don't match - aborting${BIWhite}\r\n"; exit
  543.     fi
  544.    
  545.     adminname=$(whiptail --inputbox "Enter an ADMIN name (example admin)\nFor Node-Red and MQTT" 8 60 $adminname 3>&1 1>&2 2>&3)
  546.     if [[ -z "${adminname// }" ]]; then
  547.         printf "${BIRed}No admin name given - aborting${BIWhite}\r\n"
  548.         exit
  549.     fi
  550.    
  551.     adminpass=$(whiptail --passwordbox "Enter an admin password" 8 60 3>&1 1>&2 2>&3)
  552.     if [[ -z "${adminpass// }" ]]; then
  553.         printf "${BIRed}No user password given - aborting${BIWhite}\r\n"; exit
  554.     fi
  555.    
  556.     adminpass2=$(whiptail --passwordbox "Confirm admin password" 8 60 3>&1 1>&2 2>&3)
  557.     if  [ $adminpass2 == "" ]; then
  558.         printf "${BIRed}No password confirmation given - aborting${BIWhite}\r\n"; exit
  559.     fi
  560.     if  [ $adminpass != $adminpass2 ]; then
  561.         printf "${BIRed}Passwords don't match - aborting${BIWhite}\r\n"; exit
  562.     fi
  563. fi
  564.  
  565. if [[ $MYMENU == *"passwords"* ]]; then
  566.     echo "Update your PI password"
  567.     sudo passwd pi
  568.     echo "Update your ROOT password"
  569.     sudo passwd root
  570. fi
  571.  
  572. if [[ $MYMENU == *"phone"* ]]; then
  573.     echo "en_US.UTF-8 UTF-8" | sudo tee -a /etc/locale.gen > /dev/null
  574.     # echo "service rsyslog stop" | sudo tee -a /etc/init.d/rc.local > /dev/null
  575.     sudo update-rc.d rsyslog disable 2>&1 | tee -a $LOGFILE
  576.     sudo locale-gen 2>&1 | tee -a $LOGFILE
  577.     sudo sed -i -e 's#exit 0##g' /etc/rc.local
  578.     echo "cd /home/pi/habridge" | sudo tee -a /etc/rc.local > /dev/null
  579.     echo "[ -f /home/pi/habridge/habridge-log.txt ] && rm /home/pi/habridge/habridge-log.txt" | sudo tee -a /etc/rc.local > /dev/null
  580.     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
  581.     echo "chmod 777 /home/pi/habridge/habridge-log.txt" | sudo tee -a /etc/rc.local > /dev/null
  582.     echo "exit 0" | sudo tee -a /etc/rc.local > /dev/null
  583. fi
  584.  
  585. if [[ $MYMENU == *"wolfram"* ]]; then
  586.     printstatus "Removing Wolfram"
  587.     sudo apt-get $AQUIET -y purge wolfram-engine 2>&1 | tee -a $LOGFILE
  588. fi
  589.  
  590. if [[ $MYMENU == *"office"* ]]; then
  591.     printstatus "Removing LibreOffice"
  592.     sudo apt-get $AQUIET -y remove --purge libreoffice* 2>&1 | tee -a $LOGFILE
  593. fi
  594.  
  595. if [[ $MYMENU == *"prereq"* ]]; then
  596.     printstatus "Installing pre-requisites (this could take some time)"
  597.     sudo apt-get $AQUIET -y autoremove 2>&1 | tee -a $LOGFILE
  598.     sudo apt-get $AQUIET  update 2>&1 | tee -a $LOGFILE
  599.     sudo apt-get $AQUIET -y upgrade 2>&1 | tee -a $LOGFILE
  600.     # fix for RPI treating PING as a root function - by Dave
  601.     sudo setcap cap_net_raw=ep /bin/ping > /dev/null 2>&1
  602.     sudo setcap cap_net_raw=ep /bin/ping6 > /dev/null 2>&1
  603.     # Prerequisite suggested by Julian and adding in python-dev - and stuff I've added for SAMBA and telnet, and Common utilities
  604.  
  605.     sudo apt-get install $AQUIET -y nmap netdiscover
  606.     sudo apt install $AQUIET -y sysfsutils
  607.  
  608.     sudo apt-get install $AQUIET -y tcpdump
  609.     sudo apt-get install $AQUIET -y pure-ftpd
  610.  
  611.     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...
  612.     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
  613.     sudo pip -q install psutil 2>&1 | tee -a $LOGFILE
  614.     sudo -H pip -q install feedparser 2>&1 | tee -a $LOGFILE
  615.     # This line to ensure name is resolved from hosts FIRST
  616.     sudo sed -i '/\[global\]/a name resolve order = hosts wins bcast' /etc/samba/smb.conf
  617.    
  618.     if [[ $MYMENU == *"hwsupport"* ]]; then
  619.         sudo apt-get install $AQUIET -y i2c-tools 2>&1 | tee -a $LOGFILE
  620.     fi
  621. fi
  622.  
  623. if [[ $MYMENU == *"mosquitto"* ]]; then
  624.     printstatus "Installing Mosquitto with Websockets"
  625.     cd
  626.     if [[ $OPSYS == *"UBUNTU"* ]]; then
  627.         sudo apt-get $AQUIET -y install mosquitto mosquitto-clients 2>&1 | tee -a $LOGFILE
  628.         [ $? -eq 0 ] && mosquitto=1 # mosquitto installed
  629.     else
  630.         if [[ $OPSYS == *"BIAN"* ]] && [[ $DISTRO == *"8."* ]]; then
  631.             wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key -a $LOGFILE -O - | sudo apt-key add -
  632.             echo "deb http://repo.mosquitto.org/debian jessie main" |sudo tee /etc/apt/sources.list.d/mosquitto-jessie.list
  633.         fi
  634.         sudo apt-get $AQUIET -y update && sudo apt-get $AQUIET -y install mosquitto mosquitto-clients 2>&1 | tee -a $LOGFILE
  635.         [ $? -eq 0 ] && mosquitto=1 # mosquitto installed
  636.     fi
  637.     # add mosquitto mods+pass ONLY if it was installed...
  638.     if [ $mosquitto -eq 1 ]; then
  639.         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"
  640.         sudo touch /etc/mosquitto/passwords
  641.         sudo mosquitto_passwd  -b /etc/mosquitto/passwords $adminname $adminpass
  642.         if [[ $OPSYS == *"RASPBIAN"* ]]; then
  643.             echo -e "[Unit]\n\
  644. Description=Mosquitto MQTT Broker daemon\n\
  645. ConditionPathExists=/etc/mosquitto/mosquitto.conf\n\
  646. After=network.target\n\
  647. Requires=network.target\n\
  648. \n\
  649. [Service]\n\
  650. Type=forking\n\
  651. RemainAfterExit=no\n\
  652. StartLimitInterval=0\n\
  653. PIDFile=/var/run/mosquitto.pid\n\
  654. ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d\n\
  655. ExecReload=/bin/kill -HUP $MAINPID\n\
  656. Restart=on-failure\n\
  657. RestartSec=2\n\
  658. \n\
  659. [Install]\n\
  660. WantedBy=multi-user.target\n" | sudo tee /lib/systemd/system/mosquitto
  661.             sudo systemctl  start mosquitto 2>&1 | tee -a $LOGFILE
  662.             sudo systemctl enable mosquitto 2>&1 | tee -a $LOGFILE
  663.         fi
  664.     echo "alias mqttlog='tail -f /var/log/mosquitto/mosquitto.log | ccze -A'" | sudo tee -a /etc/bash.bashrc > /dev/null 2>&1
  665.     else
  666.         printl "${IRed}!!!! Mosquitto not installed! ${IWhite}\r\n"
  667.     fi
  668. fi
  669.  
  670. if [[ $MYMENU == *"wiringpi"* ]]; then
  671.     printstatus "Installing WiringPi"
  672.     cd
  673.     git clone git://git.drogon.net/wiringPi 2>&1 | tee -a $LOGFILE
  674.     # if git fails or folder does not exist, abort+report
  675.     if [ $? -eq 0 ] && [ -d wiringPi ]; then
  676.         cd ~/wiringPi
  677.         ./build 2>&1 | tee -a $LOGFILE
  678.     else
  679.         printl "${IRed}!!!! Wiringpi not installed! ${IWhite}\r\n"
  680.     fi
  681. fi
  682.  
  683. # Moved sqlite3 so that node-red sql node will install
  684. # use back facing quotes in here - no idea why.
  685. # Changed the order of installation of Apache etc to solve issues with ARMBIAN
  686. #
  687.  
  688. if [[ $MYMENU == *"apache"* ]]; then
  689.     printstatus "Installing Apache/PHP and Sqlite"
  690.     cd
  691.     sudo groupadd -f -g33 www-data
  692.    
  693.     if [[ $OPSYS != *"UBUNTU"* ]]; then
  694.         if [[ $OPSYS == *"BIAN"* ]] && [[ $DISTRO == *"10"* ]]; then
  695.             sudo apt-get $AQUIET -y install apache2 libapache2-mod-php7.3 sqlite3 php-sqlite3 php-xml php-mbstring 2>&1 | tee -a $LOGFILE
  696.         fi
  697.         if [[ $OPSYS == *"BIAN"* ]] && [[ $DISTRO == *"9."* ]]; then
  698.             sudo apt-get $AQUIET -y install apache2 libapache2-mod-php7.0 sqlite3 php-sqlite3 php-xml php-mbstring 2>&1 | tee -a $LOGFILE
  699.         fi
  700.         if [[ $OPSYS == *"BIAN"* ]] && [[ $DISTRO == *"8"* ]]; then
  701.             sudo apt-get $AQUIET -y install apache2 libapache2-mod-php5 sqlite3 php5-sqlite 2>&1 | tee -a $LOGFILE
  702.         fi
  703.         [ $? -eq 0 ] && apache=1 # apache installed
  704.     else
  705.         sudo apt-get $AQUIET -y install apache2 libapache2-mod-php7.0 sqlite3 php-sqlite3 php-xml php-mbstring 2>&1 | tee -a $LOGFILE
  706.         [ $? -eq 0 ] && apache=1 # apache installed
  707.     fi
  708.     # if apache installed and /var/www/html exists, go on...
  709.     if [ $apache -eq 1 ] && [ -d /var/www/html ]; then
  710.         cd /var/www/html
  711.         sudo mkdir phpliteadmin
  712.         cd phpliteadmin
  713.         #sudo wget --no-check-certificate http://bitbucket.org/phpliteadmin/public/downloads/phpLiteAdmin_v1-9-7-1.zip -a $LOGFILE
  714.         sudo wget --no-check-certificate https://www.phpliteadmin.org/phpliteadmin-dev.zip -a $LOGFILE
  715.         if [ $? -eq 0 ]; then
  716.             sudo unzip phpliteadmin-dev.zip 2>&1 | tee -a $LOGFILE
  717.             sudo mv phpliteadmin.php index.php
  718.             sudo mv phpliteadmin.config.sample.php phpliteadmin.config.php
  719.             sudo rm *.zip
  720.             sudo mkdir themes
  721.             cd themes
  722.             sudo wget --no-check-certificate http://bitbucket.org/phpliteadmin/public/downloads/phpliteadmin_themes_2016-02-29.zip -a $LOGFILE
  723.             sudo unzip phpliteadmin_themes_2016-02-29.zip 2>&1 | tee -a $LOGFILE
  724.             sudo rm *.zip
  725.             sudo sed -i -e 's#\$directory = \x27.\x27;#\$directory = \x27/home/pi/dbs/\x27;#g' /var/www/html/phpliteadmin/phpliteadmin.config.php
  726.             sudo sed -i -e "s#\$password = \x27admin\x27;#\$password = \x27$adminpass\x27;#g" /var/www/html/phpliteadmin/phpliteadmin.config.php
  727.             sudo sed -i -e "s#\$subdirectories = false;#\$subdirectories = true;#g" /var/www/html/phpliteadmin/phpliteadmin.config.php
  728.             cd
  729.         else
  730.             printl "${IRed}!!!! PHPLITEADMIN not installed! ${IWhite}\r\n"
  731.             cd ; rm -rf /var/www/html/phpliteadmin
  732.         fi
  733.        
  734.         mkdir dbs
  735.         sqlite3 /home/pi/dbs/iot.db << EOF
  736.         CREATE TABLE IF NOT EXISTS \`pinDescription\` (
  737.          \`pinID\` INTEGER PRIMARY KEY NOT NULL,
  738.          \`pinNumber\` varchar(2) NOT NULL,
  739.          \`pinDescription\` varchar(255) NOT NULL
  740.         );
  741.         CREATE TABLE IF NOT EXISTS \`pinDirection\` (
  742.          \`pinID\` INTEGER PRIMARY KEY NOT NULL,
  743.          \`pinNumber\` varchar(2) NOT NULL,
  744.          \`pinDirection\` varchar(3) NOT NULL
  745.         );
  746.         CREATE TABLE IF NOT EXISTS \`pinStatus\` (
  747.          \`pinID\` INTEGER PRIMARY KEY NOT NULL,
  748.          \`pinNumber\` varchar(2)  NOT NULL,
  749.          \`pinStatus\` varchar(1) NOT NULL
  750.         );
  751.         CREATE TABLE IF NOT EXISTS \`users\` (
  752.          \`userID\` INTEGER PRIMARY KEY NOT NULL,
  753.          \`username\` varchar(28) NOT NULL,
  754.          \`password\` varchar(64) NOT NULL,
  755.          \`salt\` varchar(8) NOT NULL
  756.         );
  757.         CREATE TABLE IF NOT EXISTS \`device_list\` (
  758.          \`device_name\` varchar(80) NOT NULL DEFAULT '',
  759.          \`device_description\` varchar(80) DEFAULT NULL,
  760.          \`device_attribute\` varchar(80) DEFAULT NULL,
  761.          \`logins\` int(11) DEFAULT NULL,
  762.          \`creation_date\` datetime DEFAULT NULL,
  763.          \`last_update\` datetime DEFAULT NULL,
  764.          PRIMARY KEY (\`device_name\`)
  765.         );
  766.  
  767.         CREATE TABLE IF NOT EXISTS \`readings\` (
  768.          \`recnum\` INTEGER PRIMARY KEY,
  769.          \`location\` varchar(20),
  770.          \`value\` int(11) NOT NULL,
  771.          \`logged\` timestamp not NULL DEFAULT CURRENT_TIMESTAMP ,
  772.          \`device_name\` varchar(40) not null,
  773.          \`topic\` varchar(40) not null
  774.         );
  775.  
  776.  
  777.         CREATE TABLE IF NOT EXISTS \`pins\` (
  778.          \`gpio0\` int(11) NOT NULL DEFAULT '0',
  779.          \`gpio1\` int(11) NOT NULL DEFAULT '0',
  780.          \`gpio2\` int(11) NOT NULL DEFAULT '0',
  781.          \`gpio3\` int(11) NOT NULL DEFAULT '0'
  782.         );
  783.         INSERT INTO PINS VALUES(0,0,0,0);
  784.         CREATE TABLE IF NOT EXISTS \`temperature_record\` (
  785.          \`device_name\` varchar(64) NOT NULL,
  786.          \`rec_num\` INTEGER PRIMARY KEY,
  787.          \`temperature\` float NOT NULL,
  788.          \`date_time\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
  789.         );
  790.         CREATE TABLE IF NOT EXISTS \`Device\` (
  791.          \`DeviceID\` INTEGER PRIMARY KEY,
  792.          \`DeviceName\` TEXT NOT NULL
  793.         );
  794.         CREATE TABLE IF NOT EXISTS \`DeviceData\` (
  795.          \`DataID\` INTEGER PRIMARY KEY,
  796.         DeviceID INTEGER,
  797.          \`DataName\` TEXT, FOREIGN KEY(DeviceID ) REFERENCES Device(DeviceID)
  798.         );
  799.         CREATE TABLE IF NOT EXISTS \`Data\` (
  800.         SequenceID INTEGER PRIMARY KEY,
  801.          \`DeviceID\` INTEGER NOT NULL,
  802.          \`DataID\` INTEGER NOT NULL,
  803.          \`DataValue\` NUMERIC NOT NULL,
  804.          \`epoch\` NUMERIC NOT NULL,
  805.          \`timestamp\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP , FOREIGN KEY(DataID, DeviceID ) REFERENCES DeviceData(DAtaID, DeviceID )
  806.         );
  807. EOF
  808.        
  809.         cd
  810.         chmod 777 /home/pi/dbs
  811.         chmod 666 /home/pi/dbs/iot.db
  812.         cd
  813.     else
  814.         printl "${IRed}!!!! Apache+PHP+SQLITE+PHPLITEADMIN NOT INSTALLED! ${IWhite}\r\n"
  815.     fi
  816. fi
  817.  
  818. if [[ $MYMENU == *"nodenew"* ]]; then
  819.     printstatus "Installing NodeJS and NodeRed"
  820.    
  821. ##  bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)
  822.    
  823.     curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered > update-nodejs-and-nodered
  824.     echo 143.204.15.127 deb.nodesource.com | sudo tee -a /etc/hosts
  825.     chmod +x update-nodejs-and-nodered
  826.     echo y | ./update-nodejs-and-nodered
  827.  
  828. cd && sudo cp /var/log/nodered-install.log . && sudo chown pi.pi ./nodered-install.log && cd ~/.node-red/
  829.  
  830.  
  831.  
  832.     printstatus "Installing Nodes (could take some time)"
  833. # TAKEN OUT  node-red-contrib-graphs - I dont use it, most likely defunct - no work done on it in 3 years
  834.     for addonnodes in moment node-red-contrib-config node-red-contrib-grove node-red-contrib-diode node-red-contrib-bigtimer \
  835.     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 \
  836.     node-red-contrib-web-worldmap node-red-contrib-ramp-thermostat node-red-contrib-fs-ops node-red-contrib-infuxdb \
  837.     node-red-contrib-isonline node-red-node-ping node-red-node-random node-red-node-smooth node-red-contrib-npm node-red-node-arduino \
  838.     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 \
  839.     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
  840.         printstatus "Installing node \"${addonnodes}\""
  841.         npm $NQUIET install --save ${addonnodes} 2>&1 | tee -a $LOGFILE
  842.     done
  843.    
  844.     printstatus "Installing node \"node-red-node-sqlite\""
  845.     npm $NQUIET install --unsafe-perm node-red-node-sqlite 2>&1 | tee -a $LOGFILE
  846.     if [[ $MYMENU == *"hwsupport"* ]]; then
  847.     printstatus "Installing node \"i2c-bus\""
  848.         npm $NQUIET install i2c-bus 2>&1 | tee -a $LOGFILE
  849.     fi
  850.     printstatus "Installing node \"bcryptjs\""
  851.     sudo npm $NQUIET install bcryptjs 2>&1 | tee -a $LOGFILE
  852.  
  853.     if [[ $MYMENU == *"hwsupport"* ]]; then
  854.         ## this last bit of code is to ensure that node-red-contrib-opi-gpio can gain access to port bits!!
  855.         getent group gpio || sudo groupadd gpio 2>&1 | tee -a $LOGFILE
  856.         getent group gpio | grep -w -l pi || sudo adduser pi gpio 2>&1 | tee -a $LOGFILE
  857.         [ ! -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
  858.        
  859.         if [[ $OPSYS == *"RASPBIAN"* ]]; then
  860.             sudo sed -i -e 's#exit 0#chmod 777 /dev/ttyAMA0\nexit 0#g' /etc/rc.local
  861.             sudo apt-get -y install python{,3}-rpi.gpio 2>&1 | tee -a $LOGFILE
  862.         else
  863.             if [[ $MYMENU == *"generich3"* ]]; then
  864.                 npm $NQUIET install node-red-contrib-opi-gpio 2>&1 | tee -a $LOGFILE
  865.             fi
  866.         fi
  867.         sudo sed -i -e 's#exit 0#chmod 777 /dev/ttyS*\nexit 0#g' /etc/rc.local
  868.     fi
  869.            
  870.     cd ~/.node-red/
  871.     sudo wget -a $LOGFILE $AQUIET http://tech.scargill.net/iot/settings.txt -O settings.js
  872.  
  873.     echo " "
  874.     bcryptadminpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $adminpass)
  875.     bcryptuserpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $userpass)
  876.     # echo Encrypted password: $bcryptpass
  877.     cp settings.js settings.js.bak-pre-crypt
  878.  
  879.     sed -i -e "s#\/\/adminAuth#adminAuth#" /home/pi/.node-red/settings.js
  880.     sed -i -e "s#\/\/httpNodeAuth#httpNodeAuth#" /home/pi/.node-red/settings.js
  881.     sed -i -e "s#NRUSERNAMEA#$adminname#" /home/pi/.node-red/settings.js
  882.     sed -i -e "s#NRPASSWORDA#$bcryptadminpass#" /home/pi/.node-red/settings.js
  883.     sed -i -e "s#NRUSERNAMEU#$username#" /home/pi/.node-red/settings.js
  884.     sed -i -e "s#NRPASSWORDU#$bcryptuserpass#" /home/pi/.node-red/settings.js
  885.     if [[ $MYMENU == *"hwsupport"* ]]; then
  886.         sed -i -e "s#\/\/var i2c#var i2c#" /home/pi/.node-red/settings.js
  887.         sed -i -e "s#\/\/i2c#i2c#" /home/pi/.node-red/settings.js
  888.     fi
  889.     sudo systemctl enable nodered.service 2>&1 | tee -a $LOGFILE
  890.     ## add a nice little command line utility (nrlog) for showing and tailing Node-Red scripts in colour
  891.     echo "alias nrlog='sudo journalctl -f -n 50 -u nodered -o cat | ccze -A'" | sudo tee -a /etc/bash.bashrc > /dev/null 2>&1
  892. fi
  893.  
  894. if [[ $MYMENU == *"nodejs"* ]]; then
  895.     printstatus "Installing NodeJS"
  896.     LATESTNODE="v6.17.1"
  897.     if [[ $(uname -m) == *"armv6"* ]]; then
  898.         printstatus "Installing ARM6 version"
  899.         wget --no-check-certificate https://nodejs.org/dist/$LATESTNODE/node-$LATESTNODE-linux-armv6l.tar.xz -a $LOGFILE
  900.         [ $? -eq 0 ] && nodejs=1
  901.         pv node-$LATESTNODE-linux-armv6l.tar.xz | tar -xJf -
  902.         cd node-$LATESTNODE-linux-armv6l
  903.         sudo cp -R * /usr/local/
  904.         rm -f node-$LATESTNODE-linux-armv6l.tar.xz
  905.     else
  906.         if [[ $CHECK64 == *"aarch64"* ]]; then
  907.             printstatus "Installing ARM64 version"
  908.             wget --no-check-certificate https://nodejs.org/dist/$LATESTNODE/node-$LATESTNODE-linux-arm64.tar.xz -a $LOGFILE
  909.             [ $? -eq 0 ] && nodejs=1
  910.             pv node-$LATESTNODE-linux-arm64.tar.xz | tar -xJf -
  911.             cd node-$LATESTNODE-linux-arm64
  912.             sudo cp -R * /usr/local/
  913.             rm -f node-$LATESTNODE-linux-arm64.tar.xz
  914.         else
  915.             sudo apt-get $AQUIET -y remove --purge nodejs nodejs-legacy npm  2>&1 | tee -a $LOGFILE
  916.             sudo apt-get $AQUIET -y autoremove 2>&1 | tee -a $LOGFILE
  917.             curl -sL https://deb.nodesource.com/setup_6.x > nodesetup.sh
  918.             #curl -sL https://deb.nodesource.com/setup_8.x > nodesetup.sh
  919.             sudo bash nodesetup.sh 2>&1 | tee -a $LOGFILE
  920.             sudo apt-get $AQUIET -y install nodejs 2>&1 | tee -a $LOGFILE
  921.             sudo apt-get $AQUIET -y install npm 2>&1 | tee -a $LOGFILE
  922.             sudo npm $NQUIET install npm@latest -g 2>&1 | tee -a $LOGFILE
  923.  #           sudo apt-get $AQUIET -y remove --purge npm 2>&1 | tee -a $LOGFILE
  924.  #           sudo apt-get $AQUIET -y autoremove 2>&1 | tee -a $LOGFILE
  925.             sudo ln -sf /usr/local/bin/npm /usr/bin
  926.            [ $? -eq 0 ] && nodejs=1
  927.         fi
  928.     fi
  929.     if [ $nodejs -ne 1 ]; then
  930.         printl "${IRed}!!!! NodeJS not installed! ${IWhite}\r\n"
  931.     fi
  932. fi
  933.  
  934. if [[ $MYMENU == *"nodered"* ]]; then
  935.     #sudo npm cache clean
  936.     printstatus "Installing Node-Red"
  937.     # if nodejs does not exist, abort node-red install
  938.     if [ -f /usr/bin/node ] || [ -f /usr/local/bin/node ]; then
  939.         # prevent double additions to settings.js if it exists and is already modified
  940.         if [ $(grep public ~/.node-red/settings.js 2> /dev/null | wc -l) -ne 1 ]; then
  941.             # sudo npm $NQUIET install -g npm node-gyp node-pre-gyp 2>&1 | tee -a $LOGFILE
  942.             sudo npm $NQUIET install -g --unsafe-perm node-red 2>&1 | tee -a $LOGFILE
  943.             if [[ $MYMENU == *"phone"* ]]; then
  944.                 sudo wget -a $LOGFILE -O /etc/init.d/nodered https://gist.githubusercontent.com/bigmonkeyboy/9962293/raw/0fe19671b1aef8e56cbcb20f6677173f8495e539/nodered
  945.                 sudo chmod 755 /etc/init.d/nodered && sudo update-rc.d nodered defaults 2>&1 | tee -a $LOGFILE
  946.             else
  947.                 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
  948.                 [[ $? -ne 0 ]] && echo 151.101.128.133 raw.githubusercontent.com | sudo tee -a /etc/hosts
  949.                 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
  950.                 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
  951.                 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
  952.                 #sudo sed -i -e 's#=pi#=%USER#g' /lib/systemd/system/nodered.service
  953.                 sudo chmod +x /usr/bin/node-red-st*
  954.                 sudo systemctl daemon-reload 2>&1 | tee -a $LOGFILE
  955.             fi
  956.            
  957.             cd
  958.             mkdir .node-red
  959.             cd .node-red
  960.             printstatus "Installing Nodes (could take some time)"
  961.     for addonnodes in moment node-red-contrib-config node-red-contrib-grove node-red-contrib-diode node-red-contrib-bigtimer \
  962.     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 \
  963.     node-red-contrib-web-worldmap node-red-contrib-ramp-thermostat node-red-contrib-fs-ops node-red-contrib-infuxdb \
  964.     node-red-contrib-isonline node-red-node-ping node-red-node-random node-red-node-smooth node-red-contrib-npm node-red-node-arduino \
  965.     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 \
  966.     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
  967.         printstatus "Installing node \"${addonnodes}\""
  968.         npm $NQUIET install --save ${addonnodes} 2>&1 | tee -a $LOGFILE
  969.     done
  970.    
  971.     printstatus "Installing node \"node-red-node-sqlite\""
  972.     npm $NQUIET install --unsafe-perm node-red-node-sqlite 2>&1 | tee -a $LOGFILE
  973.  
  974.     if [[ $MYMENU == *"hwsupport"* ]]; then
  975.         printstatus "Installing nodes \"serialport and i2c-bus\""
  976.         npm $NQUIET install node-red-node-serialport i2c-bus 2>&1 | tee -a $LOGFILE
  977.     fi
  978.     printstatus "Installing node \"bcryptjs\""
  979.     sudo npm $NQUIET install bcryptjs 2>&1 | tee -a $LOGFILE
  980.  
  981.     if [[ $MYMENU == *"hwsupport"* ]]; then
  982.             ## this last bit of code is to ensure that node-red-contrib-opi-gpio can gain access to port bits!!
  983.             getent group gpio || sudo groupadd gpio 2>&1 | tee -a $LOGFILE
  984.             getent group gpio | grep -w -l pi || sudo adduser pi gpio 2>&1 | tee -a $LOGFILE
  985.             [ ! -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
  986.            
  987.             if [[ $OPSYS == *"RASPBIAN"* ]]; then
  988.                 sudo sed -i -e 's#exit 0#chmod 777 /dev/ttyAMA0\nexit 0#g' /etc/rc.local
  989.                 sudo apt-get -y install python{,3}-rpi.gpio 2>&1 | tee -a $LOGFILE
  990.                 #npm $NQUIET install node-red-contrib-gpio 2>&1 | tee -a $LOGFILE
  991.                 #npm $NQUIET install raspi-io 2>&1 | tee -a $LOGFILE
  992.             else
  993.                 if [[ $MYMENU == *"generich3"* ]]; then
  994.                     npm $NQUIET install node-red-contrib-opi-gpio 2>&1 | tee -a $LOGFILE
  995.                 fi
  996.             fi
  997.         sudo sed -i -e 's#exit 0#chmod 777 /dev/ttyS*\nexit 0#g' /etc/rc.local
  998.     fi
  999.            
  1000.             cd ~/.node-red/
  1001.             sudo wget -a $LOGFILE $AQUIET http://tech.scargill.net/iot/settings.txt -O settings.js
  1002.  
  1003.             #sudo service nodered start 2>&1 | tee -a $LOGFILE
  1004.             #while [ ! -f settings.js ] ; do sudo sleep 1 ; done
  1005.             #sudo service nodered stop  2>&1 | tee -a $LOGFILE
  1006.             echo " "
  1007.             bcryptadminpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $adminpass)
  1008.             bcryptuserpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $userpass)
  1009.             # echo Encrypted password: $bcryptpass
  1010.             cp settings.js settings.js.bak-pre-crypt
  1011.  
  1012.             sed -i -e "s#\/\/adminAuth#adminAuth#" /home/pi/.node-red/settings.js
  1013.             sed -i -e "s#\/\/httpNodeAuth#httpNodeAuth#" /home/pi/.node-red/settings.js
  1014.             sed -i -e "s#NRUSERNAMEA#$adminname#" /home/pi/.node-red/settings.js
  1015.             sed -i -e "s#NRPASSWORDA#$bcryptadminpass#" /home/pi/.node-red/settings.js
  1016.             sed -i -e "s#NRUSERNAMEU#$username#" /home/pi/.node-red/settings.js
  1017.             sed -i -e "s#NRPASSWORDU#$bcryptuserpass#" /home/pi/.node-red/settings.js
  1018.     if [[ $MYMENU == *"hwsupport"* ]]; then
  1019.             sed -i -e "s#\/\/var i2c#var i2c#" /home/pi/.node-red/settings.js
  1020.             sed -i -e "s#\/\/i2c#i2c#" /home/pi/.node-red/settings.js
  1021.     fi
  1022.  
  1023.             #datetimestamp=`date +%Y-%m-%d_%Hh%Mm`
  1024.             #cd ~/.node-red
  1025.             # this will add the TOP piece of code for non-vol variables in settings.js
  1026.             #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
  1027.            
  1028.             #sudo sed -i -e 's#functionGlobalContext: {#\/\/ functionGlobalContext: {#g' settings.js
  1029.             #sudo sed -i -e 's#\s\s\s\s\},#    \/\/ },#g' settings.js
  1030.             #sudo sed -i -e 's#^\}#,#g' settings.js
  1031.             #sudo echo " " > tmpfile
  1032.             #sudo echo "    httpStatic: '/home/pi/.node-red/public'," >> tmpfile
  1033.             #sudo echo "    functionGlobalContext: {" >> tmpfile
  1034.             #sudo echo "        os:require('os')," >> tmpfile
  1035.             #sudo echo "        moment:require('moment'), " >> tmpfile
  1036.             #sudo echo "        fs:require('fs'), " >> tmpfile
  1037.             #sudo echo "        i2c:require('i2c-bus'), " >> tmpfile
  1038.             #sudo echo "        mySettings:mySettings " >> tmpfile
  1039.             #sudo echo "    }," >> tmpfile
  1040.             #sudo echo " " >> tmpfile
  1041.             #sudo echo "    adminAuth: {" >> tmpfile
  1042.             #sudo echo "        type: \"credentials\"," >> tmpfile
  1043.             #sudo echo "        users: [{" >> tmpfile
  1044.             #sudo echo "            username: \"$adminname\"," >> tmpfile
  1045.             #sudo echo "            password: \"$bcryptadminpass\"," >> tmpfile
  1046.             #sudo echo "            permissions: \"*\"" >> tmpfile
  1047.             #sudo echo "        }]" >> tmpfile
  1048.             #sudo echo "    }," >> tmpfile
  1049.             #sudo echo " " >> tmpfile
  1050.             #sudo echo "    httpNodeAuth: {user:\"$username\", pass:\"$bcryptuserpass\"}" >> tmpfile
  1051.             #sudo echo "}" >> tmpfile
  1052.             #sudo cat tmpfile >> settings.js
  1053.             #sudo rm -f tmpfile
  1054.         else
  1055.             printl "${IRed}!!!! Settings.JS already present and modified, skipping! ${IWhite}\r\n"
  1056.         fi
  1057.         #sed -i -e 's#\/\/\s*var fs = require("fs");#var fs = require("fs");\nvar i2c = require("i2c-bus");#' /home/pi/.node-red/settings.js
  1058.         ## The next two lines are new (Sept 2017) and change the flows files to non-host-specific names - good for copying
  1059.         #sed -i -e 's#\/\/flowFile#flowFile#' /home/pi/.node-red/settings.js
  1060.         #sed -i -e 's#\/\/flowFilePretty#flowFilePretty#' /home/pi/.node-red/settings.js
  1061.         #sed -i -e 's#\/\/ Customising#},\n\n    \/\/ Customising#' /home/pi/.node-red/settings.js
  1062.         if [[ $MYMENU == *"phone"* ]]; then
  1063.             cd && sudo mv /etc/init.d/sendsigs .
  1064.         else
  1065.             sudo systemctl enable nodered.service 2>&1 | tee -a $LOGFILE
  1066.         fi
  1067.         ## add a nice little command line utility (nrlog) for showing and tailing Node-Red scripts in colour
  1068.         echo "alias nrlog='sudo journalctl -f -n 50 -u nodered -o cat | ccze -A'" | sudo tee -a /etc/bash.bashrc > /dev/null 2>&1
  1069.     else
  1070.         printl "${IRed}!!!! Node-Red not installed! ${IWhite}\r\n"
  1071.     fi
  1072. fi
  1073.  
  1074. if [[ $MYMENU == *"hwsupport"* ]]; then
  1075.     if [[ $OPSYS != *"RASPBIAN"* ]]; then
  1076.         if [[ $MYMENU == *"odroid"* ]]; then
  1077.             printstatus "Installing Odroid GPIO"
  1078.             git clone https://github.com/hardkernel/wiringPi.git 2>&1 | tee -a $LOGFILE
  1079.             cd wiringPi
  1080.             ./build 2>&1 | tee -a $LOGFILE
  1081.             sudo chmod a+s /usr/local/bin/gpio
  1082.         fi
  1083.         if [[ $MYMENU == *"generich3"* ]]; then
  1084.             printstatus "Installing H3 GPIO"
  1085.             # Install NanoPi H3 based IO library
  1086.             git clone https://github.com/zhaolei/WiringOP.git -b h3 2>&1 | tee -a $LOGFILE
  1087.             cd WiringOP
  1088.             chmod +x ./build
  1089.             sudo ./build 2>&1 | tee -a $LOGFILE
  1090.             cd
  1091.         fi
  1092.     fi
  1093. fi
  1094.  
  1095. if [[ $MYMENU == *"webmin"* ]]; then
  1096.     printstatus "Installing Webmin at port 10000 (could take some time)"
  1097.     #cd
  1098.     #mkdir webmin
  1099.     #cd webmin
  1100.     #wget --no-check-certificate http://prdownloads.sourceforge.net/webadmin/webmin-1.831.tar.gz
  1101.     #sudo gunzip -q webmin-1.831.tar.gz
  1102.     #tar -xf webmin-1.831.tar
  1103.     #sudo rm *.tar
  1104.     #cd webmin-1.831
  1105.     #sudo ./setup.sh /usr/local/Webmin
  1106.     wget -a $LOGFILE http://www.webmin.com/jcameron-key.asc -O - | sudo apt-key add -
  1107.     echo "deb http://download.webmin.com/download/repository sarge contrib" | sudo tee /etc/apt/sources.list.d/webmin.list > /dev/null
  1108.     sudo apt-get $AQUIET -y update 2>&1 | tee -a $LOGFILE
  1109.     sudo apt-get $AQUIET -y install webmin 2>&1 | tee -a $LOGFILE
  1110.     # http vs https: if you want unsecure http access on port 10000 instead of https, uncomment next line
  1111.     sudo sed -i -e 's#ssl=1#ssl=0#g' /etc/webmin/miniserv.conf
  1112. fi
  1113.  
  1114. #
  1115. # 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!
  1116. #
  1117. if [[ $MYMENU == *"opimonitor"* ]]; then
  1118.     printstatus "Installing Armbian Monitor"
  1119.     sudo armbianmonitor -r 2>&1 | tee -a $LOGFILE
  1120. fi
  1121.  
  1122. if [[ $MYMENU == *"java"* ]]; then
  1123.     printstatus "Installing/Updating Java"
  1124.     sudo apt-get $AQUIET -y install software-properties-common dirmngr 2>&1 | tee -a $LOGFILE
  1125.     sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 2>&1 | tee -a $LOGFILE
  1126.     sudo apt-key adv --keyserver hkp://pgpkeys.mit.edu:80 --recv-keys C2518248EEA14886 2>&1 | tee -a $LOGFILE
  1127.     sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EA8CACC073C3DB2A 2>&1 | tee -a $LOGFILE
  1128.     if [[ $OPSYS == *"BIAN"* ]] && [[ $DISTRO == *"10"* ]]; then
  1129.         echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | sudo tee /etc/apt/sources.list.d/java.list
  1130.         echo "deb-src http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | sudo tee -a /etc/apt/sources.list.d/java.list
  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-java12-installer oracle-java12-set-default 2>&1 | tee -a $LOGFILE
  1135.     else
  1136.         echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/java.list
  1137.         echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/java.list
  1138.         sudo apt-get $AQUIET update 2>&1 | tee -a $LOGFILE
  1139.         echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
  1140.         echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
  1141.         sudo apt-get $AQUIET -y install oracle-java8-installer 2>&1 | tee -a $LOGFILE
  1142.     fi
  1143. fi
  1144.  
  1145. if [[ $MYMENU == *"habridge"* ]]; then
  1146.     printstatus "Installing HA-Bridge on port 82"
  1147.     #sudo sed -i -e 's#80#81#g' /etc/apache2/ports.conf
  1148.     #sudo sed -i -e 's#80#81#g' /etc/apache2/sites-enabled/000-default.conf
  1149.     #sudo service apache2 restart
  1150.     ## now to install HA-Bridge on port 82 and get it running from power up.
  1151.     cd ~
  1152.     mkdir habridge
  1153.     cd habridge
  1154.     #wget https://github.com/bwssytems/ha-bridge/releases/download/v3.5.1/ha-bridge-3.5.1.jar -O ~/habridge/ha-bridge.jar
  1155.     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
  1156.     echo -e "[Unit]\n\
  1157. Description=HA Bridge\n\
  1158. Wants=network.target\n\
  1159. After=network.target\n\
  1160. \n\
  1161. [Service]\n\
  1162. Type=simple\n\
  1163. ExecStart=/usr/bin/java -jar -Dserver.port=82 -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge.jar\n\
  1164. \n\
  1165. [Install]\n\
  1166.    WantedBy=multi-user.target\n" | sudo tee /lib/systemd/system/habridge.service
  1167.     sudo systemctl  start habridge.service 2>&1 | tee -a $LOGFILE
  1168.     sudo systemctl enable habridge.service 2>&1 | tee -a $LOGFILE
  1169. fi
  1170.  
  1171.  
  1172.  
  1173. if [[ $MYMENU == *"phpsysinfo"* ]]; then
  1174.     printstatus "Installing PHPSysInfo"
  1175.     #   sudo apt-get $AQUIET -y install phpsysinfo
  1176.     #   sudo ln -s /usr/share/phpsysinfo /var/www/html
  1177.     if [ -d /var/www/html ]; then
  1178.         cd /var/www/html
  1179.         sudo git clone https://github.com/phpsysinfo/phpsysinfo.git 2>&1 | tee -a $LOGFILE
  1180.         sudo cp /var/www/html/phpsysinfo/phpsysinfo.ini.new /var/www/html/phpsysinfo/phpsysinfo.ini
  1181.     else
  1182.         printl "${IRed}!!!! Apache+PHP not installed! ${IWhite}\r\n"
  1183.     fi
  1184. fi
  1185.  
  1186. # you may want to use these on a Pi or elsewhere to force either a graphical or command line environment
  1187. #sudo systemctl set-default multi-user.target
  1188. #sudo systemctl set-default graphical.target
  1189.  
  1190. if [[ $MYMENU == *"rpiclone"* ]]; then
  1191.     printstatus "Installing RPI-Clone"
  1192.     cd
  1193.     sudo git clone https://github.com/billw2/rpi-clone.git
  1194.     cd rpi-clone
  1195.     sudo cp rpi-clone /usr/local/sbin
  1196.     cd
  1197.     sudo rm -r rpi-clone
  1198. fi
  1199.  
  1200. if [[ $MYMENU == *"log2ram"* ]]; then
  1201.     printstatus "Installing Log2Ram"
  1202.     cd
  1203.     git clone https://github.com/azlux/log2ram.git 2>&1 | tee -a $LOGFILE
  1204.     cd log2ram
  1205.     chmod +x install.sh
  1206.     sudo ./install.sh 2>&1 | tee -a $LOGFILE
  1207.     cd
  1208. fi
  1209.  
  1210. # Drop in an index file and css for a menu page
  1211. if [[ $MYMENU == *"addindex"* ]]; then
  1212.     printstatus "Adding index page and CSS"
  1213.     if [ -d /var/www/html ]; then
  1214.         sudo wget -a $LOGFILE $AQUIET http://www.scargill.net/iot/index.html -O /var/www/html/index.html
  1215.         sudo wget -a $LOGFILE $AQUIET http://www.scargill.net/iot/reset.css -O /var/www/html/reset.css
  1216.     else
  1217.         printl "${IRed}!!!! Apache+PHP not installed! ${IWhite}\r\n"
  1218.     fi
  1219. fi
  1220.  
  1221. if [[ $MYMENU == *"grafana"* ]]; then
  1222.         printstatus "Installing Grafana and Influxdb"
  1223.         cd
  1224.         sudo apt-get $AQUIET -y update 2>&1 | tee -a $LOGFILE
  1225.         sudo apt-get $AQUIET install -y apt-transport-https curl 2>&1 | tee -a $LOGFILE
  1226.         curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
  1227.         test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list
  1228.         test $VERSION_ID = "9" && echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list
  1229.         test $VERSION_ID = "10" && echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list
  1230.         test $VERSION_ID = "16.04" && echo "deb https://repos.influxdata.com/ubuntu xenial stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list
  1231.         curl -sL https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
  1232.         curl -sL https://packages.grafana.com/gpg.key | sudo apt-key add -
  1233.         [[ $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
  1234.         [[ $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
  1235.         [[ $OPSYS == *"UBUNTU"* ]] && echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
  1236.         sudo apt-get $AQUIET -y remove --purge grafana grafana-data 2>&1 | tee -a $LOGFILE
  1237.         sudo rm -rf /var/log/grafana /etc/grafana
  1238.         sudo apt-get $AQUIET -y autoremove 2>&1 | tee -a $LOGFILE
  1239.         sudo apt-get $AQUIET -y update 2>&1 | tee -a $LOGFILE
  1240.         sudo apt-get install $AQUIET -y influxdb grafana chronograf 2>&1 | tee -a $LOGFILE
  1241.         [ $? -eq 0 ] && grafana=1 # grafana installed
  1242.         if [ $grafana -eq 1 ]; then
  1243.                 #sudo sed -i -e 's/.*auth-enabled = false/  auth-enabled = true/g' /etc/influxdb/influxdb.conf
  1244.                 sudo systemctl daemon-reload 2>&1 | tee -a $LOGFILE
  1245.                 sudo systemctl enable influxdb 2>&1 | tee -a $LOGFILE
  1246.                 sudo systemctl start influxdb 2>&1 | tee -a $LOGFILE
  1247.                 sudo systemctl enable grafana-server 2>&1 | tee -a $LOGFILE
  1248.                 sudo systemctl start grafana-server 2>&1 | tee -a $LOGFILE
  1249.                 sudo systemctl enable chronograf 2>&1 | tee -a $LOGFILE
  1250.                 sudo systemctl start chronograf 2>&1 | tee -a $LOGFILE
  1251.     else
  1252.         printl "${IRed}!!!! GRAFANA AND INFLUXDB NOT INSTALLED! ${IWhite}\r\n"
  1253.     fi
  1254. fi
  1255.  
  1256. sudo rm -rf /var/cache/apt/archives/apt-fast
  1257. sudo apt-get $AQUIET -y clean 2>&1 | tee -a $LOGFILE
  1258.  
  1259. myip=$(hostname -I)
  1260. thehostname=$(hostname)
  1261. echo $newhostname | sudo tee /etc/hostname > /dev/null 2>&1
  1262. sudo sed -i '/^127.0.1.1/ d' /etc/hosts > /dev/null 2>&1
  1263. echo 127.0.1.1 $newhostname | sudo tee -a /etc/hosts > /dev/null 2>&1
  1264. sudo /etc/init.d/hostname.sh > /dev/null 2>&1
  1265.  
  1266. #printstatus "Installing Glances"
  1267. #sudo apt-get -y install python{,3}-setuptools 2>&1 | tee -a $LOGFILE
  1268. #sudo pip install glances 2>&1 | tee -a $LOGFILE
  1269. #sudo pip install bottle 2>&1 | tee -a $LOGFILE
  1270.  
  1271. printstatus "All done."
  1272. printf "${BIGreen}== ${BIYELLOW}When complete, remove the script from the /home/pi directory.\r\n"
  1273. printf "${BIGreen}==\r\n"
  1274. printf "${BIGreen}== ${BIPurple}Current IP: %s${BIWhite}\r\n" "$myip"
  1275. printf "${BIGreen}== ${BIPurple}Existing Hostname: %s  New Hostname: %s${BIWhite}\r\n\r\n" "$thehostname" "$newhostname"
  1276. echo -e Current IP: $myip  Hostname: $thehostname >> $LOGFILE
  1277. echo -e Hostname: $newhostname >> $LOGFILE
  1278. echo -e NPM: $(npm -v) >> $LOGFILE
  1279. echo -e PHP: $(php -v) >> $LOGFILE
  1280. echo -e NODE: $(node -v) >> $LOGFILE
  1281. echo -e MQTT: $(/usr/sbin/mosquitto --help | grep version) >> $LOGFILE
  1282. sudo grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* 2>&1 >> $LOGFILE
  1283. echo "alias space='df -h|grep -v udev|grep -v tmpfs|grep -v run'" | sudo tee -a /etc/bash.bashrc > /dev/null 2>&1
  1284. printstatus  "ALL DONE - PLEASE REBOOT NOW THEN TEST"
Advertisement
Add Comment
Please, Sign In to add comment