/
postinst
executable file
·117 lines (91 loc) · 3.16 KB
/
postinst
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
#!/bin/sh
#
# see: dh_installdeb(1)
set -e
package="bb-node-red-installer"
service="nodered"
pkg_user="node-red"
pkg_data_dir="/var/lib/node-red"
# Create node-red user with home in /var/lib
echo "Creating/updating ${pkg_user} user account..."
adduser --system --home /var/lib/node-red --gecos "${pkg_user} user" --shell /bin/sh \
--quiet --disabled-password --group ${pkg_user} || {
echo "Proceeding with existing ${pkg_user} user..."
}
# Give node_red_user ownership of node_red_data_dir
chown ${pkg_user} ${pkg_data_dir}
groupadd gpio --system || true
echo "Updating ${pkg_user} user to group gpio"
usermod -a -G gpio ${pkg_user}
echo "Updating ${pkg_user} user to group dialout"
usermod -a -G dialout ${pkg_user}
main_install () {
if [ -d /etc/avahi/services/ ] ; then
#Annouce http server via DNS Sevice Discovery
wfile="/etc/avahi/services/nodered.service"
echo "<?xml version=\"1.0\" standalone='no'?><!--*-nxml-*-->" > ${wfile}
echo "<!DOCTYPE service-group SYSTEM \"avahi-service.dtd\">" >> ${wfile}
echo "" >> ${wfile}
echo "<!-- See avahi.service(5) for more information about this configuration file -->" >> ${wfile}
echo "" >> ${wfile}
echo "<service-group>" >> ${wfile}
echo "" >> ${wfile}
echo " <name replace-wildcards=\"yes\">Node-RED for %h</name>" >> ${wfile}
echo " <service>" >> ${wfile}
echo "" >> ${wfile}
echo " <type>_http._tcp</type>" >> ${wfile}
echo " <port>1880</port>" >> ${wfile}
echo " </service>" >> ${wfile}
echo "" >> ${wfile}
echo "</service-group>" >> ${wfile}
chown -R root:root ${wfile}
fi
systemctl enable ${service}.socket || true
systemctl start ${service} || true
echo "${package}:Installed"
}
cleanup () {
if [ -d /usr/local/lib/node_modules/node-red/ ] ; then
rm -rf /usr/local/lib/node_modules/node-red/ || true
fi
if [ -d /usr/local/lib/node_modules/node-red-contrib-blockly/ ] ; then
rm -rf /usr/local/lib/node_modules/node-red-contrib-blockly/ || true
fi
if [ -d /usr/local/lib/node_modules/node-red-contrib-gpio/ ] ; then
rm -rf /usr/local/lib/node_modules/node-red-contrib-gpio/ || true
fi
if [ -d /usr/local/lib/node_modules/node-red-contrib-mjpgcamera/ ] ; then
rm -rf /usr/local/lib/node_modules/node-red-contrib-mjpgcamera/ || true
fi
if [ -d /usr/local/lib/node_modules/node-red-contrib-particle/ ] ; then
rm -rf /usr/local/lib/node_modules/node-red-contrib-particle/ || true
fi
if [ -d /usr/local/lib/node_modules/node-red-dashboard/ ] ; then
rm -rf /usr/local/lib/node_modules/node-red-dashboard/ || true
fi
if [ -d /usr/local/lib/node_modules/node-red-node-serialport/ ] ; then
rm -rf /usr/local/lib/node_modules/node-red-node-serialport/ || true
fi
if [ -d /var/cache/bb-node-red-installer/ ] ; then
rm -rf /var/cache/bb-node-red-installer/ || true
fi
if [ -d /root/.node-red/ ] ; then
rm -rf /root/.node-red/ || true
fi
}
case "$1" in
configure)
main_install
cleanup
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0