forked from whiskerz007/proxmox_hassio_lxc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setupnodered.sh
61 lines (50 loc) · 1.57 KB
/
setupnodered.sh
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
#!/usr/bin/env bash
set -Eeuo pipefail
shopt -s expand_aliases
alias die='EXIT=$? LINE=$LINENO error_exit'
trap die ERR
function error_exit() {
trap - ERR
local DEFAULT='Unknown failure occured.'
local REASON="\e[97m${1:-$DEFAULT}\e[39m"
local FLAG="\e[91m[ERROR:LXC] \e[93m$EXIT@$LINE"
msg "$FLAG $REASON"
exit $EXIT
}
function msg() {
local TEXT="$1"
echo -e "$TEXT"
}
# Prepare container OS
msg "Setting up container OS..."
sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
locale-gen >/dev/null
apt-get -y purge openssh-{client,server} >/dev/null
apt-get autoremove >/dev/null
# Update container OS
msg "Updating container OS..."
apt-get update >/dev/null
apt-get -qqy upgrade &>/dev/null
# Install prerequisites
msg "Installing prerequisites..."
msg "-----------------"
msg "At times, there will be very low CPU activity during install"
msg "I don't know why but trust me - things are happening."
msg "-----------------"
msg "Installing Node..."
apt-get -y install node.js &>/dev/null
msg "Installing NPM..."
apt-get -y install npm &>/dev/null
msg "Installing PM2..."
npm install -g pm2 &>/dev/null # This will expose a bunch of errors. They are ignorable, as far as I can tell.
# Install Node Red
msg "Installing Node Red..."
npm install -g --unsafe-perm node-red &>/dev/null
# Set up PM2 to manage startup of Node Red
msg "Setting up PM2..."
/usr/local/bin/pm2 start /usr/local/bin/node-red #&>/dev/null
/usr/local/bin/pm2 save #&>/dev/null
/usr/local/bin/pm2 startup #&>/dev/null
# Cleanup container
msg "Cleanup..."
rm -rf /setup.sh /var/{cache,log}/* /var/lib/apt/lists/*