From 892c285963c24acd3215634bde38d9c8fa54e90e Mon Sep 17 00:00:00 2001 From: Dmitry Maksyoma Date: Wed, 21 Jul 2021 18:53:24 +1200 Subject: [PATCH] Easy start script: refactor and correct option processing --- builder/startup/deb/kasmvncserver-easy-start | 59 +++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/builder/startup/deb/kasmvncserver-easy-start b/builder/startup/deb/kasmvncserver-easy-start index 519d2cb..f0f4647 100755 --- a/builder/startup/deb/kasmvncserver-easy-start +++ b/builder/startup/deb/kasmvncserver-easy-start @@ -8,6 +8,8 @@ cert_group=ssl-cert xstartup_script=~/.vnc/xstartup de_was_selected_file="$HOME/.vnc/.kasmvncserver-easy-start-de-was-selected" +action=start + manual_xstartup_choice="Manually edit xstartup" declare -A all_desktop_environments=( [Cinnamon]=cinnamon-session @@ -122,25 +124,47 @@ 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 Usage: `basename $0` [options] - -d Debug output - -kill Kill vncserver - --help show this help + -d Debug output + -kill Kill vncserver + -select-de Select desktop environent to run + --help show this help USAGE - exit -fi +} -if [[ "$1" = "-d" ]]; then - debug=1 - log_option="-log *:stderr:100" -fi - -action=start -if [[ "$1" = "-kill" ]]; then - action=kill -fi +process_cli_options "$@" if groups | grep -qvw ssl-cert; then cat <<-EOF @@ -150,11 +174,6 @@ EOF exit 1 fi -if [[ "$action" = "kill" ]]; then - vncserver -kill $display - exit -fi - if ! de_was_selected; then detect_desktop_environments ask_user_to_choose_de