├── Fan controller.docx ├── fan ├── .gitattributes ├── .gitignore ├── MakePiUser.sh ├── run-fan.py ├── nodeRedUserReset ├── fan_shutdown.py ├── Flow.txt ├── Flow enhanced.txt └── ChristmasScript.txt /Fan controller.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SensorsIot/Dietpi-Helpers/HEAD/Fan controller.docx -------------------------------------------------------------------------------- /fan: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: dnscheck 4 | # Required-Start: $remote_fs $syslog 5 | # Required-Stop: $remote_fs $syslog 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Short-Description: Start fan script at boot time 9 | # Description: Enable service provided by daemon. 10 | ### END INIT INFO 11 | python /home/pi/Development/run-fan.py -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /MakePiUser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # ONLY use this script - as root - if user Pi does not exist on this device - to help with my main script, ROOT user can run this 4 | # (after adding execute permissions) to instantly make a user Pi with SUDO permissions and none of that constant password reminder stuff 5 | # pi user will have password "password" - you should really change that ASAP. This script will run quickly and silently. 6 | # 7 | # So for Debian systems with no SUDO - add this first. 8 | # 9 | apt-get install -y sudo 10 | # 11 | # Now adding Pi user and ensuring they are part of the SUDO group - and minimising password requests 12 | # 13 | adduser --quiet --disabled-password --shell /bin/bash --home /home/pi --gecos "User" pi 14 | echo "pi:password" | chpasswd 15 | usermod pi -g sudo 16 | echo "pi ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/pi 17 | chmod 0440 /etc/sudoers.d/pi -------------------------------------------------------------------------------- /run-fan.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Author: Edoardo Paolo Scalafiotti 3 | import os 4 | from time import sleep 5 | import signal 6 | import sys 7 | import RPi.GPIO as GPIO 8 | pin = 2 # The pin ID, edit here to change it 9 | maxTMP = 45 # The maximum temperature in Celsius after which we trigger the fan 10 | def setup(): 11 | GPIO.setmode(GPIO.BCM) 12 | GPIO.setup(pin, GPIO.OUT) 13 | GPIO.setwarnings(False) 14 | return() 15 | def getCPUtemperature(): 16 | res = os.popen('vcgencmd measure_temp').readline() 17 | temp =(res.replace("temp=","").replace("'C\n","")) 18 | print("temp is {0}".format(temp)) #Uncomment here for testing 19 | return temp 20 | def fanON(): 21 | setPin(True) 22 | return() 23 | def fanOFF(): 24 | setPin(False) 25 | return() 26 | def getTEMP(): 27 | CPU_temp = float(getCPUtemperature()) 28 | if CPU_temp>maxTMP: 29 | fanON() 30 | if CPU_temp tmpfile 20 | sudo echo " httpStatic: '/home/pi/.node-red/public'," >> tmpfile 21 | sudo echo " functionGlobalContext: {" >> tmpfile 22 | sudo echo " os:require('os')," >> tmpfile 23 | sudo echo " moment:require('moment'), " >> tmpfile 24 | sudo echo " fs:require('fs')" >> tmpfile 25 | sudo echo " }," >> tmpfile 26 | sudo echo " " >> tmpfile 27 | sudo echo " adminAuth: {" >> tmpfile 28 | sudo echo " type: \"credentials\"," >> tmpfile 29 | sudo echo " users: [{" >> tmpfile 30 | sudo echo " username: \"$adminname\"," >> tmpfile 31 | sudo echo " password: \"$bcryptadminpass\"," >> tmpfile 32 | sudo echo " permissions: \"*\"" >> tmpfile 33 | sudo echo " }]" >> tmpfile 34 | sudo echo " }," >> tmpfile 35 | sudo echo " " >> tmpfile 36 | sudo echo " httpNodeAuth: {user:\"$username\", pass:\"$bcryptuserpass\"}" >> tmpfile 37 | sudo echo "}" >> tmpfile 38 | sudo cat tmpfile >> settings.js 39 | sudo rm -f tmpfile 40 | sudo node-red-start 41 | -------------------------------------------------------------------------------- /fan_shutdown.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Author: Andreas Spiess 3 | import os 4 | import time 5 | from time import sleep 6 | import signal 7 | import sys 8 | import RPi.GPIO as GPIO 9 | 10 | 11 | fanPin = 17 # The pin ID, edit here to change it 12 | batterySensPin = 18 13 | 14 | maxTMP = 50 # The maximum temperature in Celsius after which we trigger the fan 15 | 16 | def Shutdown(): 17 | fanOFF() 18 | os.system("sudo shutdown -h 1") 19 | sleep(100) 20 | def setup(): 21 | GPIO.setmode(GPIO.BCM) 22 | GPIO.setup(fanPin, GPIO.OUT) 23 | GPIO.setup(batterySensPin, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) 24 | #GPIO.add_event_detect(batterySensPin, GPIO.RISING, callback = Shutdown, bouncetime = 2000) 25 | GPIO.setwarnings(False) 26 | fanOFF() 27 | return() 28 | def getCPUtemperature(): 29 | res = os.popen('vcgencmd measure_temp').readline() 30 | temp =(res.replace("temp=","").replace("'C\n","")) 31 | #print("temp is {0}".format(temp)) #Uncomment here for testing 32 | return temp 33 | def fanON(): 34 | setPin(True) 35 | return() 36 | def fanOFF(): 37 | setPin(False) 38 | return() 39 | def handleFan(): 40 | CPU_temp = float(getCPUtemperature()) 41 | if CPU_temp>maxTMP: 42 | fanON() 43 | #print("fan on") 44 | if CPU_temp /dev/null 2&>1 228 | if [ $? -eq 0 ]; then 229 | printf "${IRed}!!!! User \"pi\" already exists, logout as root and redo procedure as pi. ${IWhite}\r\n" 230 | else 231 | adduser --quiet --disabled-password --shell /bin/bash --home /home/pi --gecos "User" pi 232 | echo "pi:password" | chpasswd 233 | usermod pi -g sudo 234 | echo "pi ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/pi 235 | chmod 0440 /etc/sudoers.d/pi 236 | chmod 4755 /usr/bin/sudo # bug of dietpi 145, solved in future 146: https://github.com/Fourdee/DietPi/issues/794 237 | printf "${IRed}!!!! User PI created, password is \"password\". Logout as root and login as pi, and redo the procedure ${IWhite}\r\n" 238 | fi 239 | exit 240 | else 241 | exit 242 | fi 243 | fi 244 | 245 | # this block done here, to prevent possible ssh timeouts... 246 | # Allow remote root login and speed up SSH 247 | sudo sed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config 248 | sudo sed -i -e 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config 249 | sudo sed -i -e 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config 250 | sudo sed -i -e 's/TCPKeepAlive yes/TCPKeepAlive no/g' /etc/ssh/sshd_config 251 | sudo sed -i '$ a UseDNS no' /etc/ssh/sshd_config 252 | sudo sed -i '$ a ClientAliveInterval 30' /etc/ssh/sshd_config 253 | sudo sed -i '$ a ClientAliveCountMax 100' /etc/ssh/sshd_config 254 | sudo /etc/init.d/ssh restart 255 | 256 | # Whiptail menu may already be installed by default, on the other hand maybe not. 257 | sudo apt-get $AQUIET -y install whiptail ccze 258 | sudo update-alternatives --set newt-palette /etc/newt/palette.original 259 | # Another way - Xenial should come up in upper case in $DISTRO 260 | . /etc/os-release 261 | OPSYS=${ID^^} 262 | 263 | if [[ $OPSYS == "LINUXMINT" ]]; then 264 | OPSYS="UBUNTU" 265 | fi 266 | 267 | 268 | if [[ $OPSYS != *"RASPBIAN"* ]] && [[ $OPSYS != *"DEBIAN"* ]] && [[ $OPSYS != *"UBUNTU"* ]] && [[ $OPSYS != *"DIETPI"* ]]; then 269 | printf "${BIRed}By the look of it, not one of the supported operating systems - aborting${BIWhite}\r\n"; exit 270 | fi 271 | 272 | 273 | # setup a progress bar 274 | echo "Dpkg::Progress-Fancy \"1\";" | sudo tee /etc/apt/apt.conf.d/99progressbar > /dev/null 275 | echo "APT::Color \"1\";" | sudo tee -a /etc/apt/apt.conf.d/99progressbar > /dev/null 276 | 277 | username="user" 278 | userpass="password123" 279 | 280 | adminname="admin" 281 | adminpass="password123" 282 | 283 | SECONDS=0 284 | 285 | if [[ $OPSYS == *"RASPBIAN"* ]];then 286 | MYMENU=$(whiptail --title "Main Raspberry Pi Selection" --checklist \ 287 | "\nSelect items for your Pi as required then hit OK" 29 73 22 \ 288 | "quiet" "Quiet(er) install - untick for lots of info " ON \ 289 | "prereq" "Install general pre-requisites " ON \ 290 | "phone" "Install on Android Smartphone - see blog" OFF \ 291 | "mosquitto" "Install Mosquitto" ON \ 292 | "apache" "Install Apache/PHP/SQLITE + PHPLITEADMIN " ON \ 293 | "nodejs" "Install NodeJS" ON \ 294 | "nodered" "Install Node-Red" ON \ 295 | "webmin" "Install Webmin" ON \ 296 | "screen" "Install Screen" ON \ 297 | "java" "Update Java" ON \ 298 | "wiringpi" "Wiring Pi for the GPIO utility" OFF \ 299 | "mpg123" "Install MPG123" ON \ 300 | "modpass" "Mod USER and ADMIN passwords (password123)" ON \ 301 | "phpsysinfo" "Install PHPSYSYINFO" ON \ 302 | "upgradenpm" "Upgrade NPM to latest version " ON \ 303 | "addindex" "Add an index page and some CSS" ON \ 304 | "passwords" "Update ROOT and PI user passwords" OFF \ 305 | "installcu" "Install CU for serial VT100 Terminal" ON \ 306 | "installmc" "Install MC+MCEDIT file manager + editor " ON \ 307 | "installjed" "Install JED file editor" OFF \ 308 | "habridge" "Install HA-bridge on port 82" OFF \ 309 | "wolfram" "Remove Wolfram on a PI to save space" OFF \ 310 | "office" "Remove LibreOffice on PI to save space" OFF 3>&1 1>&2 2>&3) 311 | else 312 | MYMENU=$(whiptail --title "Main Non-Pi Selection" --checklist \ 313 | "\nSelect items as required then hit OK" 30 74 23 \ 314 | "quiet" "Quiet(er) install - untick for lots of info " ON \ 315 | "prereq" "Install general pre-requisites" ON \ 316 | "phone" "Install on Android Smartphone - see blog" OFF \ 317 | "mosquitto" "Install Mosquitto" ON \ 318 | "apache" "Install Apache/PHP/SQLITE + PHPLITEADMIN" ON \ 319 | "nodejs" "Install NodeJS" ON \ 320 | "nodered" "Install Node-Red" ON \ 321 | "odroid" "Install ODROID C2-specific GPIO" OFF \ 322 | "generich3" "Install GENERIC H3 GPIO (not Raspberry Pi) " OFF \ 323 | "webmin" "Install Webmin" ON \ 324 | "screen" "Install Screen" ON \ 325 | "java" "Update Java" ON \ 326 | "modpass" "Mod USER and ADMIN passwords (password123)" ON \ 327 | "mpg123" "Install MPG123" ON \ 328 | "opimonitor" "Install OPI-Monitor - H3 ONLY" OFF \ 329 | "phpsysinfo" "Install PHPSYSYINFO" ON \ 330 | "upgradenpm" "Upgrade NPN to latest version " ON \ 331 | "addindex" "Add an index page and some CSS" ON \ 332 | "passwords" "Update ROOT and PI user passwords" OFF \ 333 | "installcu" "Install CU for serial VT100 Terminal" ON \ 334 | "installmc" "Install MC+MCEDIT file manager + editor" ON \ 335 | "installjed" "Install JED file editor" OFF \ 336 | "habridge" "Install HA-bridge on port 82" OFF 3>&1 1>&2 2>&3) 337 | fi 338 | 339 | if [[ $MYMENU == *"quiet"* ]]; then 340 | AQUIET="-qq" 341 | NQUIET="-s" 342 | fi 343 | 344 | if [[ $MYMENU == "" ]]; then 345 | whiptail --title "Installation Aborted" --msgbox "Cancelled as requested." 8 78 346 | exit 347 | fi 348 | 349 | if [[ $MYMENU == *"modpass"* ]]; then 350 | username=$(whiptail --inputbox "Enter a user name (example user)" 8 40 $username 3>&1 1>&2 2>&3) 351 | if [[ -z "${username// }" ]]; then 352 | printf "No user name given - aborting\r\n"; exit 353 | fi 354 | 355 | userpass=$(whiptail --passwordbox "Enter a user password" 8 40 3>&1 1>&2 2>&3) 356 | if [[ -z "${userpass// }" ]]; then 357 | printf "No user password given - aborting${BIWhite}\r\n"; exit 358 | fi 359 | 360 | userpass2=$(whiptail --passwordbox "Confirm user password" 8 40 3>&1 1>&2 2>&3) 361 | if [ $userpass2 == "" ]; then 362 | printf "${BIRed}No password confirmation given - aborting${BIWhite}\r\n"; exit 363 | fi 364 | if [ $userpass != $userpass2 ] 365 | then 366 | printf "${BIRed}Passwords don't match - aborting${BIWhite}\r\n"; exit 367 | fi 368 | 369 | adminname=$(whiptail --inputbox "Enter an admin name (example admin)" 8 40 $adminname 3>&1 1>&2 2>&3) 370 | if [[ -z "${adminname// }" ]]; then 371 | printf "${BIRed}No admin name given - aborting${BIWhite}\r\n" 372 | exit 373 | fi 374 | 375 | adminpass=$(whiptail --passwordbox "Enter an admin password" 8 40 3>&1 1>&2 2>&3) 376 | if [[ -z "${adminpass// }" ]]; then 377 | printf "${BIRed}No user password given - aborting${BIWhite}\r\n"; exit 378 | fi 379 | 380 | adminpass2=$(whiptail --passwordbox "Confirm admin password" 8 40 3>&1 1>&2 2>&3) 381 | if [ $adminpass2 == "" ]; then 382 | printf "${BIRed}No password confirmation given - aborting${BIWhite}\r\n"; exit 383 | fi 384 | if [ $adminpass != $adminpass2 ]; then 385 | printf "${BIRed}Passwords don't match - aborting${BIWhite}\r\n"; exit 386 | fi 387 | fi 388 | 389 | 390 | if [[ $MYMENU == *"passwords"* ]]; then 391 | echo "Update your PI password" 392 | sudo passwd pi 393 | echo "Update your ROOT password" 394 | sudo passwd root 395 | fi 396 | 397 | 398 | if [[ $OPSYS != *"RASPBIAN"* ]]; then 399 | printstatus "Adding user Pi permissions" 400 | sudo adduser pi sudo 401 | sudo adduser pi adm 402 | sudo adduser pi dialout 403 | sudo adduser pi cdrom 404 | sudo adduser pi audio 405 | sudo adduser pi video 406 | sudo adduser pi plugdev 407 | sudo adduser pi games 408 | sudo adduser pi users 409 | sudo adduser pi netdev 410 | sudo adduser pi input 411 | fi 412 | 413 | 414 | 415 | 416 | if [[ $MYMENU == *"phone"* ]]; then 417 | echo "en_US.UTF-8 UTF-8" | sudo tee -a /etc/locale.gen > /dev/null 418 | # echo "service rsyslog stop" | sudo tee -a /etc/init.d/rc.local > /dev/null 419 | sudo update-rc.d rsyslog disable 420 | sudo locale-gen 421 | sudo sed -i -e 's#exit 0##g' /etc/rc.local 422 | echo "cd /home/pi/habridge" | sudo tee -a /etc/rc.local > /dev/null 423 | echo "[ -f /home/pi/habridge/habridge-log.txt ] && rm /home/pi/habridge/habridge-log.txt" | sudo tee -a /etc/rc.local > /dev/null 424 | 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 425 | echo "chmod 777 /home/pi/habridge/habridge-log.txt" | sudo tee -a /etc/rc.local > /dev/null 426 | echo "exit 0" | sudo tee -a /etc/rc.local > /dev/null 427 | else 428 | sudo apt-get install avahi-daemon avahi-utils -y 429 | sudo sed -i -e 's/use-ipv6=yes/use-ipv6=no/g' /etc/avahi/avahi-daemon.conf 430 | fi 431 | 432 | if [[ $MYMENU == *"wolfram"* ]]; then 433 | printstatus "Removing Wolfram" 434 | sudo apt-get $AQUIET -y purge wolfram-engine 435 | fi 436 | 437 | if [[ $MYMENU == *"office"* ]]; then 438 | printstatus "Removing LibreOffice" 439 | sudo apt-get $AQUIET -y remove --purge libreoffice* 440 | fi 441 | 442 | 443 | if [[ $MYMENU == *"prereq"* ]]; then 444 | printstatus "Installing pre-requisites (this could take some time)" 445 | sudo apt-get $AQUIET -y autoremove 446 | sudo apt-get $AQUIET update 447 | sudo apt-get $AQUIET -y upgrade 448 | # fix for RPI treating PING as a root function - by Dave 449 | sudo setcap cap_net_raw=ep /bin/ping 450 | sudo setcap cap_net_raw=ep /bin/ping6 451 | # Prerequisite suggested by Julian and adding in python-dev - and stuff I've added for SAMBA and telnet 452 | 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 samba samba-common samba-common-bin winbind telnet usbutils gawk jq 453 | # libboost-thread-dev libboost-all-dev 454 | # This line to ensure name is resolved from hosts FIRST 455 | sudo sed -i '/\[global\]/a name resolve order = hosts wins bcast' /etc/samba/smb.conf 456 | fi 457 | 458 | if [[ $MYMENU == *"jed"* ]]; then 459 | printstatus "Installing JED Editor" 460 | sudo apt-get $AQUIET -y install jed 461 | fi 462 | 463 | if [[ $MYMENU == *"mosquitto"* ]]; then 464 | printstatus "Installing Mosquitto with Websockets" 465 | cd 466 | if [[ $OPSYS == *"UBUNTU"* ]]; then 467 | sudo apt-get $AQUIET -y install mosquitto mosquitto-clients 468 | else 469 | wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key -O - | sudo apt-key add - 470 | echo "deb http://repo.mosquitto.org/debian jessie main" |sudo tee /etc/apt/sources.list.d/mosquitto-jessie.list 471 | sudo apt-get $AQUIET -y update && sudo apt-get $AQUIET -y install mosquitto mosquitto-clients 472 | fi 473 | 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" 474 | sudo touch /etc/mosquitto/passwords 475 | sudo mosquitto_passwd -b /etc/mosquitto/passwords $adminname $adminpass 476 | fi 477 | 478 | if [[ $MYMENU == *"wiringpi"* ]]; then 479 | cd 480 | git clone git://git.drogon.net/wiringPi 481 | cd ~/wiringPi 482 | ./build 483 | fi 484 | 485 | # Moved sqlite3 so that node-red sql node will install 486 | # use back facing quotes in here - no idea why. 487 | # Changed the order of installation of Apache etc to solve issues with ARMBIAN 488 | # 489 | if [[ $MYMENU == *"apache"* ]]; then 490 | printstatus "Installing Apache/PHP and Sqlite" 491 | cd 492 | sudo groupadd -f -g33 www-data 493 | 494 | if [[ $OPSYS != *"UBUNTU"* ]]; then 495 | sudo apt-get $AQUIET -y install apache2 libapache2-mod-php5 sqlite3 php5-sqlite 496 | else 497 | sudo apt-get $AQUIET -y install apache2 libapache2-mod-php7.0 sqlite3 php-sqlite3 php-xml php-mbstring 498 | fi 499 | 500 | cd /var/www/html 501 | sudo mkdir phpliteadmin 502 | cd phpliteadmin 503 | sudo wget --no-verbose --no-check-certificate http://bitbucket.org/phpliteadmin/public/downloads/phpLiteAdmin_v1-9-7-1.zip 504 | sudo unzip phpLiteAdmin_v1-9-7-1.zip 505 | sudo mv phpliteadmin.php index.php 506 | sudo mv phpliteadmin.config.sample.php phpliteadmin.config.php 507 | sudo rm *.zip 508 | sudo mkdir themes 509 | cd themes 510 | sudo wget --no-verbose --no-check-certificate http://bitbucket.org/phpliteadmin/public/downloads/phpliteadmin_themes_2013-12-26.zip 511 | sudo unzip phpliteadmin_themes_2013-12-26.zip 512 | sudo rm *.zip 513 | sudo sed -i -e 's#\$directory = \x27.\x27;#\$directory = \x27/home/pi/dbs/\x27;#g' /var/www/html/phpliteadmin/phpliteadmin.config.php 514 | sudo sed -i -e "s#\$password = \x27admin\x27;#\$password = \x27$adminpass\x27;#g" /var/www/html/phpliteadmin/phpliteadmin.config.php 515 | sudo sed -i -e "s#\$subdirectories = false;#\$subdirectories = true;#g" /var/www/html/phpliteadmin/phpliteadmin.config.php 516 | cd 517 | 518 | mkdir dbs 519 | sqlite3 /home/pi/dbs/iot.db << EOF 520 | CREATE TABLE IF NOT EXISTS \`pinDescription\` ( 521 | \`pinID\` INTEGER PRIMARY KEY NOT NULL, 522 | \`pinNumber\` varchar(2) NOT NULL, 523 | \`pinDescription\` varchar(255) NOT NULL 524 | ); 525 | CREATE TABLE IF NOT EXISTS \`pinDirection\` ( 526 | \`pinID\` INTEGER PRIMARY KEY NOT NULL, 527 | \`pinNumber\` varchar(2) NOT NULL, 528 | \`pinDirection\` varchar(3) NOT NULL 529 | ); 530 | CREATE TABLE IF NOT EXISTS \`pinStatus\` ( 531 | \`pinID\` INTEGER PRIMARY KEY NOT NULL, 532 | \`pinNumber\` varchar(2) NOT NULL, 533 | \`pinStatus\` varchar(1) NOT NULL 534 | ); 535 | CREATE TABLE IF NOT EXISTS \`users\` ( 536 | \`userID\` INTEGER PRIMARY KEY NOT NULL, 537 | \`username\` varchar(28) NOT NULL, 538 | \`password\` varchar(64) NOT NULL, 539 | \`salt\` varchar(8) NOT NULL 540 | ); 541 | CREATE TABLE IF NOT EXISTS \`device_list\` ( 542 | \`device_name\` varchar(80) NOT NULL DEFAULT '', 543 | \`device_description\` varchar(80) DEFAULT NULL, 544 | \`device_attribute\` varchar(80) DEFAULT NULL, 545 | \`logins\` int(11) DEFAULT NULL, 546 | \`creation_date\` datetime DEFAULT NULL, 547 | \`last_update\` datetime DEFAULT NULL, 548 | PRIMARY KEY (\`device_name\`) 549 | ); 550 | 551 | CREATE TABLE IF NOT EXISTS \`readings\` ( 552 | \`recnum\` INTEGER PRIMARY KEY, 553 | \`location\` varchar(20), 554 | \`value\` int(11) NOT NULL, 555 | \`logged\` timestamp not NULL DEFAULT CURRENT_TIMESTAMP , 556 | \`device_name\` varchar(40) not null, 557 | \`topic\` varchar(40) not null 558 | ); 559 | 560 | 561 | CREATE TABLE IF NOT EXISTS \`pins\` ( 562 | \`gpio0\` int(11) NOT NULL DEFAULT '0', 563 | \`gpio1\` int(11) NOT NULL DEFAULT '0', 564 | \`gpio2\` int(11) NOT NULL DEFAULT '0', 565 | \`gpio3\` int(11) NOT NULL DEFAULT '0' 566 | ); 567 | INSERT INTO PINS VALUES(0,0,0,0); 568 | CREATE TABLE IF NOT EXISTS \`temperature_record\` ( 569 | \`device_name\` varchar(64) NOT NULL, 570 | \`rec_num\` INTEGER PRIMARY KEY, 571 | \`temperature\` float NOT NULL, 572 | \`date_time\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP 573 | ); 574 | CREATE TABLE IF NOT EXISTS \`Device\` ( 575 | \`DeviceID\` INTEGER PRIMARY KEY, 576 | \`DeviceName\` TEXT NOT NULL 577 | ); 578 | CREATE TABLE IF NOT EXISTS \`DeviceData\` ( 579 | \`DataID\` INTEGER PRIMARY KEY, 580 | DeviceID INTEGER, 581 | \`DataName\` TEXT, FOREIGN KEY(DeviceID ) REFERENCES Device(DeviceID) 582 | ); 583 | CREATE TABLE IF NOT EXISTS \`Data\` ( 584 | SequenceID INTEGER PRIMARY KEY, 585 | \`DeviceID\` INTEGER NOT NULL, 586 | \`DataID\` INTEGER NOT NULL, 587 | \`DataValue\` NUMERIC NOT NULL, 588 | \`epoch\` NUMERIC NOT NULL, 589 | \`timestamp\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP , FOREIGN KEY(DataID, DeviceID ) REFERENCES DeviceData(DAtaID, DeviceID ) 590 | ); 591 | EOF 592 | 593 | cd 594 | chmod 777 /home/pi/dbs 595 | chmod 666 /home/pi/dbs/iot.db 596 | cd 597 | fi 598 | 599 | 600 | if [[ $MYMENU == *"nodejs"* ]]; then 601 | printstatus "Installing NodeJS" 602 | if [[ $(uname -m) == *"armv6"* ]]; then 603 | printstatus "Installing ARM6 version" 604 | wget --no-check-certificate https://nodejs.org/dist/v6.10.0/node-v6.10.0-linux-armv6l.tar.xz 605 | tar -xvf node-v6.10.0-linux-armv6l.tar.xz 606 | cd node-v6.10.0-linux-armv6l 607 | sudo cp -R * /usr/local/ 608 | else 609 | curl -sL https://deb.nodesource.com/setup_6.x > nodesetup.sh 610 | sudo bash nodesetup.sh 611 | sudo apt-get $AQUIET -y install nodejs 612 | fi 613 | fi 614 | 615 | 616 | if [[ $MYMENU == *"nodered"* ]]; then 617 | #sudo npm cache clean 618 | printstatus "Installing Node-Red" 619 | sudo npm $NQUIET install -g --unsafe-perm node-red 620 | if [[ $MYMENU == *"phone"* ]]; then 621 | sudo wget -O /etc/init.d/nodered https://gist.githubusercontent.com/bigmonkeyboy/9962293/raw/0fe19671b1aef8e56cbcb20f6677173f8495e539/nodered 622 | sudo chmod 755 /etc/init.d/nodered && sudo update-rc.d nodered defaults 623 | else 624 | sudo wget --no-check-certificate https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service -O /lib/systemd/system/nodered.service 625 | sudo wget --no-check-certificate https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start -O /usr/bin/node-red-start 626 | sudo wget --no-check-certificate https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop -O /usr/bin/node-red-stop 627 | #sudo sed -i -e 's#=pi#=%USER#g' /lib/systemd/system/nodered.service 628 | sudo chmod +x /usr/bin/node-red-st* 629 | sudo systemctl daemon-reload 630 | fi 631 | 632 | cd 633 | mkdir .node-red 634 | cd .node-red 635 | printstatus "Installing Nodes" 636 | npm $NQUIET install moment 637 | npm $NQUIET install node-red-contrib-config 638 | npm $NQUIET install node-red-contrib-grove 639 | npm $NQUIET install node-red-contrib-bigtimer 640 | npm $NQUIET install node-red-contrib-esplogin 641 | npm $NQUIET install node-red-contrib-timeout 642 | npm $NQUIET install node-red-node-openweathermap 643 | npm $NQUIET install node-red-node-google 644 | npm $NQUIET install node-red-node-sqlite 645 | npm $NQUIET install node-red-node-emoncms 646 | npm $NQUIET install node-red-node-geofence 647 | npm $NQUIET install node-red-contrib-ivona 648 | npm $NQUIET install node-red-contrib-moment 649 | npm $NQUIET install node-red-contrib-particle 650 | npm $NQUIET install node-red-contrib-web-worldmap 651 | npm $NQUIET install node-red-contrib-graphs 652 | npm $NQUIET install node-red-contrib-isonline 653 | npm $NQUIET install node-red-node-ping 654 | npm $NQUIET install node-red-node-random 655 | npm $NQUIET install node-red-node-smooth 656 | npm $NQUIET install node-red-contrib-npm 657 | npm $NQUIET install node-red-contrib-file-function 658 | npm $NQUIET install node-red-contrib-boolean-logic 659 | npm $NQUIET install node-red-node-arduino 660 | npm $NQUIET install node-red-contrib-blynk-websockets 661 | npm $NQUIET install node-red-dashboard 662 | npm $NQUIET install node-red-node-darksky 663 | npm $NQUIET install node-red-node-serialport 664 | npm $NQUIET install node-red-contrib-owntracks 665 | npm $NQUIET install node-red-contrib-chatbot 666 | 667 | sudo npm $NQUIET install bcryptjs 668 | 669 | if [[ $OPSYS == *"RASPBIAN"* ]]; then 670 | sudo sed -i -e 's#exit 0#chmod 777 /dev/ttyAMA0\nexit 0#g' /etc/rc.local 671 | sudo apt-get -y install python{,3}-rpi.gpio 672 | npm $NQUIET install node-red-contrib-gpio 673 | npm $NQUIET install raspi-io 674 | fi 675 | 676 | cd ~/.node-red/ 677 | sudo service nodered start ; while [ ! -f settings.js ] ; do sudo sleep 1 ; done ; sudo service nodered stop; 678 | echo " " 679 | bcryptadminpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $adminpass) 680 | bcryptuserpass=$(node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" $userpass) 681 | # echo Encrypted password: $bcryptpass 682 | cp settings.js settings.js.bak-pre-crypt 683 | 684 | datetimestamp=`date +%Y-%m-%d_%Hh%Mm` 685 | cd ~/.node-red 686 | # this will add the TOP piece of code for non-vol variables in settings.js 687 | 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 688 | 689 | sudo sed -i -e 's#functionGlobalContext: {#\/\/ functionGlobalContext: {#g' settings.js 690 | sudo sed -i -e 's#\s\s\s\s\},# \/\/ },#g' settings.js 691 | sudo sed -i -e 's#^\}#,#g' settings.js 692 | sudo echo " " > tmpfile 693 | sudo echo " httpStatic: '/home/pi/.node-red/public'," >> tmpfile 694 | sudo echo " functionGlobalContext: {" >> tmpfile 695 | sudo echo " os:require('os')," >> tmpfile 696 | sudo echo " moment:require('moment'), " >> tmpfile 697 | sudo echo " fs:require('fs'), " >> tmpfile 698 | sudo echo " mySettings:mySettings " >> tmpfile 699 | sudo echo " }," >> tmpfile 700 | sudo echo " " >> tmpfile 701 | sudo echo " adminAuth: {" >> tmpfile 702 | sudo echo " type: \"credentials\"," >> tmpfile 703 | sudo echo " users: [{" >> tmpfile 704 | sudo echo " username: \"$adminname\"," >> tmpfile 705 | sudo echo " password: \"$bcryptadminpass\"," >> tmpfile 706 | sudo echo " permissions: \"*\"" >> tmpfile 707 | sudo echo " }]" >> tmpfile 708 | sudo echo " }," >> tmpfile 709 | sudo echo " " >> tmpfile 710 | sudo echo " httpNodeAuth: {user:\"$username\", pass:\"$bcryptuserpass\"}" >> tmpfile 711 | sudo echo "}" >> tmpfile 712 | sudo cat tmpfile >> settings.js 713 | sudo rm -f tmpfile 714 | if [[ $MYMENU == *"phone"* ]]; then 715 | cd && sudo mv /etc/init.d/sendsigs . 716 | else 717 | sudo systemctl enable nodered.service 718 | fi 719 | fi 720 | 721 | 722 | if [[ $OPSYS != *"RASPBIAN"* ]]; then 723 | 724 | if [[ $MYMENU == *"odroid"* ]]; then 725 | printstatus "Installing Odroid GPIO" 726 | 727 | git clone https://github.com/hardkernel/wiringPi.git 728 | cd wiringPi 729 | ./build 730 | sudo chmod a+s /usr/local/bin/gpio 731 | fi 732 | if [[ $MYMENU == *"generich3"* ]]; then 733 | printstatus "Installing H3 GPIO" 734 | # Install NanoPi H3 based IO library 735 | git clone https://github.com/zhaolei/WiringOP.git -b h3 736 | cd WiringOP 737 | chmod +x ./build 738 | sudo ./build 739 | cd 740 | fi 741 | fi 742 | 743 | 744 | if [[ $MYMENU == *"webmin"* ]]; then 745 | printstatus "Installing Webmin at port 10000 - could take some time" 746 | #cd 747 | #mkdir webmin 748 | #cd webmin 749 | #wget --no-verbose http://prdownloads.sourceforge.net/webadmin/webmin-1.831.tar.gz 750 | #sudo gunzip -q webmin-1.831.tar.gz 751 | #tar -xf webmin-1.831.tar 752 | #sudo rm *.tar 753 | #cd webmin-1.831 754 | #sudo ./setup.sh /usr/local/Webmin 755 | wget http://www.webmin.com/jcameron-key.asc -O - | sudo apt-key add - 756 | echo "deb http://download.webmin.com/download/repository sarge contrib" | sudo tee /etc/apt/sources.list.d/webmin.list > /dev/null 757 | sudo apt-get $AQUIET -y update 758 | sudo apt-get $AQUIET -y install webmin 759 | # http vs https: if you want unsecure http access on port 10000 instead of https, uncomment next line 760 | sudo sed -i -e 's#ssl=1#ssl=0#g' /etc/webmin/miniserv.conf 761 | fi 762 | 763 | 764 | if [[ $MYMENU == *"mpg123"* ]]; then 765 | printstatus "Installing MPG123" 766 | sudo apt-get $AQUIET -y install mpg123 767 | fi 768 | 769 | 770 | # 771 | # 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! 772 | # 773 | if [[ $MYMENU == *"opimonitor"* ]]; then 774 | printstatus "Installing Armbian Monitor" 775 | sudo armbianmonitor -r 776 | fi 777 | 778 | 779 | #task_start "Install Internet Time Updater for Webmin (NTPUpdate)?" "Installing NTPUpdate" 780 | #if [ $skip -eq 0 ]; then 781 | #sudo apt-get $AQUIET -y -o=Dpkg::Use-Pty=0 --force-yes install ntpdate 782 | #task_end 783 | #fi 784 | 785 | 786 | #task_start "Install Email SMTP?" "Installing Email utils and SMTP..." 787 | #if [ $skip -eq 0 ]; then 788 | #cd 789 | #sudo apt-get $AQUIET -y -o=Dpkg::Use-Pty=0 --force-yes install mailutils ssmtp 790 | #task_end 791 | #fi 792 | 793 | 794 | if [[ $MYMENU == *"screen"* ]]; then 795 | printstatus "Installing Screen" 796 | cd 797 | sudo apt-get -y $AQUIET install screen 798 | fi 799 | 800 | 801 | if [[ $MYMENU == *"habridge"* ]]; then 802 | printstatus "Installing HA-Bridge on port 82" 803 | #sudo sed -i -e 's#80#81#g' /etc/apache2/ports.conf 804 | #sudo sed -i -e 's#80#81#g' /etc/apache2/sites-enabled/000-default.conf 805 | #sudo service apache2 restart 806 | ## now to install HA-Bridge on port 82 and get it running from power up. 807 | cd ~ 808 | mkdir habridge 809 | cd habridge 810 | #wget https://github.com/bwssytems/ha-bridge/releases/download/v3.5.1/ha-bridge-3.5.1.jar -O ~/habridge/ha-bridge.jar 811 | 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 812 | echo -e "[Unit]\n\ 813 | Description=HA Bridge\n\ 814 | Wants=network.target\n\ 815 | After=network.target\n\ 816 | \n\ 817 | [Service]\n\ 818 | Type=simple\n\ 819 | ExecStart=/usr/bin/java -jar -Dserver.port=82 -Dconfig.file=/home/pi/habridge/data/habridge.config /home/pi/habridge/ha-bridge.jar\n\ 820 | \n\ 821 | [Install]\n\ 822 | WantedBy=multi-user.target\n" | sudo tee /lib/systemd/system/habridge.service 823 | sudo systemctl start habridge.service 824 | sudo systemctl enable habridge.service 825 | fi 826 | 827 | 828 | if [[ $MYMENU == *"java"* ]]; then 829 | printstatus "Installing/Updating Java" 830 | echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list 831 | echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list 832 | sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 833 | sudo apt-get $AQUIET update 834 | echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections 835 | echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections 836 | sudo apt-get $AQUIET -y install oracle-java8-installer 837 | fi 838 | 839 | 840 | if [[ $MYMENU == *"phpsysinfo"* ]]; then 841 | printstatus "Installing PHPSysInfo" 842 | # sudo apt-get $AQUIET -y install phpsysinfo 843 | # sudo ln -s /usr/share/phpsysinfo /var/www/html 844 | cd /var/www/html 845 | sudo git clone https://github.com/phpsysinfo/phpsysinfo.git 846 | sudo cp /var/www/html/phpsysinfo/phpsysinfo.ini.new /var/www/html/phpsysinfo/phpsysinfo.ini 847 | fi 848 | 849 | 850 | # you may want to use these on a Pi or elsewhere to force either a graphical or command line environment 851 | #sudo systemctl set-default multi-user.target 852 | #sudo systemctl set-default graphical.target 853 | 854 | 855 | 856 | if [[ $MYMENU == *"upgradenpm"* ]]; then 857 | printstatus "Upgrading NPM to the latest version" 858 | sudo npm $NQUIET install npm@latest -g 859 | fi 860 | 861 | 862 | # Add CU to enable serial VT100 mode for terminals 863 | if [[ $MYMENU == *"installcu"* ]]; then 864 | printstatus "Installing CU" 865 | sudo apt-get $AQUIET -y install cu 866 | fi 867 | 868 | 869 | if [[ $MYMENU == *"installmc"* ]]; then 870 | printstatus "Installing MC File manager and editor" 871 | cd 872 | sudo apt-get -y $AQUIET install mc 873 | fi 874 | 875 | 876 | # Drop in an index file and css for a menu page 877 | if [[ $MYMENU == *"addindex"* ]]; then 878 | printstatus "Adding index page and CSS" 879 | sudo wget $AQUIET http://www.scargill.net/iot/index.html -O /var/www/html/index.html 880 | sudo wget $AQUIET http://www.scargill.net/iot/reset.css -O /var/www/html/reset.css 881 | fi 882 | 883 | sudo apt-get $AQUIET -y clean 884 | 885 | myip=$(hostname -I) 886 | newhostname=$(hostname) 887 | 888 | cd 889 | newhostname=$(whiptail --inputbox "Nearly done. Enter new host name or OK" 8 40 $newhostname 3>&1 1>&2 2>&3) 890 | echo $newhostname | sudo tee /etc/hostname 2&>1 /dev/null 891 | sudo sed -i '/^127.0.1.1/ d' /etc/hosts 2&>1 /dev/null 892 | echo 127.0.1.1 $newhostname | sudo tee -a /etc/hosts 2&>1 /dev/null 893 | sudo /etc/init.d/hostname.sh 2&>1 /dev/null 894 | 895 | 896 | printstatus "All done." 897 | printf 'Current IP is %s and hostname is \r\n' "$myip" "$newhostname" 898 | printf "${BIMagenta}**** PLEASE REBOOT NOW ****${IWhite}\r\n" 899 | --------------------------------------------------------------------------------