Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Tearran committed Feb 6, 2025
1 parent 7056fa8 commit 9ed2c23
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 60 deletions.
51 changes: 26 additions & 25 deletions bin/armbian-config
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#!/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
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"

Expand All @@ -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")
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tools/armbian-config-dev
18 changes: 18 additions & 0 deletions tools/development/dev_message.sh
Original file line number Diff line number Diff line change
@@ -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
70 changes: 35 additions & 35 deletions tools/modules/initialize/message_checkpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,52 @@ module_options+=(
function set_checkpoint() {
case "$1" in
help)
echo "Usage: set_checkpoint <start|stop|mark|show> [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 <start|stop|mark|show> [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 <start|stop|mark|show> [description]"
echo "Usage: set_checkpoint <start|stop|mark|show> [description]"
;;
esac
}

0 comments on commit 9ed2c23

Please sign in to comment.