rewrite esv (2.0.0)
This commit is contained in:
parent
970cc8e411
commit
c3f4f3d81c
136
src/esv/esv
136
src/esv/esv
@ -1,77 +1,101 @@
|
||||
#!/bin/sh
|
||||
# Everest service manager
|
||||
# (C) 2022 Everest Developers
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
# esv - everest service manager
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License along with this program.
|
||||
# If not, see <https://www.gnu.org/licenses/>.
|
||||
preload() {
|
||||
. /etc/esv.conf
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "error while parsing esv config file\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
source /etc/esv.conf
|
||||
#source $(pwd)/esv.conf # for testing purposes
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
helpmsg_big() {
|
||||
printf "esv - Everest Service Manager\n"
|
||||
printf "usage: esv {action} {service-name}\n"
|
||||
printf "usage: esv [start] [stop] [restart] [-h/--help] [-v/--version] service-name\n"
|
||||
printf "\n"
|
||||
printf "esv {start} - start a service\n"
|
||||
printf "esv {stop} - stop a currently running service\n"
|
||||
printf "esv {restart} - restart a currently running service\n"
|
||||
printf "esv {-h|--help} - print this message and exit\n"
|
||||
printf "esv {-v|--version} - print the version and exit\n"
|
||||
printf "esv {start} start a service\n"
|
||||
printf "esv {stop} stop a running service\n"
|
||||
printf "esv {restart} restart a running service\n"
|
||||
printf "esv {-h/--help} print this message and exit\n"
|
||||
printf "esv {-v/--version} print the version and exit\n"
|
||||
printf "\n"
|
||||
printf "(C) 2022 Everest Developers\n"
|
||||
printf "This program is free software: you can redistribute it and/or modify it\n"
|
||||
printf "under the terms of the GNU General Public License as published by the\n"
|
||||
printf "Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n"
|
||||
printf "This program is free software.\n"
|
||||
printf "See the GNU GPL version 3 for details.\n"
|
||||
exit 0
|
||||
;;
|
||||
start)
|
||||
printf "$blue starting service $2...\n $reset"
|
||||
$SRV_DIR/$2/$RUN
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red service $2 could not start $reset \n"
|
||||
}
|
||||
|
||||
helpmsg_small() {
|
||||
printf "usage: esv [start] [stop] [restart] [-n/--help] [-v/--version] service-name\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
startsv() {
|
||||
if [ "$2" == "" ]; then
|
||||
printf "${red}you must specify a service name${reset}\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "$green service $2 started succesfully $reset \n"
|
||||
exit 0
|
||||
;;
|
||||
stop)
|
||||
printf "$blue stopping service $2...$reset \n"
|
||||
$SRV_DIR/$2/$STOP
|
||||
printf "${blue}starting service ${2}...${reset}\n"
|
||||
${SRV_DIR}/${2}/${RUN}
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red service $2 could not stop $reset \n"
|
||||
printf "${red}service ${2} could not start${reset}\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "$green service $2 stopped succesfully $reset \n"
|
||||
printf "${green}service ${2} started successfully${reset}\n"
|
||||
exit 0
|
||||
;;
|
||||
restart)
|
||||
printf "$blue restarting service $2... $reset \n"
|
||||
$SRV_DIR/$2/$STOP && $SRV_DIR/$2/$RUN
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red service $2 could not restart $reset \n"
|
||||
}
|
||||
|
||||
stopsv() {
|
||||
if [ "$?" == "" ]; then
|
||||
printf "${red}you must specify a service name${reset}\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "$green service $2 restarted successfully $reset \n"
|
||||
printf "${blue}stopping service ${2}...${reset}\n"
|
||||
${SRV_DIR}/${2}/${STOP}
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "${red}service ${2} could not stop${reset}\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "${green}service ${2} stopped successfully${reset}\n"
|
||||
exit 0
|
||||
}
|
||||
|
||||
restartsv() {
|
||||
if [ "$2" == "" ]; then
|
||||
printf "${red}you must specify a service name${reset}\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "${blue}restarting service ${2}...${reset}\n"
|
||||
${SRV_DIR}/${2}/${STOP} && ${SRV_DIR}/${2}/${RUN}
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "${red}service ${2} could not restart${reset}\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "${green}service ${2} restarted successfully${reset}\n"
|
||||
exit 0
|
||||
}
|
||||
|
||||
printver() {
|
||||
printf "${blue}esv v2.0.0${reset}\n"
|
||||
exit 0
|
||||
}
|
||||
|
||||
case $1 in
|
||||
-h|--help)
|
||||
helpmsg_big "$@"
|
||||
;;
|
||||
-v|--version)
|
||||
printf "$blue esv v1.0.1 $reset \n"
|
||||
exit 0
|
||||
printver "$@"
|
||||
;;
|
||||
start)
|
||||
startsv "$@"
|
||||
;;
|
||||
stop)
|
||||
stopsv "$@"
|
||||
;;
|
||||
restartsv)
|
||||
restartsv "$@"
|
||||
;;
|
||||
*)
|
||||
printf "$red invalid option specified, see 'esv --help' $reset \n"
|
||||
exit 1
|
||||
helpmsg_small "$@"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
printf "$red no option specified, see 'esv --help' $reset \n"
|
||||
esac
|
||||
|
77
src/esv/esv.old
Executable file
77
src/esv/esv.old
Executable file
@ -0,0 +1,77 @@
|
||||
#!/bin/sh
|
||||
# Everest service manager
|
||||
# (C) 2022 Everest Developers
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License along with this program.
|
||||
# If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
source /etc/esv.conf
|
||||
#source $(pwd)/esv.conf # for testing purposes
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
printf "esv - Everest Service Manager\n"
|
||||
printf "usage: esv {action} {service-name}\n"
|
||||
printf "\n"
|
||||
printf "esv {start} - start a service\n"
|
||||
printf "esv {stop} - stop a currently running service\n"
|
||||
printf "esv {restart} - restart a currently running service\n"
|
||||
printf "esv {-h|--help} - print this message and exit\n"
|
||||
printf "esv {-v|--version} - print the version and exit\n"
|
||||
printf "\n"
|
||||
printf "(C) 2022 Everest Developers\n"
|
||||
printf "This program is free software: you can redistribute it and/or modify it\n"
|
||||
printf "under the terms of the GNU General Public License as published by the\n"
|
||||
printf "Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n"
|
||||
exit 0
|
||||
;;
|
||||
start)
|
||||
printf "$blue starting service $2...\n $reset"
|
||||
$SRV_DIR/$2/$RUN
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red service $2 could not start $reset \n"
|
||||
exit 1
|
||||
fi
|
||||
printf "$green service $2 started succesfully $reset \n"
|
||||
exit 0
|
||||
;;
|
||||
stop)
|
||||
printf "$blue stopping service $2...$reset \n"
|
||||
$SRV_DIR/$2/$STOP
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red service $2 could not stop $reset \n"
|
||||
exit 1
|
||||
fi
|
||||
printf "$green service $2 stopped succesfully $reset \n"
|
||||
exit 0
|
||||
;;
|
||||
restart)
|
||||
printf "$blue restarting service $2... $reset \n"
|
||||
$SRV_DIR/$2/$STOP && $SRV_DIR/$2/$RUN
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "$red service $2 could not restart $reset \n"
|
||||
exit 1
|
||||
fi
|
||||
printf "$green service $2 restarted successfully $reset \n"
|
||||
exit 1
|
||||
;;
|
||||
-v|--version)
|
||||
printf "$blue esv v1.0.1 $reset \n"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
printf "$red invalid option specified, see 'esv --help' $reset \n"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
printf "$red no option specified, see 'esv --help' $reset \n"
|
0
src/esv/lib/libesv
Normal file → Executable file
0
src/esv/lib/libesv
Normal file → Executable file
@ -1,12 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
chroot "$EV" /usr/bin/env -i \
|
||||
HOME=/root \
|
||||
TERM="$TERM" \
|
||||
PS1='[everest-chroot] \u:\w \$ ' \
|
||||
PATH=/usr/bin:/usr/sbin \
|
||||
/bin/bash --login
|
||||
chroot $1 /bin/sh --userspec=USER:GROUP
|
||||
if [ "$?" != "0" ]; then
|
||||
printf "\033[1;31m [ \xE2\x9C\x95 ] \033[m Could not enter chroot environment.\n" 1>&2
|
||||
printf "[ X ] Failed to change root to $1.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user