From 9ed2c23093b314985723347e38c0f368ddcaa7c3 Mon Sep 17 00:00:00 2001 From: Tearran Date: Thu, 6 Feb 2025 06:18:05 +0000 Subject: [PATCH] update --- bin/armbian-config | 51 +++++++------- tools/armbian-config-dev | 1 + tools/development/dev_message.sh | 18 +++++ .../modules/initialize/message_checkpoint.sh | 70 +++++++++---------- 4 files changed, 80 insertions(+), 60 deletions(-) create mode 120000 tools/armbian-config-dev create mode 100644 tools/development/dev_message.sh diff --git a/bin/armbian-config b/bin/armbian-config index 20ec1b157..ebcbed868 100755 --- a/bin/armbian-config +++ b/bin/armbian-config @@ -1,10 +1,11 @@ #!/bin/bash # initializes the terminal from TERM if stdin is a terminal -[[ -t 0 ]] && tput init - +unset UXMODE +[[ -t 0 && "$1" =~ ^(|--cmd|--help)$ ]] && UXMODE="true" && tput init # allows CTRL c to exit trap "exit" INT TERM + [[ $EUID != 0 ]] && exec sudo "$0" "$@" # # Get the script directory @@ -12,28 +13,27 @@ script_dir="$(dirname "$0")" declare -A module_options -# Conditional settings based on arguments -# for interactive vs non-interactive modes -if [[ "$1" == "--api" || "$1" == "--doc" ]]; then - UXMODE="false" -elif [[ -z "$1" || "$1" == "--cmd" || "$1" == "--help" ]]; then - UXMODE="true" -fi - -# Additional check for interactive vs non-interactive mode -if [[ ! -t 0 ]]; then - UXMODE="false" -fi - # Load the initialize modules source "$script_dir/../lib/armbian-config/config.initialize.sh" +# Start loading messages set_checkpoint start -set_checkpoint mark "Initializing script" true +set_checkpoint mark "Initializing script" [[ -d "$script_dir/../tools" ]] && tools_dir="$script_dir/../tools" [[ ! -d "$script_dir/../lib" && -n "$tools_dir" ]] && die -e "Please run\nbash "$tools_dir/config-assemble.sh" to build the lib directory\n" + +DEV=$([[ "$(basename "$0")" =~ .*"-dev"$ ]] && echo "true") + +# If the script name ends with "-dev", source all .sh files in the dev directory +if [[ "$DEV" == "true" ]]; then + for file in "$tools_dir/development"/*.sh; do + set_checkpoint mark "Loading development modules" + . "$file" + done +fi + # 'whiptail' is a simple dialog box utility that works well with Bash. It doesn't have all the features of some other dialog box utilities, but it does everything we need for this script. [[ -x "$(command -v whiptail)" ]] && DIALOG="whiptail" @@ -51,24 +51,25 @@ json_data=$(<"$json_file") source "$lib_dir/config.functions.sh" set_runtime_variables -set_checkpoint mark "Loaded Runtime variables..." true +set_checkpoint mark "Loaded Runtime variables..." # checks for supported os -set_checkpoint mark "$(check_distro_status)" true +set_checkpoint mark "$(check_distro_status)" -set_checkpoint mark "Loaded Dialog..." true +set_checkpoint mark "Loaded Dialog..." source "$lib_dir/config.docs.sh" -set_checkpoint mark "Loaded Docs..." true +set_checkpoint mark "Loaded Docs..." source "$lib_dir/config.system.sh" -set_checkpoint mark "Loaded System helpers..." true +set_checkpoint mark "Loaded System helpers..." source "$lib_dir/config.network.sh" -set_checkpoint mark "Loaded Network helpers..." true +set_checkpoint mark "Loaded Network helpers..." source "$lib_dir/config.software.sh" -set_checkpoint mark "Loaded Software helpers..." true +set_checkpoint mark "Loaded Software helpers..." # # Loads the variables from beta armbian-config for runtime handling source "$lib_dir/config.runtime.sh" -echo "Loaded Runtime conditions..." true +set_checkpoint mark "Loaded Runtime conditions..." +set_checkpoint stop case "$1" in "--help") @@ -77,7 +78,7 @@ case "$1" in echo "" else echo "Usage: armbian-config --[option] - Options: + Options: --help [category] Use [category] to filter specific menu options. --cmd [option] Run a command from the menu (simple) --api [option] Run a helper command (advanced) diff --git a/tools/armbian-config-dev b/tools/armbian-config-dev new file mode 120000 index 000000000..386782a6b --- /dev/null +++ b/tools/armbian-config-dev @@ -0,0 +1 @@ +../bin/armbian-config \ No newline at end of file diff --git a/tools/development/dev_message.sh b/tools/development/dev_message.sh new file mode 100644 index 000000000..92a1565f4 --- /dev/null +++ b/tools/development/dev_message.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# +dev_playground() { + # playground + set_checkpoint mark "Loading Production modules in [##########]" + sleep 0.25 + set_checkpoint mark "Loading Production modules in [####### ]" + sleep 0.25 + set_checkpoint mark "Loading Production modules in [##### ]" + sleep 0.25 + set_checkpoint mark "Loading Production modules in [## ]" + sleep 0.25 + echo "Loading Production modules " + +} + +dev_playground diff --git a/tools/modules/initialize/message_checkpoint.sh b/tools/modules/initialize/message_checkpoint.sh index a0f691729..adea909df 100644 --- a/tools/modules/initialize/message_checkpoint.sh +++ b/tools/modules/initialize/message_checkpoint.sh @@ -16,52 +16,52 @@ module_options+=( function set_checkpoint() { case "$1" in help) - echo "Usage: set_checkpoint [description] [show]" - echo "Commands:" - echo " start Start the timer." - echo " stop Stop the timer." - echo " mark [description] [time] Mark a checkpoint with an optional description and an optional flag to show the output." - echo " show Show the total elapsed time and checkpoints." + echo "Usage: set_checkpoint [description] [show]" + echo "Commands:" + echo " start Start the timer." + echo " stop Stop the timer." + echo " mark [description] [time] Mark a checkpoint with an optional description and an optional flag to show the output." + echo " show Show the total elapsed time and checkpoints." ;; start) - set_checkpoint_START=$(date +%s) - set_checkpoint_CHECKPOINTS=() - set_checkpoint_DESCRIPTIONS=() - set_checkpoint_PREV=$set_checkpoint_START + set_checkpoint_START=$(date +%s) + set_checkpoint_CHECKPOINTS=() + set_checkpoint_DESCRIPTIONS=() + set_checkpoint_PREV=$set_checkpoint_START ;; stop) - set_checkpoint_STOP=$(date +%s) + set_checkpoint_STOP=$(date +%s) ;; mark) - local checkpoint_time=$(date +%s) - local checkpoint_duration=$((checkpoint_time - set_checkpoint_PREV)) - set_checkpoint_PREV=$checkpoint_time - set_checkpoint_CHECKPOINTS+=($checkpoint_time) - set_checkpoint_DESCRIPTIONS+=("$2") - local count=${#set_checkpoint_DESCRIPTIONS[@]} - if [[ "$3" == "true" && $UXMODE == "true" ]]; then - printf "%-30s %10d seconds\n" "$2:" "${checkpoint_duration}" - fi + if [[ "$UXMODE" == "true" ]]; then + local checkpoint_time=$(date +%s) + local checkpoint_duration=$((checkpoint_time - set_checkpoint_PREV)) + set_checkpoint_PREV=$checkpoint_time + set_checkpoint_CHECKPOINTS+=($checkpoint_time) + set_checkpoint_DESCRIPTIONS+=("$2") + local count=${#set_checkpoint_DESCRIPTIONS[@]} + printf "%-30s %10d seconds\n" "$2 " "${checkpoint_duration}" + fi ;; show) - if [[ -n "$set_checkpoint_START" && -n "$set_checkpoint_STOP" ]]; then - set_checkpoint_DURATION=$((set_checkpoint_STOP - set_checkpoint_START)) - printf "%-30s: %d seconds\n" "Total elapsed time" "${set_checkpoint_DURATION}" + if [[ -n "$set_checkpoint_START" && -n "$set_checkpoint_STOP" ]]; then + set_checkpoint_DURATION=$((set_checkpoint_STOP - set_checkpoint_START)) + printf "%-30s: %d seconds\n" "Total elapsed time" "${set_checkpoint_DURATION}" - local previous_time=$set_checkpoint_START - for i in "${!set_checkpoint_CHECKPOINTS[@]}"; do - local checkpoint_time=${set_checkpoint_CHECKPOINTS[$i]} - local checkpoint_duration=$((checkpoint_time - previous_time)) - local description=${set_checkpoint_DESCRIPTIONS[$i]} - printf "%-30s: %d seconds\n" "${description:-Checkpoint $((i+1))}" "${checkpoint_duration}" - previous_time=$checkpoint_time - done - else - echo "Timer has not been started and stopped properly." - fi + local previous_time=$set_checkpoint_START + for i in "${!set_checkpoint_CHECKPOINTS[@]}"; do + local checkpoint_time=${set_checkpoint_CHECKPOINTS[$i]} + local checkpoint_duration=$((checkpoint_time - previous_time)) + local description=${set_checkpoint_DESCRIPTIONS[$i]} + printf "%-30s: %d seconds\n" "${description:-Checkpoint $((i+1))}" "${checkpoint_duration}" + previous_time=$checkpoint_time + done + else + echo "Timer has not been started and stopped properly." + fi ;; *) - echo "Usage: set_checkpoint [description]" + echo "Usage: set_checkpoint [description]" ;; esac }