feat: add support for SVR.JS zip archives with "svrjs.yaml" file
[svrjs-installer-linux.git] / installer.sh
blob5b7910084c03d6017ceed125d57f3c8c94a13f00
1 #!/bin/bash
3 ##Print splash
4 echo '**********************************'
5 echo '**SVR.JS installer for GNU/Linux**'
6 echo '**********************************'
7 echo
9 ##Check if user is root
10 if [ "$(id -u)" != "0" ]; then
11 echo 'You need to have root privileges to install SVR.JS'
12 exit 1
15 ##Determine the OS
16 OS="$(uname -s)"
17 if [ "$OS" == "Linux" ]; then
18 if [ -f /etc/redhat-release ] ; then
19 DISTRO=rhel
20 elif [ -f /etc/SuSE-release ] ; then
21 DISTRO=suse
22 elif [ -f /etc/debian_version ] ; then
23 DISTRO=debian
24 elif [ -f /etc/arch-release ] ; then
25 DISTRO=arch
26 else
27 DISTRO=other
29 elif [ "$OS" == "FreeBSD" ]; then
30 DISTRO=freebsd
31 else
32 DISTRO=other
35 ##Define depedency installation functions
36 install_nodejs() {
37 case "$DISTRO" in
38 "debian") apt install nodejs;;
39 "rhel") yum install nodejs;;
40 "suse") zypper install nodejs;;
41 "arch") pacman -S nodejs;;
42 "freebsd") pkg install node;;
43 *) echo "You need to install Node.JS manually"
44 esac
47 install_unzip() {
48 case "$DISTRO" in
49 "debian") apt install unzip;;
50 "rhel") yum install unzip;;
51 "suse") zypper install unzip;;
52 "arch") pacman -S unzip;;
53 "freebsd") pkg install unzip;;
54 *) echo "You need to install unzip manually"
55 esac
58 install_setcap() {
59 case "$DISTRO" in
60 "debian") apt install libcap2-bin;;
61 "rhel") yum install libcap;;
62 "suse") zypper install libcap-progs;;
63 "arch") pacman -S libcap;;
64 "freebsd") echo "Your OS doesn't support setcap";;
65 *) echo "You need to install setcap manually"
66 esac
69 ##Select SVR.JS installation type
70 echo 'Select your SVR.JS installation type. Valid SVR.JS installation types:'
71 echo '0 - Latest stable version'
72 echo '1 - Latest LTS version'
73 echo '2 - Install and update manually'
74 echo -n 'Your SVR.JS installation type: '
75 read ITP
76 case $ITP in
77 0) INSTALLTYPE=stable;;
78 1) INSTALLTYPE=lts;;
79 2) INSTALLTYPE=manual;;
80 *) echo 'Invalid SVR.JS installation type!'; exit 1;;
81 esac
83 if [ "$INSTALLTYPE" == "manual" ]; then
84 echo -n 'Path to SVR.JS zip archive: '
85 read SVRJSZIPARCHIVE
86 elif [ "$INSTALLTYPE" == "stable" ]; then
87 SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest.svrjs)"
88 if [ "$SVRJSVERSION" == "" ]; then
89 echo 'There was a problem while determining latest SVR.JS version!'
90 exit 1
92 SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
93 if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
94 echo 'There was a problem while downloading latest SVR.JS version!'
95 exit 1
97 elif [ "$INSTALLTYPE" == "lts" ]; then
98 SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest-lts.svrjs)"
99 if [ "$SVRJSVERSION" == "" ]; then
100 echo 'There was a problem while determining latest LTS SVR.JS version!'
101 exit 1
103 SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
104 if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
105 echo 'There was a problem while downloading latest LTS SVR.JS version!'
106 exit 1
108 else
109 echo 'There was a problem determining SVR.JS installation type!'
110 exit 1
113 ##Check if SVR.JS zip archive exists
114 if ! [ -f $SVRJSZIPARCHIVE ]; then
115 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".'
116 exit 1
119 ##Check if unzip is installed
120 echo "Checking for unzip..."
121 unziputil=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f unzip | awk '{ print $2}' | xargs)
122 if [ "$unziputil" == "" ]; then
123 install_unzip #Install unzip
125 unziputil=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f unzip | awk '{ print $2}' | xargs)
126 if [ "$unziputil" == "" ]; then
127 echo 'Can'"'"'t locate unzip!'
128 exit 1
131 ##Check if Node.JS is installed
132 echo "Checking for Node.JS..."
133 nodejs=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f node | awk '{ print $2}' | xargs)
134 if [ "$nodejs" == "" ]; then
135 install_nodejs #Install Node.JS
137 nodejs=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f node | awk '{ print $2}' | xargs)
138 if [ "$nodejs" == "" ]; then
139 echo 'Can'"'"'t locate Node.JS!'
140 exit 1
143 ##Check if setcap is installed
144 echo "Checking for setcap..."
145 setcapis=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f setcap | awk '{ print $2}' | xargs)
146 if [ "$setcapis" == "" ]; then
147 install_setcap #Install Node.JS
149 setcapis=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f setcap | awk '{ print $2}' | xargs)
150 if [ "$setcapis" == "" ]; then
151 echo 'Can'"'"'t locate setcap, you need to grant networking permissions manually'
152 else
153 ##Grant networking permissions to Node.JS
154 echo "Granting networking permissions..."
155 setcap cap_net_bind_service=+ep $nodejs
158 ##Copy SVR.JS files
159 echo "Copying SVR.JS files..."
160 mkdir -p /usr/lib/svrjs
161 echo $INSTALLTYPE > /usr/lib/svrjs/.installer.prop;
162 if [ "$SVRJSVERSION" != "" ]; then
163 echo "$SVRJSVERSION" > /usr/lib/svrjs/.installer.version
165 unzip $SVRJSZIPARCHIVE -d /usr/lib/svrjs > /dev/null
166 if [ -f /usr/lib/svrjs/svr.compressed ]; then
167 pushd .
168 cd /usr/lib/svrjs
169 node svr.js > /dev/null
170 popd
172 ln -s /usr/lib/svrjs/log /var/log/svrjs
173 if [ -f /usr/lib/svrjs/svrjs.yaml ]; then
174 ln -s /usr/lib/svrjs/svrjs.yaml /etc/svrjs.yaml
175 echo "global:" > /usr/lib/svrjs/svrjs.yaml
176 echo " wwwroot: /var/www/svrjs" >> /usr/lib/svrjs/svrjs.yaml
177 else
178 ln -s /usr/lib/svrjs/config.json /etc/svrjs-config.json
179 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
181 if [ -d /usr/lib/svrjs/wwwroot ]; then
182 mkdir -p /var/www
183 mv /usr/lib/svrjs/wwwroot /var/www/svrjs
184 else
185 mkdir -p /var/www/svrjs
186 mv /usr/lib/svrjs/index.html /var/www/svrjs
187 mv /usr/lib/svrjs/tests.html /var/www/svrjs
188 mv /usr/lib/svrjs/licenses /var/www/svrjs
189 mv /usr/lib/svrjs/testdir /var/www/svrjs
190 mv /usr/lib/svrjs/serverSideScript.js /var/www/svrjs
191 mv /usr/lib/svrjs/logo.png /var/www/svrjs
192 mv /usr/lib/svrjs/powered.png /var/www/svrjs
193 mv /usr/lib/svrjs/favicon.ico /var/www/svrjs 2>/dev/null
194 mv /usr/lib/svrjs/views.txt /var/www/svrjs 2>/dev/null
195 mv /usr/lib/svrjs/hviews.txt /var/www/svrjs 2>/dev/null
198 ##Install SVR.JS utilities
199 echo "Installing SVR.JS utilities..."
200 echo '#!/bin/bash' > /tmp/svrjs-utiltemplate
201 echo 'PARAMETERS=$(printf "%q " "$@")' >> /tmp/svrjs-utiltemplate
202 echo >> /tmp/svrjs-utiltemplate
203 echo 'if [ "$PARAMETERS" == "'"'""'"' " ]; then' >> /tmp/svrjs-utiltemplate
204 echo ' PARAMETERS=""' >> /tmp/svrjs-utiltemplate
205 echo 'fi' >> /tmp/svrjs-utiltemplate
206 echo >> /tmp/svrjs-utiltemplate
207 echo 'cd /usr/lib/svrjs' >> /tmp/svrjs-utiltemplate
208 cp /tmp/svrjs-utiltemplate /usr/bin/svrjs-loghighlight
209 echo 'node loghighlight.js $PARAMETERS' >> /usr/bin/svrjs-loghighlight
210 chmod a+x /usr/bin/svrjs-loghighlight
211 cp /tmp/svrjs-utiltemplate /usr/bin/svrjs-logviewer
212 echo 'node logviewer.js $PARAMETERS' >> /usr/bin/svrjs-logviewer
213 chmod a+x /usr/bin/svrjs-logviewer
214 cp /tmp/svrjs-utiltemplate /usr/bin/svrpasswd
215 echo 'node svrpasswd.js $PARAMETERS' >> /usr/bin/svrpasswd
216 chmod a+x /usr/bin/svrpasswd
217 cp /tmp/svrjs-utiltemplate /usr/bin/svrjs
218 echo 'node svr.js $PARAMETERS' >> /usr/bin/svrjs
219 chmod a+x /usr/bin/svrjs
220 cat > /usr/bin/svrjs-updater << 'EOF'
221 #!/bin/bash
223 ##Print splash
224 echo '********************************'
225 echo '**SVR.JS updater for GNU/Linux**'
226 echo '********************************'
227 echo
229 ##Check if user is root
230 if [ "$(id -u)" != "0" ]; then
231 echo 'You need to have root privileges to update SVR.JS'
232 exit 1
235 ##Check if SVR.JS is installed
236 if ! [ -d /usr/lib/svrjs ]; then
237 echo 'SVR.JS isn'"'"'t installed (or it'"'"'s installed without using SVR.JS installer)!'
238 exit 1
241 ##Create .installer.prop file, if it doesn't exist
242 if ! [ -f /usr/lib/svrjs/.installer.prop ]; then
243 echo manual > /usr/lib/svrjs/.installer.prop;
246 ##Check the SVR.JS installation type
247 INSTALLTYPE="$(cat /usr/lib/svrjs/.installer.prop)"
248 if [ "$INSTALLTYPE" == "manual" ]; then
249 echo -n 'Path to SVR.JS zip archive: '
250 read SVRJSZIPARCHIVE
251 elif [ "$INSTALLTYPE" == "stable" ]; then
252 SVRJSOLDVERSION=""
253 SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest.svrjs)"
254 if [ "$SVRJSVERSION" == "" ]; then
255 echo 'There was a problem while determining latest SVR.JS version!'
256 exit 1
258 if [ -f /usr/lib/svrjs/.installer.version ]; then
259 SVRJSOLDVERSION="$(cat /usr/lib/svrjs/.installer.version)"
261 if [ "$SVRJSOLDVERSION" == "$SVRJSVERSION" ]; then
262 echo 'Your SVR.JS version is up to date!'
263 exit 0
265 SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
266 if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
267 echo 'There was a problem while downloading latest SVR.JS version!'
268 exit 1
270 echo "$SVRJSVERSION" > /usr/lib/svrjs/.installer.version
271 elif [ "$INSTALLTYPE" == "lts" ]; then
272 SVRJSOLDVERSION=""
273 SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest-lts.svrjs)"
274 if [ "$SVRJSVERSION" == "" ]; then
275 echo 'There was a problem while determining latest LTS SVR.JS version!'
276 exit 1
278 if [ -f /usr/lib/svrjs/.installer.version ]; then
279 SVRJSOLDVERSION="$(cat /usr/lib/svrjs/.installer.version)"
281 if [ "$SVRJSOLDVERSION" == "$SVRJSVERSION" ]; then
282 echo 'Your SVR.JS version is up to date!'
283 exit 0
285 SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
286 if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
287 echo 'There was a problem while downloading latest LTS SVR.JS version!'
288 exit 1
290 echo "$SVRJSVERSION" > /usr/lib/svrjs/.installer.version
291 else
292 echo 'There was a problem determining SVR.JS installation type!'
293 exit 1
296 ##Check if SVR.JS zip archive exists
297 if ! [ -f $SVRJSZIPARCHIVE ]; then
298 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".'
299 exit 1
302 ##Copy SVR.JS files
303 echo "Copying SVR.JS files..."
304 unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs svr.compressed modules.compressed svr.js > /dev/null 2> /dev/null
305 chown svrjs:svrjs /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js > /dev/null 2> /dev/null
306 chmod 775 /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js > /dev/null 2> /dev/null
307 unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs logviewer.js loghighlight.js > /dev/null 2> /dev/null
308 chown svrjs:svrjs /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js > /dev/null 2> /dev/null
309 chmod 775 /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js > /dev/null 2> /dev/null
310 unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs svrpasswd.js > /dev/null 2> /dev/null
311 chown svrjs:svrjs /usr/lib/svrjs/svrpasswd.js > /dev/null 2> /dev/null
312 chmod 775 /usr/lib/svrjs/svrpasswd.js > /dev/null 2> /dev/null
313 if [ -f /usr/lib/svrjs/svr.compressed ]; then
314 pushd .
315 cd /usr/lib/svrjs
316 node svr.js > /dev/null
317 popd
320 echo "Done! SVR.JS is updated successfully! You can now restart SVR.JS using \"/etc/init.d/svrjs restart\" or \"systemctl restart svrjs\"."
322 chmod a+x /usr/bin/svrjs-updater
324 ##Create user for running SVR.JS and assign permissions of files
325 echo "Creating user for running SVR.JS..."
326 useradd -r -d /usr/lib/svrjs svrjs
327 echo "Assigning SVR.JS permissions..."
328 chown -hR svrjs:svrjs /usr/lib/svrjs
329 chown -hR svrjs:svrjs /var/log/svrjs
330 chown -hR svrjs:svrjs /var/www/svrjs
331 find /usr/lib/svrjs -type d -exec chmod 755 {} \;
332 find /usr/lib/svrjs -type f -exec chmod 644 {} \;
333 find /var/log/svrjs -type d -exec chmod 755 {} \;
334 find /var/log/svrjs -type f -exec chmod 644 {} \;
335 find /var/www/svrjs -type d -exec chmod 755 {} \;
336 find /var/www/svrjs -type f -exec chmod 644 {} \;
338 ##Install SVR.JS service
339 echo "Installing SVR.JS service..."
340 systemddetect=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f systemctl | awk '{ print $2}' | xargs)
341 if [ "$systemddetect" == "" ]; then
342 echo '#!/bin/bash' > /etc/init.d/svrjs
343 echo '### BEGIN INIT INFO' >> /etc/init.d/svrjs
344 echo '# Provides: svrjs' >> /etc/init.d/svrjs
345 echo '# Required-Start: $local_fs $remote_fs $network $syslog $named' >> /etc/init.d/svrjs
346 echo '# Required-Stop: $local_fs $remote_fs $network $syslog $named' >> /etc/init.d/svrjs
347 echo '# Default-Start: 2 3 4 5' >> /etc/init.d/svrjs
348 echo '# Default-Stop: 0 1 6' >> /etc/init.d/svrjs
349 echo '# X-Interactive: true' >> /etc/init.d/svrjs
350 echo '# Short-Description: SVR.JS web server' >> /etc/init.d/svrjs
351 echo '# Description: Start the web server' >> /etc/init.d/svrjs
352 echo '# This script will start the SVR.JS web server.' >> /etc/init.d/svrjs
353 echo '### END INIT INFO' >> /etc/init.d/svrjs
354 echo >> /etc/init.d/svrjs
355 echo 'server="/usr/lib/svrjs/svr.js"' >> /etc/init.d/svrjs
356 echo 'servicename="SVR.JS web server"' >> /etc/init.d/svrjs
357 echo >> /etc/init.d/svrjs
358 echo 'user="svrjs"' >> /etc/init.d/svrjs
359 echo 'nodejs=$(whereis -b -B $(echo $PATH | sed '"'"'s|:| |g'"'"') -f node | awk '"'"'{ print $2}'"'"' | xargs)' >> /etc/init.d/svrjs
360 echo >> /etc/init.d/svrjs
361 echo 'script="$(basename $0)"' >> /etc/init.d/svrjs
362 echo 'lockfile="/var/lock/$script"' >> /etc/init.d/svrjs
363 echo ' ' >> /etc/init.d/svrjs
364 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
365 echo >> /etc/init.d/svrjs
366 echo 'ulimit -n 12000 2>/dev/null' >> /etc/init.d/svrjs
367 echo 'RETVAL=0' >> /etc/init.d/svrjs
368 echo >> /etc/init.d/svrjs
369 echo 'privilege_check()' >> /etc/init.d/svrjs
370 echo '{' >> /etc/init.d/svrjs
371 echo ' if [ "$(id -u)" != "0" ]; then' >> /etc/init.d/svrjs
372 echo ' echo '"'"'You need to have root privileges to manage SVR.JS service'"'" >> /etc/init.d/svrjs
373 echo ' exit 1' >> /etc/init.d/svrjs
374 echo ' fi' >> /etc/init.d/svrjs
375 echo '}' >> /etc/init.d/svrjs
376 echo >> /etc/init.d/svrjs
377 echo 'do_start()' >> /etc/init.d/svrjs
378 echo '{' >> /etc/init.d/svrjs
379 echo ' if [ ! -f "$lockfile" ] ; then' >> /etc/init.d/svrjs
380 echo ' echo -n $"Starting $servicename: "' >> /etc/init.d/svrjs
381 echo ' runuser -l "$user" -c "$nodejs $server > /dev/null &" && echo_success || echo_failure' >> /etc/init.d/svrjs
382 echo ' RETVAL=$?' >> /etc/init.d/svrjs
383 echo ' echo' >> /etc/init.d/svrjs
384 echo ' [ $RETVAL -eq 0 ] && touch "$lockfile"' >> /etc/init.d/svrjs
385 echo ' else' >> /etc/init.d/svrjs
386 echo ' echo "$servicename is locked."' >> /etc/init.d/svrjs
387 echo ' RETVAL=1' >> /etc/init.d/svrjs
388 echo ' fi' >> /etc/init.d/svrjs
389 echo '}' >> /etc/init.d/svrjs
390 echo >> /etc/init.d/svrjs
391 echo 'echo_failure() {' >> /etc/init.d/svrjs
392 echo ' echo -n "fail"' >> /etc/init.d/svrjs
393 echo '}' >> /etc/init.d/svrjs
394 echo >> /etc/init.d/svrjs
395 echo 'echo_success() {' >> /etc/init.d/svrjs
396 echo ' echo -n "success"' >> /etc/init.d/svrjs
397 echo '}' >> /etc/init.d/svrjs
398 echo >> /etc/init.d/svrjs
399 echo 'echo_warning() {' >> /etc/init.d/svrjs
400 echo ' echo -n "warning"' >> /etc/init.d/svrjs
401 echo '}' >> /etc/init.d/svrjs
402 echo >> /etc/init.d/svrjs
403 echo 'do_stop()' >> /etc/init.d/svrjs
404 echo '{' >> /etc/init.d/svrjs
405 echo ' echo -n $"Stopping $servicename: "' >> /etc/init.d/svrjs
406 echo ' pid=`ps -aefw | grep "$nodejs $server" | grep -v " grep " | awk '"'"'{print $2}'"'"'`' >> /etc/init.d/svrjs
407 echo ' kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure' >> /etc/init.d/svrjs
408 echo ' RETVAL=$?' >> /etc/init.d/svrjs
409 echo ' echo' >> /etc/init.d/svrjs
410 echo ' [ $RETVAL -eq 0 ] && rm -f "$lockfile"' >> /etc/init.d/svrjs
411 echo >> /etc/init.d/svrjs
412 echo ' if [ "$pid" = "" -a -f "$lockfile" ]; then' >> /etc/init.d/svrjs
413 echo ' rm -f "$lockfile"' >> /etc/init.d/svrjs
414 echo ' echo "Removed lockfile ( $lockfile )"' >> /etc/init.d/svrjs
415 echo ' fi' >> /etc/init.d/svrjs
416 echo '}' >> /etc/init.d/svrjs
417 echo >> /etc/init.d/svrjs
418 echo 'do_status()' >> /etc/init.d/svrjs
419 echo '{' >> /etc/init.d/svrjs
420 echo ' pid=`ps -aefw | grep "$nodejs $server" | grep -v " grep " | awk '"'"'{print $2}'"'"' | head -n 1`' >> /etc/init.d/svrjs
421 echo ' if [ "$pid" != "" ]; then' >> /etc/init.d/svrjs
422 echo ' echo "$servicename (pid $pid) is running..."' >> /etc/init.d/svrjs
423 echo ' else' >> /etc/init.d/svrjs
424 echo ' echo "$servicename is stopped"' >> /etc/init.d/svrjs
425 echo ' fi' >> /etc/init.d/svrjs
426 echo '}' >> /etc/init.d/svrjs
427 echo >> /etc/init.d/svrjs
428 echo 'case "$1" in' >> /etc/init.d/svrjs
429 echo ' start)' >> /etc/init.d/svrjs
430 echo ' privilege_check' >> /etc/init.d/svrjs
431 echo ' do_start' >> /etc/init.d/svrjs
432 echo ' ;;' >> /etc/init.d/svrjs
433 echo ' stop)' >> /etc/init.d/svrjs
434 echo ' privilege_check' >> /etc/init.d/svrjs
435 echo ' do_stop' >> /etc/init.d/svrjs
436 echo ' ;;' >> /etc/init.d/svrjs
437 echo ' status)' >> /etc/init.d/svrjs
438 echo ' do_status' >> /etc/init.d/svrjs
439 echo ' ;;' >> /etc/init.d/svrjs
440 echo ' restart)' >> /etc/init.d/svrjs
441 echo ' privilege_check' >> /etc/init.d/svrjs
442 echo ' do_stop' >> /etc/init.d/svrjs
443 echo ' do_start' >> /etc/init.d/svrjs
444 echo ' RETVAL=$?' >> /etc/init.d/svrjs
445 echo ' ;;' >> /etc/init.d/svrjs
446 echo ' *)' >> /etc/init.d/svrjs
447 echo ' echo "Usage: $0 {start|stop|status|restart}"' >> /etc/init.d/svrjs
448 echo ' RETVAL=1' >> /etc/init.d/svrjs
449 echo 'esac' >> /etc/init.d/svrjs
450 echo >> /etc/init.d/svrjs
451 echo 'exit $RETVAL' >> /etc/init.d/svrjs
452 chmod a+x /etc/init.d/svrjs
453 update-rc.d svrjs defaults
454 /etc/init.d/svrjs start
455 else
456 echo '[Unit]' > /etc/systemd/system/svrjs.service
457 echo 'Description=SVR.JS web server' >> /etc/systemd/system/svrjs.service
458 echo 'After=network.target' >> /etc/systemd/system/svrjs.service
459 echo >> /etc/systemd/system/svrjs.service
460 echo '[Service]' >> /etc/systemd/system/svrjs.service
461 echo 'Type=simple' >> /etc/systemd/system/svrjs.service
462 echo 'User=svrjs' >> /etc/systemd/system/svrjs.service
463 echo 'ExecStart=/usr/bin/env node /usr/lib/svrjs/svr.js' >> /etc/systemd/system/svrjs.service
464 echo 'Restart=on-failure' >> /etc/systemd/system/svrjs.service
465 echo >> /etc/systemd/system/svrjs.service
466 echo '[Install]' >> /etc/systemd/system/svrjs.service
467 echo 'WantedBy=multi-user.target' >> /etc/systemd/system/svrjs.service
468 systemctl enable svrjs
469 systemctl start svrjs
472 echo "Done! SVR.JS is installed successfully!"