Snippets

Peter Scargill This script is now out of date - use the new one

Created by Peter Scargill last modified
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
#!/bin/bash
 
## Now out of date - use the newer script - DO NOT USE THIS SCRIPT
## This script was originally developed for the Raspberry Pi
## On non-Pi systems such as the FriendlyArm M1 I use Armbian. 
## Don't expect ports to work out of the box on non-Pi systems
## Also, for all systems, after you load this script and before running, you need to give 
## it execute permissions and sure it is saved in Linux format (carriage returns) - Notepad++ has this under 
## edit - eol conversion.
## See http://tech.scargill.net/orange-pi-pc-battle-of-the-pis/
## 10/12/2016 Tested on Pi3 with latest software Jessie 
## 16/5/2016 Tested on NanoPi M1 - wiped graphical interface but see last comment to get it back (
## got 3 UARTS out of the M1)
## 22/06/2016 added questions for non-Pi boards
## 22/06/2016 tested on NanoPi NEO using Armbian Jessie Server 
## http://www.armbian.com/donate/?f=Armbian_5.20_Nanopineo_Debian_jessie_3.4.112.7z
## Important: For NEO (or similar) when asked by Armbian to make a new user - make it user "pi"
##  - Pi and NanoPi units inc M1, NEO, CHIP, Orange Pi PC (Armbian), OrangePi Plus 2e and Roseapple Pi should work
## NOTE - removed node-red-contrib-admin from Node-red setup as you can now do 
## installs in the palette manager in the editor
##
## IMPORTANT - user PI must have script execute permission for this script.
##
## IMPORTANT - when selection GPIO for non-Raspberry Pi devices note - specific support for ODROID C2
##
## December 2 - tested Roseapple Pi using Armbian - for Node-Red serial had to 
## enable permissions for the serial - everything worked first time
##
## Assuming access as pi user. Please note this will NOT WORK AS ROOT - The Node-Red install will fail.
## Do not use this script as SUDO.
##
## Typically, sitting in your home directory (/home/pi) as user Pi you might want to use NANO to install this script
## and after giving the script execute permission (sudo chmod 0744 /home/pi/script.sh)
## you could run the file as ./script.sh
##
## Includes Mosquitto with web sockets (Port 9001), SQLITE ( xxx.xxx.xxx.xxx/phpliteadmin),
## Node-Red (xxx.xxx.xxx:1880), Node-Red-Dashboard (xxx.xxx.xxx.xxx:1880/ui) and Webmin(xxx.xxx.xxx:10000)
## as well as web page based items like /phpliteadmin and /phpsysinfo
##
## http://tech.scargill.net - much of this was thanks to help from others!
##
## Note- on the Odroid C2 everything installed except webmin. After reboot this is what I did to get it running..
##    wget http://prdownloads.sourceforge.net/webadmin/webmin_1.820_all.deb
##    sudo dpkg --install webmin_1.820_all.deb
## That complained about missing bits so I used... 
##    sudo apt-get install -y perl libnet-ssleay-perl openssl libauthen-pam-perl 
##             libpam-runtime libio-pty-perl apt-show-versions python
## That seemed to fail and suggested I use...
##   sudo apt-get -y -f install
## That installed the lot - working - something to do with it being 64 bits - but it works - 
## pi or root user and password and https://whatever:10000
##
## Some mods in here including bits to remove manual work - from reader Antonio Fragola - MrShark. Thank you.
##
## If you want Node-Red security you need to add this to the settings.js file in /home/pi/.node-red
##
##
##    functionGlobalContext: {
##       os:require('os'),
##        // bonescript:require('bonescript'),
##        // jfive:require("johnny-five"),
##       moment:require('moment'),
##       fs:require('fs')
##    },
## 
##    adminAuth: {
##    type: "credentials",
##    users: [{
##       username: "admin",
##        password: "your encrypted password see node red site",
##        permissions: "*"
##    }]
##},
##
##  httpNodeAuth: {user:"user", pass:"your encrypted password see node red site"},

# ROUTINES
# Here at the beginning, a load of useful routines - see further down

# Get time as a UNIX timestamp (seconds elapsed since Jan 1, 1970 0:00 UTC)
startTime="$(date +%s)"
columns=$(tput cols)
user_response=""
 
# High Intensity
IGreen='\e[0;92m'       # Green
IYellow='\e[0;93m'      # Yellow
IBlue='\e[0;94m'        # Blue
ICyan='\e[0;96m'        # Cyan
IWhite='\e[0;97m'       # White
 
# Bold High Intensity
BIRed='\e[1;91m'        # Red
BIGreen='\e[1;92m'      # Green
BIYellow='\e[1;93m'     # Yellow
BIPurple='\e[1;95m'     # Purple
BIMagenta='\e[1;95m'    # Purple
BICyan='\e[1;96m'       # Cyan
BIWhite='\e[1;97m'      # White

#!/bin/bash
 
skip=0
other=0
 
clean_stdin()
{
while read -r -t 0; do
    read -n 256 -r -s
done
}
 
# Permanent loop until both passwords are the same..
function user_input {
  local VARIABLE_NAME=${1}
  local VARIABLE_NAME_1="A"
  local VARIABLE_NAME_2="B"
  while true; do
      printf "${BICyan}$2: ${BIWhite}";
      if [ "$3" = "hide" ] ; then
        stty -echo;
      fi
      read VARIABLE_NAME_1;
      stty echo;
      if [ "$3" = "hide" ] ; then
          printf "\n${BICyan}$2 (again) : ${BIWhite}";
          stty -echo;
          read VARIABLE_NAME_2;
          stty echo;
      else
          VARIABLE_NAME_2=$VARIABLE_NAME_1;
      fi
      if [ $VARIABLE_NAME_1 != $VARIABLE_NAME_2 ] ; then
         printf "\n${BIRed}Sorry, did not match!${BIWhite}\n";
      else
         break;
       fi
  done
  readonly ${VARIABLE_NAME}=$VARIABLE_NAME_1;
  if [ "$3" == "hide" ] ; then
     printf "\n";
  fi     
}

stopit=0
other=0
yes=0
nohelp=0
hideother=0

 
timecount(){
	sec=30
	while [ $sec -ge 0 ]; do

		if [ $nohelp -eq 1 ]; then

	if [ $hideother -eq 1 ]; then
		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}"
else
		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}"
fi

		else
			printf "${BIPurple}Continue ${BIWhite}y${BIPurple}(es)/${BIWhite}h${BIPurple}(elp)-  ${BIGreen}00:0$min:$sec${BIPurple} remaining\033[0K\r${BIWhite}"
		fi
		sec=$((sec-1))
		trap '' 2
		stty -echo
		read -t 1 -n 1 user_response
		stty echo
		trap - 2
		if [ -n  "$user_response" ]; then
			break
		fi                 
	done
}


task_start(){
printf "\r\n" 
printf "${BIGreen}%*s\n" $columns | tr ' ' -
printf "$1"
clean_stdin
skip=0
printf "\n${BIGreen}%*s${BIWhite}\n" $columns | tr ' ' -
elapsedTime="$(($(date +%s)-startTime))"
printf "Elapsed Time: %02d hrs %02d mins %02d secs\n" "$((elapsedTime/3600%24))" "$((elapsedTime/60%60))" "$((elapsedTime%60))"
clean_stdin
if [ "$user_response" != "a" ]; then
    timecount
fi
echo -e "                                                                        \033[0K\r"
if  [ "$user_response" = "e" ]; then
    printf "${BIWhite}"
    exit 1
fi 
if  [ "$user_response" = "n" ]; then
    skip=1
fi 
if  [ "$user_response" = "o" ]; then
    other=1
fi 
if  [ "$user_response" = "h" ]; then
    stopit=1
fi 
if  [ "$user_response" = "y" ]; then
    yes=1
fi 
if [ -n  "$2" ]; then
    if [ $skip -eq 0 ]; then
        printf "${BIYellow}$2${BIWhite}\n"
    else
        printf "${BICyan}%*s${BIWhite}\n" $columns '[SKIPPED]'
    fi
fi
}
 
task_end(){
    printf "${BICyan}%*s${BIWhite}\n" $columns '[OK]'
}
 
 
#
# MAIN SECTION OF SCRIPT - action begins here
#
sudo apt-get -qq -y install whiptail

# for future use to determine if jessie or xenial - answer is in lower case in $distro

Distro=$(lsb_release -c | awk -F" " '/^Codename/ {print $2}')

printf "\033[2J\033[;H"
task_start "${BIRed}!! IMPORTANT !!\r\n\r\nDO NOT USE THIS SCRIPT. SUPERCEDED. First time? ONLY hit y(es) if this is a REAL pi OR you have already added in user Pi\r\nand given them SUDO permissions - otherwise hit h(elp)" ""
if [ $stopit -eq 1 ]; then
	printf "${BIYellow}For non-Pi boards (which may or may not work) you should ensure that\r\n"
	printf "you have resized the SD if necessary to make full use of your SD\r\n"
	printf "and that you have used the following commands AS ROOT:\r\n\r\n${IGreen}"
	printf "1. adduser pi\r\n"
	printf "2. usermod pi -g sudo   # that makes user Pi part of the sudo group\r\n"
	printf "3. echo \"pi ALL=(ALL) NOPASSWD: ALL\" > /etc/sudoers.d/pi\r\n"
	printf "4. chmod 0440 /etc/sudoers.d/pi\r\n\r\n${IYellow}"
	printf "When complete - reboot, log in as user PI and run the script i.e.  ./script.sh\r\n"
	printf "${IWhite}\r\n\r\n"
	task_end
	exit
fi

nohelp=1

printf "${BIYellow}To minimise input later on, enter a general admin username and password here:\r\n\r\n"
user_input generaluser "Enter general user (admin for example)"
user_input generalpass "Enter general password" "hide"

 
task_start "If this is a genuine Pi hit Y(es) otherwise hit o(ther) for OTHER board" "Ok"
if [ $other -eq 1 ]; then
	printf "${ICyan}\r\nContinuing, assuming this is NOT a genuine Raspberry Pi$\r\nAdding PI user to various groups for you{IWhite}\r\n"
	sudo adduser pi sudo
	sudo adduser pi adm
	sudo adduser pi dialout
	sudo adduser pi cdrom
	sudo adduser pi audio
	sudo adduser pi video
	sudo adduser pi plugdev
	sudo adduser pi games
	sudo adduser pi users
	sudo adduser pi netdev
	sudo adduser pi input
	else
	printf "${IBlue}\r\nContinuing, assuming this IS a genuine Raspberry Pi${IWhite}\r\n"
	task_end
fi  
 
hideother=1

task_start "Install General Upgrade and Prerequisites?" "UPDATING/UPGRADING  -  then enabling PING and SAMBA (to access the hostname externally - and ping fix etc)"
if [ $skip -eq 0 ]; then
	sudo apt-get -qq  update
	sudo apt-get -qq -y upgrade
	# fix for RPI treating PING as a root function - by Dave
	sudo setcap cap_net_raw=ep /bin/ping
	sudo setcap cap_net_raw=ep /bin/ping6
    sudo apt-get install -y jed
	# If experimenting on another computer and you want to create user PI (which you should to use this script)....
	# you'll need to add  them to groups
	# sudo adduser pi
	# sudo passwd pi  

	# for non PI systems
	# sudo visudo
	#     and in there - you want to mod sudo user to the following....
	#     %sudo   ALL=(ALL:ALL) NOPASSWD: ALL
	#     Save that - the constant password checking goes away
	#
	# sudo nano /etc/hosts  - change 127.0.0.1 entry
	# sudo nano /etc/hostname - only one entry in there - change
	# sudo /etc/init.d/hostname.sh
	# sudo reboot
	 
	 
	# Prerequisite suggested by Julian and adding in python-dev - and stuff I've added for SAMBA and telnet
	sudo apt-get install -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
	# libboost-thread-dev libboost-all-dev
    # This line to ensure name is resolved from hosts FIRST
    sudo sed -i '/\[global\]/a name resolve order = hosts wins bcast' /etc/samba/smb.conf
	task_end
fi
 
task_start "Install Mosquitto?" "Loading Mosquitto (and clients) and setting up user"
if [ $skip -eq 0 ]; then
	# installation of Mosquitto/w/Websockets
	cd
	wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key -O - | sudo apt-key add -
	echo "deb http://repo.mosquitto.org/debian jessie main" |sudo tee /etc/apt/sources.list.d/mosquitto-jessie.list
	sudo apt-get -qq -y update && sudo apt-get -qq -y install mosquitto mosquitto-clients
	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"
	sudo touch /etc/mosquitto/passwords
	sudo mosquitto_passwd  -b /etc/mosquitto/passwords $generaluser $generalpass
	task_end
fi

# Moved sqlite3 so that node-red sql node will install
# use back facing quotes in here - no idea why.
# Changed the order of installation of Apache etc to solve issues with ARMBIAN
#
task_start "Install Apache Installation with PHP and SQLITE and PHPLITEADMIN?" "Installing Apache and PHP and SQLITE and PHPLITEADMIN..."
if [ $skip -eq 0 ]; then
	cd
	sudo groupadd -f -g33 www-data
	sudo apt-get -qq --yes -o=Dpkg::Use-Pty=0 --force-yes install apache2 php5 libapache2-mod-php5
	cd /var/www/html
	sudo mkdir phpliteadmin
	cd phpliteadmin
	sudo wget --no-verbose https://bitbucket.org/phpliteadmin/public/downloads/phpLiteAdmin_v1-9-7-1.zip
	sudo unzip phpLiteAdmin_v1-9-7-1.zip
	sudo mv phpliteadmin.php index.php
	sudo mv phpliteadmin.config.sample.php phpliteadmin.config.php
	sudo rm *.zip
	sudo mkdir themes
	cd themes
	sudo wget --no-verbose https://bitbucket.org/phpliteadmin/public/downloads/phpliteadmin_themes_2013-12-26.zip
	sudo unzip phpliteadmin_themes_2013-12-26.zip
	sudo rm *.zip
	sudo sed -i -e 's#\$directory = \x27.\x27;#\$directory = \x27/home/pi/dbs/\x27;#g' /var/www/html/phpliteadmin/phpliteadmin.config.php
	sudo sed -i -e "s#\$password = \x27admin\x27;#\$password = \x27$generalpass\x27;#g" /var/www/html/phpliteadmin/phpliteadmin.config.php
	sudo sed -i -e "s#\$subdirectories = false;#\$subdirectories = true;#g" /var/www/html/phpliteadmin/phpliteadmin.config.php
	cd
	sudo apt-get -qq install -y sqlite3 php5-sqlite
	mkdir dbs
	sqlite3 /home/pi/dbs/iot.db << EOF
	CREATE TABLE IF NOT EXISTS \`pinDescription\` (
	  \`pinID\` INTEGER PRIMARY KEY NOT NULL,
	  \`pinNumber\` varchar(2) NOT NULL,
	  \`pinDescription\` varchar(255) NOT NULL
	);
	CREATE TABLE IF NOT EXISTS \`pinDirection\` (
	  \`pinID\` INTEGER PRIMARY KEY NOT NULL,
	  \`pinNumber\` varchar(2) NOT NULL,
	  \`pinDirection\` varchar(3) NOT NULL
	);
	CREATE TABLE IF NOT EXISTS \`pinStatus\` (
	  \`pinID\` INTEGER PRIMARY KEY NOT NULL,
	  \`pinNumber\` varchar(2)  NOT NULL,
	  \`pinStatus\` varchar(1) NOT NULL
	);
	CREATE TABLE IF NOT EXISTS \`users\` (
	  \`userID\` INTEGER PRIMARY KEY NOT NULL,
	  \`username\` varchar(28) NOT NULL,
	  \`password\` varchar(64) NOT NULL,
	  \`salt\` varchar(8) NOT NULL
	);
	CREATE TABLE IF NOT EXISTS \`device_list\` (
	  \`device_name\` varchar(80) NOT NULL DEFAULT '',
	  \`device_description\` varchar(80) DEFAULT NULL,
	  \`device_attribute\` varchar(80) DEFAULT NULL,
	  \`logins\` int(11) DEFAULT NULL,
	  \`creation_date\` datetime DEFAULT NULL,
	  \`last_update\` datetime DEFAULT NULL,
	  PRIMARY KEY (\`device_name\`)
	);

	CREATE TABLE IF NOT EXISTS \`readings\` (
	  \`recnum\` INTEGER PRIMARY KEY, 
	  \`location\` varchar(20), 
	  \`value\` int(11) NOT NULL, 
	  \`logged\` timestamp not NULL DEFAULT CURRENT_TIMESTAMP , 
	  \`device_name\` varchar(40) not null, 
	  \`topic\` varchar(40) not null
	);


	CREATE TABLE IF NOT EXISTS \`pins\` (
	  \`gpio0\` int(11) NOT NULL DEFAULT '0',
	  \`gpio1\` int(11) NOT NULL DEFAULT '0',
	  \`gpio2\` int(11) NOT NULL DEFAULT '0',
	  \`gpio3\` int(11) NOT NULL DEFAULT '0'
	);
	INSERT INTO PINS VALUES(0,0,0,0);
	CREATE TABLE IF NOT EXISTS \`temperature_record\` (
	  \`device_name\` varchar(64) NOT NULL,
	  \`rec_num\` INTEGER PRIMARY KEY,
	  \`temperature\` float NOT NULL,
	  \`date_time\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
	);
	CREATE TABLE IF NOT EXISTS \`Device\` (
	  \`DeviceID\` INTEGER PRIMARY KEY,
	  \`DeviceName\` TEXT NOT NULL
	);
	CREATE TABLE IF NOT EXISTS \`DeviceData\` ( 
	  \`DataID\` INTEGER PRIMARY KEY, 
	DeviceID INTEGER,
	  \`DataName\` TEXT, FOREIGN KEY(DeviceID ) REFERENCES Device(DeviceID) 
	);
	CREATE TABLE IF NOT EXISTS \`Data\` ( 
	SequenceID INTEGER PRIMARY KEY,
	  \`DeviceID\` INTEGER NOT NULL,
	  \`DataID\` INTEGER NOT NULL,
	  \`DataValue\` NUMERIC NOT NULL, 
	  \`epoch\` NUMERIC NOT NULL, 
	  \`timestamp\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP , FOREIGN KEY(DataID, DeviceID ) REFERENCES DeviceData(DAtaID, DeviceID ) 
	);
	.exit
EOF
	 
	cd
	chmod 777 /home/pi/dbs
	chmod 666 /home/pi/dbs/iot.db
	cd
	task_end
fi


task_start "Install NODEJS?" "Installing NODEJS"
if [ $skip -eq 0 ]; then
	# ====================== Aidans Additions to install node and npm =============================
	echo " ============================ Installing NODEJS ========================================="
	curl -sL https://deb.nodesource.com/setup_4.x > nodesetup.sh
	sudo bash nodesetup.sh
	sudo apt-get -y install nodejs
	task_end
fi


# =============================================================================================
task_start "Install Node-Red?" "Installing Node-Red"
if [ $skip -eq 0 ]; then
	#sudo npm cache clean
	sudo npm -s install -g --unsafe-perm node-red
	sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service -O /lib/systemd/system/nodered.service
	sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start -O /usr/bin/node-red-start
	sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop -O /usr/bin/node-red-stop
	#sudo sed -i -e 's#=pi#=%USER#g' /lib/systemd/system/nodered.service
	sudo chmod +x /usr/bin/node-red-st*
	sudo systemctl daemon-reload
	mkdir .node-red
	cd .node-red
	npm -s install moment
	npm -s install node-red-contrib-config
	npm -s install node-red-contrib-grove
	npm -s install node-red-contrib-bigtimer
	npm -s install node-red-contrib-esplogin
	npm -s install node-red-contrib-timeout
	npm -s install node-red-node-pushbullet
	npm -s install node-red-node-openweathermap
	npm -s install node-red-node-google
	npm -s install node-red-node-sqlite
	npm -s install node-red-node-emoncms
	npm -s install node-red-node-geofence
	npm -s install node-red-contrib-ivona
	npm -s install node-red-contrib-moment
	npm -s install node-red-contrib-particle
	npm -s install node-red-contrib-web-worldmap
	npm -s install node-red-contrib-graphs
	npm -s install node-red-contrib-isonline
	npm -s install node-red-node-ping
	npm -s install node-red-node-random
	npm -s install node-red-node-smooth
	npm -s install node-red-contrib-npm
	npm -s install node-red-contrib-file-function
	npm -s install node-red-contrib-boolean-logic
	npm -s install node-red-node-arduino
	npm -s install node-red-contrib-blynk-websockets
	npm -s install node-red-dashboard
    npm -s install node-red-node-darksky
	sudo npm -s install bcryptjs

	if [ $other -eq 0 ]; then
		npm -s install node-red-node-ledborg
		npm -s install node-red-contrib-gpio
		npm -s install raspi-io
	fi

	task_end
fi

 if [ $other -eq 1 ]; then
	task_start "Install GPIO library SPECIFICALLY for the ODROID C2?" "Installing GPIO library for ODROID C2"
	if [ $skip -eq 0 ]; then
       git clone https://github.com/hardkernel/wiringPi.git
       cd wiringPi
       ./build
       sudo chmod a+s /usr/local/bin/gpio
	   task_end
	fi
fi

if [ $other -eq 1 ]; then
	task_start "Install GPIO library for H3 based machines - eg NanoPi range?" "Installing general Non-Pi GPIO library"
	if [ $skip -eq 0 ]; then
		# Install NanoPi H3 based IO library
		git clone https://github.com/zhaolei/WiringOP.git -b h3
		cd WiringOP
		chmod +x ./build
		sudo ./build
		cd
		task_end
	fi
fi
 

task_start "Install Webmin?" "Installing Webmin"
if [ $skip -eq 0 ]; then
	#cd
	#mkdir webmin
	#cd webmin
	#wget --no-verbose http://prdownloads.sourceforge.net/webadmin/webmin-1.820.tar.gz
	#sudo gunzip -q webmin-1.820.tar.gz
	#tar -xf webmin-1.820.tar
	#sudo rm *.tar
	#cd webmin-1.820
	#sudo ./setup.sh /usr/local/Webmin
	wget http://www.webmin.com/jcameron-key.asc -O - | sudo apt-key add -
	echo "deb http://download.webmin.com/download/repository sarge contrib" | sudo tee /etc/apt/sources.list.d/webmin.list > /dev/null
	sudo apt-get -qq -y update
	sudo apt-get -qq -y install webmin
	task_end
fi
 
task_start "Install MPG123?" "Installing MPG123..."
if [ $skip -eq 0 ]; then
	sudo apt-get -qq -y install mpg123
	task_end
fi
 
#
# 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!
#
if [ -f /etc/armbian-release ]; then
	task_start "Install OPI-Monitor (:8888) modified for H3 (SKIP if not using H3 processor)?" "Installing OPI-Monitor"
	if [ $skip -eq 0 ]; then
		sudo armbianmonitor -r
		task_end
	fi
fi
 

#task_start "Install Internet Time Updater for Webmin (NTPUpdate)?" "Installing NTPUpdate"
#if [ $skip -eq 0 ]; then
	#sudo apt-get -qq --yes -o=Dpkg::Use-Pty=0 --force-yes install ntpdate
	#task_end
#fi
 
 
#task_start "Install Email SMTP?" "Installing Email utils and SMTP..."
#if [ $skip -eq 0 ]; then
	#cd
	#sudo apt-get  -qq --yes -o=Dpkg::Use-Pty=0 --force-yes install mailutils ssmtp
	#task_end
#fi
 
task_start "Install SCREEN?" "Installing SCREEN"
if [ $skip -eq 0 ]; then
	cd
	sudo apt-get -y -qq install screen
	task_end
fi
 
task_start "Install Midnight Commander?" "Installing MC and MCEDIT"
if [ $skip -eq 0 ]; then
	cd
	sudo apt-get -y -qq install mc
	task_end
fi
  
task_start "Update Java?" "Silently updating Java"
if [ $skip -eq 0 ]; then
    echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
    echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
    sudo apt-get -qq update
    echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
    echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
    sudo apt-get -qq -y install oracle-java8-installer
    task_end
fi
 
task_start "Install PHPSYSINFO?" "Installing phpsysinfo"
if [ $skip -eq 0 ]; then
#	sudo apt-get -qq -y install phpsysinfo
#	sudo ln -s /usr/share/phpsysinfo /var/www/html
	cd /var/www/html
	sudo git clone https://github.com/phpsysinfo/phpsysinfo.git
	sudo cp /var/www/html/phpsysinfo/phpsysinfo.ini.new /var/www/html/phpsysinfo/phpsysinfo.ini
	task_end
fi
 
printf "${BIMagenta}Please wait... starting the Node-Red service - stopping - updating a file.\r\nThis will take several seconds\r\n${BIWhite}";

sudo service nodered start ; sleep 5 ; sudo service nodered stop
sed -i -e "s/\/\/\ os:require('os')\,/os:require('os')\,\n\tmoment:require('moment')/g" .node-red/settings.js
echo " "

# you may want to use these on a Pi or elswhere to force either a graphical or command line environment
#sudo systemctl set-default multi-user.target
#sudo systemctl set-default graphical.target

sudo systemctl enable nodered.service

# Allow remote root login and speed up SSH
sudo sed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
sudo sed -i -e 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sudo sed -i '$ a UseDNS no' /etc/ssh/sshd_config

sudo /etc/init.d/ssh restart

task_start "Update PI and ROOT passwords?" "updating passwords"
if [ $skip -eq 0 ]; then
	echo "Update your PI password"
	sudo passwd pi
	echo "Update your ROOT password"
	sudo passwd root
	task_end
fi

# Upgrade to latest NPM at your own risk
task_start "Update to latest NPM?" "Updating NPM"
if [ $skip -eq 0 ]; then
	sudo npm -s install npm@latest -g
	task_end
fi

# Add CU to enable serial VT100 mode for terminals
task_start "Add CU to enable serial VT100 mode for terminals?" "Adding CU"
if [ $skip -eq 0 ]; then
	sudo apt-get -qq -y install cu
	task_end
fi

# Drop in an index file and css for a menu page
task_start "Add index/link page and a little css?" "Adding index.html and a little css"
if [ $skip -eq 0 ]; then
	sudo wget -qq http://www.scargill.net/iot/index.html -O /var/www/html/index.html
	sudo wget -qq http://www.scargill.net/iot/reset.css -O /var/www/html/reset.css
	task_end
fi

if [ $other -eq 0 ]; then
	sudo chmod 0660 /dev/ttyAMA0
fi

if [ $other -eq 0 ]; then
	task_start "Remove WolfRam on Pi - save lots of space?" "Removing Wolfram"
	if [ $skip -eq 0 ]; then
		sudo apt-get -qq -y purge wolfram-engine
		sudo apt-get -qq -y autoremove
		task_end
	fi

	task_start "Remove LibreOffice on Pi - save lots of space?" "Removing LibreOffice"
	if [ $skip -eq 0 ]; then
		sudo apt-get -qq -y remove --purge libreoffice*
		sudo apt-get -qq -y clean
		sudo apt-get -qq -y autoremove
		task_end
	fi
fi

# Something I did wrong here meant the FriendlyArm Nanopi M1 came up with no graphical interface.  sudo apt-get-install xorg fixed that followed by xstart
printf "${BIMagenta}All done.\r\n\r\n"
printf  "${ICyan}If you wish to change the hostname - change value in /etc/hosts\r\n"
printf  "Change also value in /etc/hostname to the same\r\nthen run sudo /etc/init.d/hostname.shs\r\n\r\n"
printf  "${BIMagenta}**** PLEASE REBOOT NOW ****\r\n"
printf  "..and for more info on the home control project - https://bitbucket.org/scargill/esp-mqtt-dev/raw/master/Hackitt-and-Bodgitt-ESP.doc \r\n"

Comments (10)

  1. chartley2

    Hey Peter,

    I have some feedback after installing on a raspberry pi 3. I had to install npm using apt-get in order for the npm lines to work. Also, there is one too many zeros in the line 'tar -xf webmin-1.8010.tar'

    Thanks for the great script!

    --Chris

  2. ROBERT MORE

    Peter, just ran the script, but get this error when issuing node-red-start:

    Error loading settings file: /home/pi/.node-red/settings.js Error: Cannot find module 'moment'

    Update: The .node-red/node_modules/ folder is empty...

    Same problem with today's updated script. Empty modules folder.

  3. Michael Taylor

    I too get this problem. It seems that npm is not installed when reaching this part of the script. I have had my SD card out so many times to write the latest version that I have now broken my microusb connector and am awaiting a new PSU. I'm sure I must be doing something wrong as it would seem no one else other than you and me, is having the problem. Next step, when I get the replacement PSU, will be to run the script to just before the node-red section and then manually install npm before continuing.

  4. Michael Taylor

    Hi Peter, Thanks very much for the script revisions. Hopefully my replacement PSU will arrive tomorrow so I'll be trying the script later in the day. I have created a PCB based on the esp8266-12E on which I hope to use the firmware. The Project is on hackaday.io (Solar Powered Garden Irrigation System) https://hackaday.io/projects/hacker/132066 if you have time to take a look. Currently the new PCB design is awaiting components. Mike

  5. ROBERT MORE

    Peter, appreciate your work and effort. I have attempted several installs using the handful of scripts you have uploaded over the past day or two. No luck, same problem with incomplete installation. I posted but have received no response, yet noticed a few updates on the script and assumed a possible fix. I had success a week or so ago with the script on another machine, but it is long gone. I am done for now. Will try later, I am sure you can fix, but I need to move on to another solution for the time being.

    Thanks