This repository was archived by the owner on Mar 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.sh
executable file
·472 lines (447 loc) · 18.2 KB
/
installer.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
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
#!/bin/bash
##Print splash
echo '**********************************'
echo '**SVR.JS installer for GNU/Linux**'
echo '**********************************'
echo
##Check if user is root
if [ "$(id -u)" != "0" ]; then
echo 'You need to have root privileges to install SVR.JS'
exit 1
fi
##Determine the OS
OS="$(uname -s)"
if [ "$OS" == "Linux" ]; then
if [ -f /etc/redhat-release ] ; then
DISTRO=rhel
elif [ -f /etc/SuSE-release ] ; then
DISTRO=suse
elif [ -f /etc/debian_version ] ; then
DISTRO=debian
elif [ -f /etc/arch-release ] ; then
DISTRO=arch
else
DISTRO=other
fi
elif [ "$OS" == "FreeBSD" ]; then
DISTRO=freebsd
else
DISTRO=other
fi
##Define depedency installation functions
install_nodejs() {
case "$DISTRO" in
"debian") apt install nodejs;;
"rhel") yum install nodejs;;
"suse") zypper install nodejs;;
"arch") pacman -S nodejs;;
"freebsd") pkg install node;;
*) echo "You need to install Node.JS manually"
esac
}
install_unzip() {
case "$DISTRO" in
"debian") apt install unzip;;
"rhel") yum install unzip;;
"suse") zypper install unzip;;
"arch") pacman -S unzip;;
"freebsd") pkg install unzip;;
*) echo "You need to install unzip manually"
esac
}
install_setcap() {
case "$DISTRO" in
"debian") apt install libcap2-bin;;
"rhel") yum install libcap;;
"suse") zypper install libcap-progs;;
"arch") pacman -S libcap;;
"freebsd") echo "Your OS doesn't support setcap";;
*) echo "You need to install setcap manually"
esac
}
##Select SVR.JS installation type
echo 'Select your SVR.JS installation type. Valid SVR.JS installation types:'
echo '0 - Latest stable version'
echo '1 - Latest LTS version'
echo '2 - Install and update manually'
echo -n 'Your SVR.JS installation type: '
read ITP
case $ITP in
0) INSTALLTYPE=stable;;
1) INSTALLTYPE=lts;;
2) INSTALLTYPE=manual;;
*) echo 'Invalid SVR.JS installation type!'; exit 1;;
esac
if [ "$INSTALLTYPE" == "manual" ]; then
echo -n 'Path to SVR.JS zip archive: '
read SVRJSZIPARCHIVE
elif [ "$INSTALLTYPE" == "stable" ]; then
SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest.svrjs)"
if [ "$SVRJSVERSION" == "" ]; then
echo 'There was a problem while determining latest SVR.JS version!'
exit 1
fi
SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
echo 'There was a problem while downloading latest SVR.JS version!'
exit 1
fi
elif [ "$INSTALLTYPE" == "lts" ]; then
SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest-lts.svrjs)"
if [ "$SVRJSVERSION" == "" ]; then
echo 'There was a problem while determining latest LTS SVR.JS version!'
exit 1
fi
SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
echo 'There was a problem while downloading latest LTS SVR.JS version!'
exit 1
fi
else
echo 'There was a problem determining SVR.JS installation type!'
exit 1
fi
##Check if SVR.JS zip archive exists
if ! [ -f $SVRJSZIPARCHIVE ]; then
echo 'Can'"'"'t find SVR.JS archive! Make sure to download SVR.JS archive file from https://svrjs.org and rename it to "svrjs.zip".'
exit 1
fi
##Check if unzip is installed
echo "Checking for unzip..."
unziputil=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f unzip | awk '{ print $2}' | xargs)
if [ "$unziputil" == "" ]; then
install_unzip #Install unzip
fi
unziputil=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f unzip | awk '{ print $2}' | xargs)
if [ "$unziputil" == "" ]; then
echo 'Can'"'"'t locate unzip!'
exit 1
fi
##Check if Node.JS is installed
echo "Checking for Node.JS..."
nodejs=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f node | awk '{ print $2}' | xargs)
if [ "$nodejs" == "" ]; then
install_nodejs #Install Node.JS
fi
nodejs=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f node | awk '{ print $2}' | xargs)
if [ "$nodejs" == "" ]; then
echo 'Can'"'"'t locate Node.JS!'
exit 1
fi
##Check if setcap is installed
echo "Checking for setcap..."
setcapis=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f setcap | awk '{ print $2}' | xargs)
if [ "$setcapis" == "" ]; then
install_setcap #Install Node.JS
fi
setcapis=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f setcap | awk '{ print $2}' | xargs)
if [ "$setcapis" == "" ]; then
echo 'Can'"'"'t locate setcap, you need to grant networking permissions manually'
else
##Grant networking permissions to Node.JS
echo "Granting networking permissions..."
setcap cap_net_bind_service=+ep $nodejs
fi
##Copy SVR.JS files
echo "Copying SVR.JS files..."
mkdir -p /usr/lib/svrjs
echo $INSTALLTYPE > /usr/lib/svrjs/.installer.prop;
if [ "$SVRJSVERSION" != "" ]; then
echo "$SVRJSVERSION" > /usr/lib/svrjs/.installer.version
fi
unzip $SVRJSZIPARCHIVE -d /usr/lib/svrjs > /dev/null
if [ -f /usr/lib/svrjs/svr.compressed ]; then
pushd .
cd /usr/lib/svrjs
node svr.js > /dev/null
popd
fi
ln -s /usr/lib/svrjs/log /var/log/svrjs
if [ -f /usr/lib/svrjs/svrjs.yaml ]; then
ln -s /usr/lib/svrjs/svrjs.yaml /etc/svrjs.yaml
echo "global:" > /usr/lib/svrjs/svrjs.yaml
echo " wwwroot: /var/www/svrjs" >> /usr/lib/svrjs/svrjs.yaml
else
ln -s /usr/lib/svrjs/config.json /etc/svrjs-config.json
node -e 'var fs=require("fs"),config=JSON.parse(fs.readFileSync("/usr/lib/svrjs/config.json").toString());config.wwwroot="/var/www/svrjs",fs.writeFileSync("/usr/lib/svrjs/config.json",JSON.stringify(config,null,2));' > /dev/null
fi
if [ -d /usr/lib/svrjs/wwwroot ]; then
mkdir -p /var/www
mv /usr/lib/svrjs/wwwroot /var/www/svrjs
else
mkdir -p /var/www/svrjs
mv /usr/lib/svrjs/index.html /var/www/svrjs
mv /usr/lib/svrjs/tests.html /var/www/svrjs
mv /usr/lib/svrjs/licenses /var/www/svrjs
mv /usr/lib/svrjs/testdir /var/www/svrjs
mv /usr/lib/svrjs/serverSideScript.js /var/www/svrjs
mv /usr/lib/svrjs/logo.png /var/www/svrjs
mv /usr/lib/svrjs/powered.png /var/www/svrjs
mv /usr/lib/svrjs/favicon.ico /var/www/svrjs 2>/dev/null
mv /usr/lib/svrjs/views.txt /var/www/svrjs 2>/dev/null
mv /usr/lib/svrjs/hviews.txt /var/www/svrjs 2>/dev/null
fi
##Install SVR.JS utilities
echo "Installing SVR.JS utilities..."
echo '#!/bin/bash' > /tmp/svrjs-utiltemplate
echo 'PARAMETERS=$(printf "%q " "$@")' >> /tmp/svrjs-utiltemplate
echo >> /tmp/svrjs-utiltemplate
echo 'if [ "$PARAMETERS" == "'"'""'"' " ]; then' >> /tmp/svrjs-utiltemplate
echo ' PARAMETERS=""' >> /tmp/svrjs-utiltemplate
echo 'fi' >> /tmp/svrjs-utiltemplate
echo >> /tmp/svrjs-utiltemplate
echo 'cd /usr/lib/svrjs' >> /tmp/svrjs-utiltemplate
cp /tmp/svrjs-utiltemplate /usr/bin/svrjs-loghighlight
echo 'node loghighlight.js $PARAMETERS' >> /usr/bin/svrjs-loghighlight
chmod a+x /usr/bin/svrjs-loghighlight
cp /tmp/svrjs-utiltemplate /usr/bin/svrjs-logviewer
echo 'node logviewer.js $PARAMETERS' >> /usr/bin/svrjs-logviewer
chmod a+x /usr/bin/svrjs-logviewer
cp /tmp/svrjs-utiltemplate /usr/bin/svrpasswd
echo 'node svrpasswd.js $PARAMETERS' >> /usr/bin/svrpasswd
chmod a+x /usr/bin/svrpasswd
cp /tmp/svrjs-utiltemplate /usr/bin/svrjs
echo 'node svr.js $PARAMETERS' >> /usr/bin/svrjs
chmod a+x /usr/bin/svrjs
cat > /usr/bin/svrjs-updater << 'EOF'
#!/bin/bash
##Print splash
echo '********************************'
echo '**SVR.JS updater for GNU/Linux**'
echo '********************************'
echo
##Check if user is root
if [ "$(id -u)" != "0" ]; then
echo 'You need to have root privileges to update SVR.JS'
exit 1
fi
##Check if SVR.JS is installed
if ! [ -d /usr/lib/svrjs ]; then
echo 'SVR.JS isn'"'"'t installed (or it'"'"'s installed without using SVR.JS installer)!'
exit 1
fi
##Create .installer.prop file, if it doesn't exist
if ! [ -f /usr/lib/svrjs/.installer.prop ]; then
echo manual > /usr/lib/svrjs/.installer.prop;
fi
##Check the SVR.JS installation type
INSTALLTYPE="$(cat /usr/lib/svrjs/.installer.prop)"
if [ "$INSTALLTYPE" == "manual" ]; then
echo -n 'Path to SVR.JS zip archive: '
read SVRJSZIPARCHIVE
elif [ "$INSTALLTYPE" == "stable" ]; then
SVRJSOLDVERSION=""
SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest.svrjs)"
if [ "$SVRJSVERSION" == "" ]; then
echo 'There was a problem while determining latest SVR.JS version!'
exit 1
fi
if [ -f /usr/lib/svrjs/.installer.version ]; then
SVRJSOLDVERSION="$(cat /usr/lib/svrjs/.installer.version)"
fi
if [ "$SVRJSOLDVERSION" == "$SVRJSVERSION" ]; then
echo 'Your SVR.JS version is up to date!'
exit 0
fi
SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
echo 'There was a problem while downloading latest SVR.JS version!'
exit 1
fi
echo "$SVRJSVERSION" > /usr/lib/svrjs/.installer.version
elif [ "$INSTALLTYPE" == "lts" ]; then
SVRJSOLDVERSION=""
SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest-lts.svrjs)"
if [ "$SVRJSVERSION" == "" ]; then
echo 'There was a problem while determining latest LTS SVR.JS version!'
exit 1
fi
if [ -f /usr/lib/svrjs/.installer.version ]; then
SVRJSOLDVERSION="$(cat /usr/lib/svrjs/.installer.version)"
fi
if [ "$SVRJSOLDVERSION" == "$SVRJSVERSION" ]; then
echo 'Your SVR.JS version is up to date!'
exit 0
fi
SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
echo 'There was a problem while downloading latest LTS SVR.JS version!'
exit 1
fi
echo "$SVRJSVERSION" > /usr/lib/svrjs/.installer.version
else
echo 'There was a problem determining SVR.JS installation type!'
exit 1
fi
##Check if SVR.JS zip archive exists
if ! [ -f $SVRJSZIPARCHIVE ]; then
echo 'Can'"'"'t find SVR.JS archive! Make sure to download SVR.JS archive file from https://svrjs.org and rename it to "svrjs.zip".'
exit 1
fi
##Copy SVR.JS files
echo "Copying SVR.JS files..."
unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs svr.compressed modules.compressed svr.js > /dev/null 2> /dev/null
chown svrjs:svrjs /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js > /dev/null 2> /dev/null
chmod 775 /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js > /dev/null 2> /dev/null
unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs logviewer.js loghighlight.js > /dev/null 2> /dev/null
chown svrjs:svrjs /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js > /dev/null 2> /dev/null
chmod 775 /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js > /dev/null 2> /dev/null
unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs svrpasswd.js > /dev/null 2> /dev/null
chown svrjs:svrjs /usr/lib/svrjs/svrpasswd.js > /dev/null 2> /dev/null
chmod 775 /usr/lib/svrjs/svrpasswd.js > /dev/null 2> /dev/null
if [ -f /usr/lib/svrjs/svr.compressed ]; then
pushd .
cd /usr/lib/svrjs
node svr.js > /dev/null
popd
fi
echo "Done! SVR.JS is updated successfully! You can now restart SVR.JS using \"/etc/init.d/svrjs restart\" or \"systemctl restart svrjs\"."
EOF
chmod a+x /usr/bin/svrjs-updater
##Create user for running SVR.JS and assign permissions of files
echo "Creating user for running SVR.JS..."
useradd -r -d /usr/lib/svrjs svrjs
echo "Assigning SVR.JS permissions..."
chown -hR svrjs:svrjs /usr/lib/svrjs
chown -hR svrjs:svrjs /var/log/svrjs
chown -hR svrjs:svrjs /var/www/svrjs
find /usr/lib/svrjs -type d -exec chmod 755 {} \;
find /usr/lib/svrjs -type f -exec chmod 644 {} \;
find /var/log/svrjs -type d -exec chmod 755 {} \;
find /var/log/svrjs -type f -exec chmod 644 {} \;
find /var/www/svrjs -type d -exec chmod 755 {} \;
find /var/www/svrjs -type f -exec chmod 644 {} \;
##Install SVR.JS service
echo "Installing SVR.JS service..."
systemddetect=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f systemctl | awk '{ print $2}' | xargs)
if [ "$systemddetect" == "" ]; then
echo '#!/bin/bash' > /etc/init.d/svrjs
echo '### BEGIN INIT INFO' >> /etc/init.d/svrjs
echo '# Provides: svrjs' >> /etc/init.d/svrjs
echo '# Required-Start: $local_fs $remote_fs $network $syslog $named' >> /etc/init.d/svrjs
echo '# Required-Stop: $local_fs $remote_fs $network $syslog $named' >> /etc/init.d/svrjs
echo '# Default-Start: 2 3 4 5' >> /etc/init.d/svrjs
echo '# Default-Stop: 0 1 6' >> /etc/init.d/svrjs
echo '# X-Interactive: true' >> /etc/init.d/svrjs
echo '# Short-Description: SVR.JS web server' >> /etc/init.d/svrjs
echo '# Description: Start the web server' >> /etc/init.d/svrjs
echo '# This script will start the SVR.JS web server.' >> /etc/init.d/svrjs
echo '### END INIT INFO' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'server="/usr/lib/svrjs/svr.js"' >> /etc/init.d/svrjs
echo 'servicename="SVR.JS web server"' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'user="svrjs"' >> /etc/init.d/svrjs
echo 'nodejs=$(whereis -b -B $(echo $PATH | sed '"'"'s|:| |g'"'"') -f node | awk '"'"'{ print $2}'"'"' | xargs)' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'script="$(basename $0)"' >> /etc/init.d/svrjs
echo 'lockfile="/var/lock/$script"' >> /etc/init.d/svrjs
echo ' ' >> /etc/init.d/svrjs
echo '. /etc/rc.d/init.d/functions 2>/dev/null || . /etc/rc.status 2>/dev/null || . /lib/lsb/init-functions 2>/dev/null' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'ulimit -n 12000 2>/dev/null' >> /etc/init.d/svrjs
echo 'RETVAL=0' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'privilege_check()' >> /etc/init.d/svrjs
echo '{' >> /etc/init.d/svrjs
echo ' if [ "$(id -u)" != "0" ]; then' >> /etc/init.d/svrjs
echo ' echo '"'"'You need to have root privileges to manage SVR.JS service'"'" >> /etc/init.d/svrjs
echo ' exit 1' >> /etc/init.d/svrjs
echo ' fi' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'do_start()' >> /etc/init.d/svrjs
echo '{' >> /etc/init.d/svrjs
echo ' if [ ! -f "$lockfile" ] ; then' >> /etc/init.d/svrjs
echo ' echo -n $"Starting $servicename: "' >> /etc/init.d/svrjs
echo ' runuser -l "$user" -c "$nodejs $server > /dev/null &" && echo_success || echo_failure' >> /etc/init.d/svrjs
echo ' RETVAL=$?' >> /etc/init.d/svrjs
echo ' echo' >> /etc/init.d/svrjs
echo ' [ $RETVAL -eq 0 ] && touch "$lockfile"' >> /etc/init.d/svrjs
echo ' else' >> /etc/init.d/svrjs
echo ' echo "$servicename is locked."' >> /etc/init.d/svrjs
echo ' RETVAL=1' >> /etc/init.d/svrjs
echo ' fi' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'echo_failure() {' >> /etc/init.d/svrjs
echo ' echo -n "fail"' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'echo_success() {' >> /etc/init.d/svrjs
echo ' echo -n "success"' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'echo_warning() {' >> /etc/init.d/svrjs
echo ' echo -n "warning"' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'do_stop()' >> /etc/init.d/svrjs
echo '{' >> /etc/init.d/svrjs
echo ' echo -n $"Stopping $servicename: "' >> /etc/init.d/svrjs
echo ' pid=`ps -aefw | grep "$nodejs $server" | grep -v " grep " | awk '"'"'{print $2}'"'"'`' >> /etc/init.d/svrjs
echo ' kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure' >> /etc/init.d/svrjs
echo ' RETVAL=$?' >> /etc/init.d/svrjs
echo ' echo' >> /etc/init.d/svrjs
echo ' [ $RETVAL -eq 0 ] && rm -f "$lockfile"' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo ' if [ "$pid" = "" -a -f "$lockfile" ]; then' >> /etc/init.d/svrjs
echo ' rm -f "$lockfile"' >> /etc/init.d/svrjs
echo ' echo "Removed lockfile ( $lockfile )"' >> /etc/init.d/svrjs
echo ' fi' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'do_status()' >> /etc/init.d/svrjs
echo '{' >> /etc/init.d/svrjs
echo ' pid=`ps -aefw | grep "$nodejs $server" | grep -v " grep " | awk '"'"'{print $2}'"'"' | head -n 1`' >> /etc/init.d/svrjs
echo ' if [ "$pid" != "" ]; then' >> /etc/init.d/svrjs
echo ' echo "$servicename (pid $pid) is running..."' >> /etc/init.d/svrjs
echo ' else' >> /etc/init.d/svrjs
echo ' echo "$servicename is stopped"' >> /etc/init.d/svrjs
echo ' fi' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'case "$1" in' >> /etc/init.d/svrjs
echo ' start)' >> /etc/init.d/svrjs
echo ' privilege_check' >> /etc/init.d/svrjs
echo ' do_start' >> /etc/init.d/svrjs
echo ' ;;' >> /etc/init.d/svrjs
echo ' stop)' >> /etc/init.d/svrjs
echo ' privilege_check' >> /etc/init.d/svrjs
echo ' do_stop' >> /etc/init.d/svrjs
echo ' ;;' >> /etc/init.d/svrjs
echo ' status)' >> /etc/init.d/svrjs
echo ' do_status' >> /etc/init.d/svrjs
echo ' ;;' >> /etc/init.d/svrjs
echo ' restart)' >> /etc/init.d/svrjs
echo ' privilege_check' >> /etc/init.d/svrjs
echo ' do_stop' >> /etc/init.d/svrjs
echo ' do_start' >> /etc/init.d/svrjs
echo ' RETVAL=$?' >> /etc/init.d/svrjs
echo ' ;;' >> /etc/init.d/svrjs
echo ' *)' >> /etc/init.d/svrjs
echo ' echo "Usage: $0 {start|stop|status|restart}"' >> /etc/init.d/svrjs
echo ' RETVAL=1' >> /etc/init.d/svrjs
echo 'esac' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs
echo 'exit $RETVAL' >> /etc/init.d/svrjs
chmod a+x /etc/init.d/svrjs
update-rc.d svrjs defaults
/etc/init.d/svrjs start
else
echo '[Unit]' > /etc/systemd/system/svrjs.service
echo 'Description=SVR.JS web server' >> /etc/systemd/system/svrjs.service
echo 'After=network.target' >> /etc/systemd/system/svrjs.service
echo >> /etc/systemd/system/svrjs.service
echo '[Service]' >> /etc/systemd/system/svrjs.service
echo 'Type=simple' >> /etc/systemd/system/svrjs.service
echo 'User=svrjs' >> /etc/systemd/system/svrjs.service
echo 'ExecStart=/usr/bin/env node /usr/lib/svrjs/svr.js' >> /etc/systemd/system/svrjs.service
echo 'Restart=on-failure' >> /etc/systemd/system/svrjs.service
echo >> /etc/systemd/system/svrjs.service
echo '[Install]' >> /etc/systemd/system/svrjs.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/svrjs.service
systemctl enable svrjs
systemctl start svrjs
fi
echo "Done! SVR.JS is installed successfully!"