From 112d1d741fd850166724a897723bb348a4c94034 Mon Sep 17 00:00:00 2001 From: JohnnyRevay <65253638+jan-revay@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:54:46 +0100 Subject: [PATCH] Ubuntu: Refactor CLI parameter handling --- UbuntuCLI/interactive_part.sh | 11 ++++------- UbuntuCLI/run_all.sh | 11 +---------- Ubuntu_22.04/interactive_part.sh | 10 ---------- run_init.sh | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/UbuntuCLI/interactive_part.sh b/UbuntuCLI/interactive_part.sh index 61bd4768a..29f659ed1 100755 --- a/UbuntuCLI/interactive_part.sh +++ b/UbuntuCLI/interactive_part.sh @@ -24,11 +24,8 @@ function interactive_part # TODO improve parameter parsing - move it to platform-independent code -if [ "$1" == "--noninteractive" ]; then - echo "Skipping interactive commands as $1 parameter was provided" -elif [ "$1" == "" ]; then - interactive_part +if [ "${NONINTERACTIVE}" == 'true' ]; then + echo 'Skipping interactive commands as --noninteractive parameter was provided' else - echo "invalid argument $1" - exit "${EXIT_INVALID_ARGUMENT}" -fi + interactive_part +fi \ No newline at end of file diff --git a/UbuntuCLI/run_all.sh b/UbuntuCLI/run_all.sh index ad97e8078..4b13d70a4 100755 --- a/UbuntuCLI/run_all.sh +++ b/UbuntuCLI/run_all.sh @@ -7,18 +7,9 @@ distro_is ubuntu distro_version_ge 22 gnome_present no -# TODO improve parameter parsing - move it to platform-independent code -if [ "$1" = "--help" ]; then - echo "usage: ./run_all.sh [--noninteractive]" - echo - # shellcheck disable=SC2016 - echo '--noninteractive skip stuff requiring user interaction (e.g. `gh auth login`)' - exit "${EXIT_SUCCESS}" -fi - -# Run stuff that requires user input first (if not turned off by `--noninteractive`) . ubuntu_specific_packages.sh . packages_install.sh +# stuff that requires user input can be turned off by `--noninteractive` CLI param . interactive_part.sh . optional_packages_install.sh . configs_install.sh diff --git a/Ubuntu_22.04/interactive_part.sh b/Ubuntu_22.04/interactive_part.sh index f333aece6..80d9707b1 100755 --- a/Ubuntu_22.04/interactive_part.sh +++ b/Ubuntu_22.04/interactive_part.sh @@ -6,14 +6,4 @@ . ../prelude.sh . ../UbuntuCLI/interactive_part.sh - -# TODO racionalize parameter handling (`--help` and invalid parameters are handled in UbuntuCLI) -# TODO -- refactor parameter handling and initialization of the NONINTERACTIVE global variable -if [ "$1" == "--noninteractive" ]; then - readonly NONINTERACTIVE='true' - echo "Ubuntu 22.04 - Skipping interactive commands as $1 parameter was provided" -elif [ "$1" == "" ]; then - echo "Ubuntu 22.04 - Executing the interactive part..." -fi - . ../CommonInitScripts/gnome_install_extensions.sh diff --git a/run_init.sh b/run_init.sh index cf585e539..380c41d3f 100755 --- a/run_init.sh +++ b/run_init.sh @@ -6,6 +6,23 @@ . prelude.sh +# TODO improve parameter parsing - move it to platform-independent code +if [ "$1" = "--help" ]; then + echo "usage: ./run_all.sh [--noninteractive]" + echo + # shellcheck disable=SC2016 + echo '--noninteractive skip stuff requiring user interaction (e.g. `gh auth login`)' + exit "${EXIT_SUCCESS}" +elif [ "$1" == "--noninteractive" ]; then + readonly NONINTERACTIVE='true' + echo 'NONINTERACTIVE=true' +elif [ "$1" == "" ]; then + echo "Interactive part of the script will be executed at the end..." +else + echo "Invalid argument $1" + exit "${EXIT_INVALID_ARGUMENT}" +fi + LOG_PATH="$(pwd)/Logs/$(date '+%Y%m%d_%H%M%S').log" readonly LOG_PATH mkdir -p "$(dirname "${LOG_PATH}")"