2024-04-04 15:26:55 +02:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
perror() {
|
|
|
|
>&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$*"
|
2023-06-11 12:46:46 +02:00
|
|
|
}
|
|
|
|
|
2024-04-06 15:12:23 +02:00
|
|
|
usage() {
|
|
|
|
name=$(basename "$0")
|
|
|
|
|
|
|
|
cat << EOF
|
|
|
|
${name}: usage
|
|
|
|
${name} [status] - show if the server is running
|
|
|
|
${name} start|stop|restart - control the server
|
|
|
|
${name} help|usage - show help
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2024-04-04 15:26:55 +02:00
|
|
|
error_usage() {
|
|
|
|
perror "invalid usage"
|
|
|
|
>&2 usage
|
2023-05-07 22:08:11 +02:00
|
|
|
|
2024-04-04 15:26:55 +02:00
|
|
|
exit 1
|
2023-05-01 00:11:01 +02:00
|
|
|
}
|
|
|
|
|
2023-06-11 12:46:46 +02:00
|
|
|
is_running() {
|
2024-04-04 15:26:55 +02:00
|
|
|
vncserver -list | grep -q '^:1'
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
if ! is_running; then
|
|
|
|
set -- vncserver \
|
|
|
|
-localhost -alwaysshared \
|
|
|
|
-securitytypes none
|
|
|
|
[ -x ~/.vnc/xstartup ] && set -- "$@" -xstartup ~/.vnc/xstartup
|
|
|
|
|
|
|
|
"$@"
|
|
|
|
else
|
|
|
|
perror "server already started"
|
2024-04-04 15:39:02 +02:00
|
|
|
return 2
|
2024-04-04 15:26:55 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
if is_running; then
|
|
|
|
vncserver -kill :1
|
|
|
|
else
|
|
|
|
perror "server is not running"
|
2024-04-04 15:39:02 +02:00
|
|
|
return 2
|
2024-04-04 15:26:55 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
status() {
|
|
|
|
if is_running; then
|
|
|
|
printf '\033[1;32m*\033[0m \033[1m%s\n' "the server is running"
|
|
|
|
else
|
|
|
|
printf '\033[1;31m*\033[0m \033[1m%s\n' "the server is not running"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
2024-04-06 15:12:49 +02:00
|
|
|
""|stat*) status ;;
|
|
|
|
star*) start ;;
|
|
|
|
sto*) stop ;;
|
|
|
|
r*)
|
2024-04-04 15:26:55 +02:00
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
error_usage
|
|
|
|
;;
|
|
|
|
esac
|