59 lines
914 B
Bash
Executable file
59 lines
914 B
Bash
Executable file
#!/usr/bin/env sh
|
|
perror() {
|
|
>&2 printf '\033[1;31mERROR:\033[0m \033[1m%s\033[0m\n' "$*"
|
|
}
|
|
|
|
error_usage() {
|
|
perror "invalid usage"
|
|
>&2 usage
|
|
|
|
exit 1
|
|
}
|
|
|
|
is_running() {
|
|
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"
|
|
exit 2
|
|
fi
|
|
}
|
|
|
|
stop() {
|
|
if is_running; then
|
|
vncserver -kill :1
|
|
else
|
|
perror "server is not running"
|
|
exit 2
|
|
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
|
|
""|status) status ;;
|
|
start) start ;;
|
|
stop) stop ;;
|
|
restart)
|
|
stop
|
|
start
|
|
;;
|
|
*)
|
|
error_usage
|
|
;;
|
|
esac
|