Installer now uses "case" conditionals. Also updated init script.

This commit is contained in:
Dorian Niemiec 2023-09-09 23:14:47 +02:00
parent b069fcd409
commit 3aff2400a2

View file

@ -22,70 +22,48 @@ echo '4 - FreeBSD'
echo '5 - Other' echo '5 - Other'
echo -n 'Your OS type: ' echo -n 'Your OS type: '
read OSTYPE read OSTYPE
if [ "$OSTYPE" == "0" ]; then case $OSTYPE in
DISTRO=debian 0) DISTRO=debian;;
elif [ "$OSTYPE" == "1" ]; then 1) DISTRO=rhel;;
DISTRO=rhel 2) DISTRO=suse;;
elif [ "$OSTYPE" == "2" ]; then 3) DISTRO=arch;;
DISTRO=suse 4) DISTRO=freebsd;;
elif [ "$OSTYPE" == "3" ]; then 5) DISTRO=other;;
DISTRO=arch *) echo 'Invalid OS type!'; exit 1;;
elif [ "$OSTYPE" == "4" ]; then esac
DISTRO=freebsd
elif [ "$OSTYPE" == "5" ]; then
DISTRO=other
else
echo 'Invalid OS type!'
exit 1
fi
##Define depedency installation functions ##Define depedency installation functions
install_nodejs() { install_nodejs() {
if [ "$DISTRO" == "debian" ]; then case "$DISTRO" in
apt install nodejs "debian") apt install nodejs;;
elif [ "$DISTRO" == "rhel" ]; then "rhel") yum install nodejs;;
yum install nodejs "suse") zypper install nodejs;;
elif [ "$DISTRO" == "suse" ]; then "arch") pacman -S nodejs;;
zypper install nodejs14 "freebsd") pkg install node;;
elif [ "$DISTRO" == "arch" ]; then *) echo "You need to install Node.JS manually"
pacman -S nodejs esac
elif [ "$DISTRO" == "freebsd" ]; then
pkg install node
else
echo "You need to install Node.JS manually"
fi
} }
install_unzip() { install_unzip() {
if [ "$DISTRO" == "debian" ]; then case "$DISTRO" in
apt install unzip "debian") apt install unzip;;
elif [ "$DISTRO" == "rhel" ]; then "rhel") yum install unzip;;
yum install unzip "suse") zypper install unzip;;
elif [ "$DISTRO" == "suse" ]; then "arch") pacman -S unzip;;
zypper install unzip "freebsd") pkg install unzip;;
elif [ "$DISTRO" == "arch" ]; then *) echo "You need to install unzip manually"
pacman -S unzip esac
elif [ "$DISTRO" == "freebsd" ]; then
pkg install unzip
else
echo "You need to install unzip manually"
fi
} }
install_setcap() { install_setcap() {
if [ "$DISTRO" == "debian" ]; then case "$DISTRO" in
apt install libcap2-bin "debian") apt install libcap2-bin;;
elif [ "$DISTRO" == "rhel" ]; then "rhel") yum install libcap;;
yum install libcap "suse") zypper install libcap-progs;;
elif [ "$DISTRO" == "suse" ]; then "arch") pacman -S libcap;;
zypper install libcap-progs "freebsd") echo "Your OS doesn't support setcap";;
elif [ "$DISTRO" == "arch" ]; then *) echo "You need to install setcap manually"
pacman -S libcap esac
elif [ "$DISTRO" == "freebsd" ]; then
echo "Your OS doesn't support setcap"
else
echo "You need to install setcap manually"
fi
} }
##Check if svrjs.zip exists ##Check if svrjs.zip exists
@ -221,6 +199,14 @@ if [ "$systemddetect" == "" ]; then
echo 'ulimit -n 12000 2>/dev/null' >> /etc/init.d/svrjs echo 'ulimit -n 12000 2>/dev/null' >> /etc/init.d/svrjs
echo 'RETVAL=0' >> /etc/init.d/svrjs echo 'RETVAL=0' >> /etc/init.d/svrjs
echo >> /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 'do_start()' >> /etc/init.d/svrjs
echo '{' >> /etc/init.d/svrjs echo '{' >> /etc/init.d/svrjs
echo ' if [ ! -f "$lockfile" ] ; then' >> /etc/init.d/svrjs echo ' if [ ! -f "$lockfile" ] ; then' >> /etc/init.d/svrjs
@ -234,17 +220,17 @@ if [ "$systemddetect" == "" ]; then
echo ' RETVAL=1' >> /etc/init.d/svrjs echo ' RETVAL=1' >> /etc/init.d/svrjs
echo ' fi' >> /etc/init.d/svrjs echo ' fi' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs echo '}' >> /etc/init.d/svrjs
echo ' ' >> /etc/init.d/svrjs echo >> /etc/init.d/svrjs
echo 'echo_failure() {' >> /etc/init.d/svrjs echo 'echo_failure() {' >> /etc/init.d/svrjs
echo ' echo "fail"' >> /etc/init.d/svrjs echo ' echo -n "fail"' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs echo '}' >> /etc/init.d/svrjs
echo >> /etc/init.d/svrjs echo >> /etc/init.d/svrjs
echo 'echo_success() {' >> /etc/init.d/svrjs echo 'echo_success() {' >> /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 >> /etc/init.d/svrjs echo >> /etc/init.d/svrjs
echo 'echo_warning() {' >> /etc/init.d/svrjs echo 'echo_warning() {' >> /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 >> /etc/init.d/svrjs echo >> /etc/init.d/svrjs
echo 'do_stop()' >> /etc/init.d/svrjs echo 'do_stop()' >> /etc/init.d/svrjs
@ -261,7 +247,7 @@ if [ "$systemddetect" == "" ]; then
echo ' echo "Removed lockfile ( $lockfile )"' >> /etc/init.d/svrjs echo ' echo "Removed lockfile ( $lockfile )"' >> /etc/init.d/svrjs
echo ' fi' >> /etc/init.d/svrjs echo ' fi' >> /etc/init.d/svrjs
echo '}' >> /etc/init.d/svrjs echo '}' >> /etc/init.d/svrjs
echo ' ' >> /etc/init.d/svrjs echo >> /etc/init.d/svrjs
echo 'do_status()' >> /etc/init.d/svrjs echo 'do_status()' >> /etc/init.d/svrjs
echo '{' >> /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 ' pid=`ps -aefw | grep "$nodejs $server" | grep -v " grep " | awk '"'"'{print $2}'"'"' | head -n 1`' >> /etc/init.d/svrjs
@ -274,15 +260,18 @@ if [ "$systemddetect" == "" ]; then
echo >> /etc/init.d/svrjs echo >> /etc/init.d/svrjs
echo 'case "$1" in' >> /etc/init.d/svrjs echo 'case "$1" in' >> /etc/init.d/svrjs
echo ' start)' >> /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 ' do_start' >> /etc/init.d/svrjs
echo ' ;;' >> /etc/init.d/svrjs echo ' ;;' >> /etc/init.d/svrjs
echo ' stop)' >> /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 ' do_stop' >> /etc/init.d/svrjs
echo ' ;;' >> /etc/init.d/svrjs echo ' ;;' >> /etc/init.d/svrjs
echo ' status)' >> /etc/init.d/svrjs echo ' status)' >> /etc/init.d/svrjs
echo ' do_status' >> /etc/init.d/svrjs echo ' do_status' >> /etc/init.d/svrjs
echo ' ;;' >> /etc/init.d/svrjs echo ' ;;' >> /etc/init.d/svrjs
echo ' restart)' >> /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_stop' >> /etc/init.d/svrjs
echo ' do_start' >> /etc/init.d/svrjs echo ' do_start' >> /etc/init.d/svrjs
echo ' RETVAL=$?' >> /etc/init.d/svrjs echo ' RETVAL=$?' >> /etc/init.d/svrjs
@ -291,7 +280,7 @@ if [ "$systemddetect" == "" ]; then
echo ' echo "Usage: $0 {start|stop|status|restart}"' >> /etc/init.d/svrjs echo ' echo "Usage: $0 {start|stop|status|restart}"' >> /etc/init.d/svrjs
echo ' RETVAL=1' >> /etc/init.d/svrjs echo ' RETVAL=1' >> /etc/init.d/svrjs
echo 'esac' >> /etc/init.d/svrjs echo 'esac' >> /etc/init.d/svrjs
echo ' ' >> /etc/init.d/svrjs echo >> /etc/init.d/svrjs
echo 'exit $RETVAL' >> /etc/init.d/svrjs echo 'exit $RETVAL' >> /etc/init.d/svrjs
chmod a+x /etc/init.d/svrjs chmod a+x /etc/init.d/svrjs
update-rc.d svrjs defaults update-rc.d svrjs defaults