From 6301e5500c3a30440e5e6d634b6097401a7ee5ec Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Fri, 5 Apr 2024 15:36:36 +0200 Subject: [PATCH] Add "svrjs-updater" command --- installer.sh | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ test.sh | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 test.sh diff --git a/installer.sh b/installer.sh index 0f42516..ae71dd1 100755 --- a/installer.sh +++ b/installer.sh @@ -208,6 +208,107 @@ 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 -d /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 +chown svrjs:svrjs /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js +chmod 775 /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js +unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs logviewer.js loghighlight.js > /dev/null +chown svrjs:svrjs /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js +chmod 775 /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js +unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs svrpasswd.js > /dev/null +chown svrjs:svrjs /usr/lib/svrjs/svrpasswd.js +chmod 775 /usr/lib/svrjs/svrpasswd.js +pushd . +cd /usr/lib/svrjs +node svr.js > /dev/null +popd + +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..." diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..8fc8d63 --- /dev/null +++ b/test.sh @@ -0,0 +1,100 @@ +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 -d /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 +chown svrjs:svrjs /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js +chmod 775 /usr/lib/svrjs/svr.compressed /usr/lib/svrjs/modules.compressed /usr/lib/svrjs/svr.js +unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs logviewer.js loghighlight.js > /dev/null +chown svrjs:svrjs /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js +chmod 775 /usr/lib/svrjs/logviewer.js /usr/lib/svrjs/loghighlight.js +unzip -o $SVRJSZIPARCHIVE -d /usr/lib/svrjs svrpasswd.js > /dev/null +chown svrjs:svrjs /usr/lib/svrjs/svrpasswd.js +chmod 775 /usr/lib/svrjs/svrpasswd.js +pushd . +cd /usr/lib/svrjs +node svr.js > /dev/null +popd + +echo "Done! SVR.JS is updated successfully! You can now restart SVR.JS using \"/etc/init.d/svrjs restart\" or \"systemctl restart svrjs\"." +EOF