-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-node-red.sh
More file actions
137 lines (122 loc) · 4.77 KB
/
install-node-red.sh
File metadata and controls
137 lines (122 loc) · 4.77 KB
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
#!/bin/bash
#
# This script is based on instructions posted here:
# http://nodered.org/docs/hardware/raspberrypi.html
#
## INFO:
# This script provides routine commands to install and configure
# a default installation of node red in your Raspberry Pi.
#
## ASSUMPTIONS
# I am assuming you have raspbian >=3.18.11-v7,
# when you issue the command "uname -r" you get
# '3.18.11-v7' or greater
# This script will work with an installation via NOOBS => 1.4.1
#
## LIMITATIONS
# + This script will only work for Raspberry Pi v2
# + This is intended as an initial setup. There are important security flaws:
# + The /etc/init.d/node-red file is using the root user making it insecure
# for production.
# + Node-RED runs with a garbage collection size of 128, can be optimized as 64
# + This script was tested with a clean install of raspbian NOOBS
SUDO=''
NC='\033[0m' # No Color
RED='\033[0;31m'
GREEN='\033[0;32m'
if (( $EUID != 0 )); then
SUDO='sudo'
fi
cd ~
## Install nodejs
##
if dpkg --get-selections | grep nodejs ; then
echo -e "${GREEN}NodeJS is already installed${NC}"
else
echo -e "${GREEN}Installing nodejs for raspberry pi${NC}"
{
#Prepare install
$SUDO curl -sL https://deb.nodesource.com/setup_0.12 | $SUDO bash
#Install
$SUDO apt-get install -y nodejs
} || {
echo -e "${RED}ERROR: There was a problem installing nodejs${NC}"
exit
}
fi
## You need to install GPIO dependencies (python-dev and python-rpi.gipo)
##
if dpkg --get-selections | grep python-rpi.gpio ; then
echo -e "${GREEN}GPIO dependencies already installed${NC}"
else
{
echo -e "${GREEN}Installing GPIO Dependencies.${NC}"
$SUDO apt-get install -y --force-yes -y build-essential python-dev python-rpi.gpio nodejs
} || { #catch block
echo -e "${RED}ERROR: There was a problem installing GPIO dependencies${NC}"
exit
}
fi
## Download and install NodeRED via NPM
##
#DIR='/usr/lib/node_modules/node-red'
NODEREDBIN="$(which node-red)"
if [ -a "$NODEREDBIN" ]; then
echo -e "${GREEN}It seems like node-red is already installed. If you want a new installation remove node-red with `npm uninstall -g node-red` "
else
echo -e "${GREEN}Downloading, compiling and installing node-red${NC}"
{
$SUDO npm cache clean
$SUDO npm install -g --unsafe-perm node-red
} || {
echo -e "${RED}ERROR: there was a problem installing node-red${NC}"
exit
}
fi
## Install Interesting Nodes.
echo -e "${GREEN}Downloading, compiling and installing complimentary nodes${NC}"
{
$SUDO npm install -g --unsafe-perm \
node-red-contrib-wotkit \
node-red-node-web-nodes \
node-red-node-pushbullet \
node-red-node-wordpos \
node-red-node-xmpp \
node-red-node-badwords \
node-red-node-suncalc \
node-red-node-smooth \
node-red-node-ping \
node-red-contrib-moment \
node-red-node-fitbit \
node-red-contrib-slack \
node-red-node-dweetio \
node-red-node-rbe
$SUDO npm cache clean
} || {
echo -e "${RED}ERROR: there was a problem installing node-red${NC}"
exit
}
## Finally, set up node red to run on boot
##
NODEREDBIN="$(which node-red)"
PM2BIN="$(which pm2)"
echo -e "${GREEN}Configuring to start nodered at boot via $NODEREDBIN ${NC}"
{
echo 'Installing pm2'
$SUDO npm install -g --unsafe-perm pm2
echo 'Deleting previous configurations and starting service'
$SUDO pm2 delete node-red
$SUDO pm2 start $NODEREDBIN --node-args="--max-old-space-size=128" -- -v
echo 'Configuring for startup'
$SUDO pm2 save
$SUDO pm2 startup
} || {
echo -e "${RED}ERROR: there was a problem configuring start on boot${NC}"
exit
}
HOSTNAMEIP="$(hosname -I)"
echo -e "${GREEN}Yay! You have node-red up and running.${NC}"
echo -e "${GREEN}Visit http://$HOSTNAMEIP:1880/ to begin noding in awe.${NC}"
echo -e "${GREEN}You can use the following nodes to test your configuration.${NC}"
echo ' '
echo '[{"id":"2462d9f5.db9d26","type":"function","name":"Toggle 0/1 on input","func":"\ncontext.state = context.state || 0;\n\n(context.state == 0) ? context.state = 1 : context.state = 0;\nmsg.payload = context.state;\n\nreturn msg;","outputs":1,"x":362,"y":76,"z":"2fd1a8b8.d02e58","wires":[["f7fad3c0.08053"]]},{"id":"47794a9.fb886b4","type":"debug","name":"","active":true,"x":341,"y":146.00002098083496,"z":"2fd1a8b8.d02e58","wires":[]},{"id":"bc3c8444.43c378","type":"inject","name":"tick every 3 secs","topic":"","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"x":160,"y":76.00002098083496,"z":"2fd1a8b8.d02e58","wires":[["2462d9f5.db9d26"]]},{"id":"f7fad3c0.08053","type":"rpi-gpio out","name":"","pin":"12","set":false,"out":"out","x":533.8333740234375,"y":75.83333396911621,"z":"2fd1a8b8.d02e58","wires":[]},{"id":"8035245c.7fcad8","type":"rpi-gpio in","name":"","pin":"16","intype":"tri","read":true,"x":182,"y":145.8333339691162,"z":"2fd1a8b8.d02e58","wires":[["47794a9.fb886b4"]]}]'