Fix problems installing and updating LTS versions
[svrjs-installer-linux.git] / updater.sh
blobee88a664fe8f1cfb855ab6f4c8002baffc4d4e05
1 #!/bin/bash
3 ##Print splash
4 echo '********************************'
5 echo '**SVR.JS updater 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 update SVR.JS'
12 exit 1
15 ##Check if SVR.JS is installed
16 if ! [ -d /usr/lib/svrjs ]; then
17 echo 'SVR.JS isn'"'"'t installed (or it'"'"'s installed without using SVR.JS installer)!'
18 exit 1
21 ##Create .installer.prop file, if it doesn't exist
22 if ! [ -f /usr/lib/svrjs/.installer.prop ]; then
23 echo manual > /usr/lib/svrjs/.installer.prop;
26 ##Check the SVR.JS installation type
27 INSTALLTYPE="$(cat /usr/lib/svrjs/.installer.prop)"
28 if [ "$INSTALLTYPE" == "manual" ]; then
29 echo -n 'Path to SVR.JS zip archive: '
30 read SVRJSZIPARCHIVE
31 elif [ "$INSTALLTYPE" == "stable" ]; then
32 SVRJSOLDVERSION=""
33 SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest.svrjs)"
34 if [ "$SVRJSVERSION" == "" ]; then
35 echo 'There was a problem while determining latest SVR.JS version!'
36 exit 1
38 if [ -f /usr/lib/svrjs/.installer.version ]; then
39 SVRJSOLDVERSION="$(cat /usr/lib/svrjs/.installer.version)"
41 if [ "$SVRJSOLDVERSION" == "$SVRJSVERSION" ]; then
42 echo 'Your SVR.JS version is up to date!'
43 exit 0
45 SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
46 if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
47 echo 'There was a problem while downloading latest SVR.JS version!'
48 exit 1
50 echo "$SVRJSVERSION" > /usr/lib/svrjs/.installer.version
51 elif [ "$INSTALLTYPE" == "lts" ]; then
52 SVRJSOLDVERSION=""
53 SVRJSVERSION="$(curl -fsL https://downloads.svrjs.org/latest-lts.svrjs)"
54 if [ "$SVRJSVERSION" == "" ]; then
55 echo 'There was a problem while determining latest LTS SVR.JS version!'
56 exit 1
58 if [ -f /usr/lib/svrjs/.installer.version ]; then
59 SVRJSOLDVERSION="$(cat /usr/lib/svrjs/.installer.version)"
61 if [ "$SVRJSOLDVERSION" == "$SVRJSVERSION" ]; then
62 echo 'Your SVR.JS version is up to date!'
63 exit 0
65 SVRJSZIPARCHIVE="$(mktemp /tmp/svrjs.XXXXX.zip)"
66 if ! curl -fsSL "https://downloads.svrjs.org/svr.js.$SVRJSVERSION.zip" > $SVRJSZIPARCHIVE; then
67 echo 'There was a problem while downloading latest LTS SVR.JS version!'
68 exit 1
70 echo "$SVRJSVERSION" > /usr/lib/svrjs/.installer.version
71 else
72 echo 'There was a problem determining SVR.JS installation type!'
73 exit 1
76 ##Check if SVR.JS zip archive exists
77 if ! [ -f $SVRJSZIPARCHIVE ]; then
78 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".'
79 exit 1
82 ##Copy SVR.JS files
83 echo "Copying SVR.JS files..."
84 unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs svr.compressed modules.compressed svr.js > /dev/null
85 chown svrjs:svrjs /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js
86 chmod 775 /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js
87 unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs logviewer.js loghighlight.js > /dev/null
88 chown svrjs:svrjs /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js
89 chmod 775 /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js
90 unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs svrpasswd.js > /dev/null
91 chown svrjs:svrjs /usr/lib/svrjs/svrpasswd.js
92 chmod 775 /usr/lib/svrjs/svrpasswd.js
93 pushd .
94 cd /usr/lib/svrjs
95 node svr.js > /dev/null
96 popd
98 echo "Done! SVR.JS is updated successfully! You can now restart SVR.JS using \"/etc/init.d/svrjs restart\" or \"systemctl restart svrjs\"."