Easy start script: refactor and correct option processing

easy-start-select-de-to-run
Dmitry Maksyoma 4 years ago
parent 26cc3845b0
commit 892c285963

@ -8,6 +8,8 @@ cert_group=ssl-cert
xstartup_script=~/.vnc/xstartup xstartup_script=~/.vnc/xstartup
de_was_selected_file="$HOME/.vnc/.kasmvncserver-easy-start-de-was-selected" de_was_selected_file="$HOME/.vnc/.kasmvncserver-easy-start-de-was-selected"
action=start
manual_xstartup_choice="Manually edit xstartup" manual_xstartup_choice="Manually edit xstartup"
declare -A all_desktop_environments=( declare -A all_desktop_environments=(
[Cinnamon]=cinnamon-session [Cinnamon]=cinnamon-session
@ -122,25 +124,47 @@ SCRIPT
chmod +x "$xstartup_script" chmod +x "$xstartup_script"
} }
if [[ "$1" = "--help" ]]; then enable_debug() {
debug=1
log_option="-log *:stderr:100"
}
kill_vnc_server() {
vncserver -kill $display
}
process_cli_options() {
for option in "$@"; do
case "$option" in
--help)
show_help
exit
;;
-d)
enable_debug
;;
-kill)
kill_vnc_server
exit
;;
-select-de)
action=select-de-and-start
;;
esac
done
}
show_help() {
cat >&2 <<-USAGE cat >&2 <<-USAGE
Usage: `basename $0` [options] Usage: `basename $0` [options]
-d Debug output -d Debug output
-kill Kill vncserver -kill Kill vncserver
-select-de Select desktop environent to run
--help show this help --help show this help
USAGE USAGE
exit }
fi
if [[ "$1" = "-d" ]]; then process_cli_options "$@"
debug=1
log_option="-log *:stderr:100"
fi
action=start
if [[ "$1" = "-kill" ]]; then
action=kill
fi
if groups | grep -qvw ssl-cert; then if groups | grep -qvw ssl-cert; then
cat <<-EOF cat <<-EOF
@ -150,11 +174,6 @@ EOF
exit 1 exit 1
fi fi
if [[ "$action" = "kill" ]]; then
vncserver -kill $display
exit
fi
if ! de_was_selected; then if ! de_was_selected; then
detect_desktop_environments detect_desktop_environments
ask_user_to_choose_de ask_user_to_choose_de

Loading…
Cancel
Save