forked from ghoulmann/raspi-etherpad-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_raspi_etherpad-lite.sh
executable file
·144 lines (116 loc) · 3.34 KB
/
install_raspi_etherpad-lite.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
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
#!/bin/bash -ex
##########CONFIGURE############
#Set full path to install directory
target=/opt/etherpad-lite
port=8080 #must be above 1024
###############################
#Check for Root
ifaces=/etc/network/interfaces
LUID=$(id -u)
if [[ $LUID -ne 0 ]]; then
echo "$0 must be run as root"
exit 1
fi
install ()
{
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y \
-o DPkg::Options::=--force-confdef \
-o DPkg::Options::=--force-confold \
install $@
}
install gzip git-core curl python libssl-dev pkg-config build-essential
# install nodejs v.0.8.25 for arm, as etherpad-lite require nodejs v.0.8.x
wget https://gist.github.com/raw/3245130/v0.8.25/node-v0.8.25-linux-arm-armv6j-vfp-hard.tar.gz -O /tmp/node-v0.8.25-linux-arm-armv6j-vfp-hard.tar.gz
(cd /usr/local/ ; tar -xvzf /tmp/node-v0.8.25-linux-arm-armv6j-vfp-hard.tar.gz --strip=1)
rm -f /tmp/node-v0.8.25-linux-arm-armv6j-vfp-hard.tar.gz
#git-clone to /opt/etherpad-lite
git clone git://github.com/ether/etherpad-lite.git $target
#Create settings.json
cp $target/settings.json.template $target/settings.json
#configure etherpad
sed -i "s|9001|$port|" $target/settings.json
#Make sure dependencies are up to date
$target/bin/installDeps.sh
#useradd system user named etherpad-lite
useradd -MrU etherpad-lite
#create log directory
mkdir -p /var/log/etherpad-lite/
#permissions
chown -R etherpad-lite:etherpad-lite $target/
chown -R etherpad-lite:etherpad-lite /var/log/etherpad-lite/
#configure daemon
cat > /etc/init.d/etherpad-lite <<"EOF"
#!/bin/sh
### BEGIN INIT INFO
# Provides: etherpad-lite
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts etherpad lite
# Description: starts etherpad lite using start-stop-daemon
### END INIT INFO
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin"
LOGFILE="/var/log/etherpad-lite/etherpad-lite.log"
EPLITE_DIR="#target#"
EPLITE_BIN="bin/safeRun.sh"
USER="etherpad-lite"
GROUP="etherpad-lite"
DESC="Etherpad Lite"
NAME="etherpad-lite"
set -e
. /lib/lsb/init-functions
start() {
echo "Starting $DESC... "
start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --exec $EPLITE_DIR/$EPLITE_BIN -- $LOGFILE || true
echo "done"
}
#We need this function to ensure the whole process tree will be killed
killtree() {
local _pid=$1
local _sig=${2-TERM}
for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
killtree ${_child} ${_sig}
done
kill -${_sig} ${_pid}
}
stop() {
echo "Stopping $DESC... "
while test -d /proc/$(cat /var/run/$NAME.pid); do
killtree $(cat /var/run/$NAME.pid) 15
sleep 0.5
done
rm /var/run/$NAME.pid
echo "done"
}
status() {
status_of_proc -p /var/run/$NAME.pid "" "etherpad-lite" && exit 0 || exit $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: $NAME {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0
EOF
#specify the etherpad install directory
sed -i "s|#target#|$target|" /etc/init.d/etherpad-lite
#Make daemon file executeable
chmod +x /etc/init.d/etherpad-lite
#Configure as a service
update-rc.d etherpad-lite defaults