diff --git a/tools/armbian-config-dev b/tools/armbian-config-dev new file mode 100755 index 000000000..3b3c14258 --- /dev/null +++ b/tools/armbian-config-dev @@ -0,0 +1,217 @@ +#!/bin/bash + +# Prepare the module options array +declare -A module_options + +module_options+=( + ["set_checkpoint,author"]="@armbian" + ["set_checkpoint,maintainer"]="@igorpecovnik" + ["set_checkpoint,feature"]="set_checkpoint" + ["set_checkpoint,example"]="start stop show" + ["set_checkpoint,desc"]="Helper module for timing code execution" + ["set_checkpoint,status"]="Active" +) +# +# Function to manage timer with multiple checkpoints +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] [show] 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 + ;; + stop) + 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" ]; then + echo "$2: ${checkpoint_duration} seconds" + fi + ;; + show) + if [[ -n "$set_checkpoint_START" && -n "$set_checkpoint_STOP" ]]; then + set_checkpoint_DURATION=$((set_checkpoint_STOP - set_checkpoint_START)) + echo "Total elapsed time: ${set_checkpoint_DURATION} seconds" + + 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]} + echo "${description:-Checkpoint $((i+1))}: ${checkpoint_duration} seconds" + previous_time=$checkpoint_time + done + + local final_duration=$((set_checkpoint_STOP - previous_time)) + echo "Final segment: ${final_duration} seconds" + else + echo "Timer has not been started and stopped properly." + fi + ;; + *) + echo "Usage: set_checkpoint [description]" + ;; + esac +} + + +set_checkpoint start + +tput init + +set_checkpoint mark "Initializing script" true +# +# Language-based variable assignment for script directory path +# This serves as a Rosetta Stone for developers, +# allowing them to use the variable name they are most comfortable with. + +# allows CTRL c to exit +trap "exit" INT TERM +[[ $EUID != 0 ]] && exec sudo "$0" "$@" +# +# Get the script directory +script_dir="$(dirname "$0")" +set_checkpoint mark "Setting base data" true + +[[ -d "$script_dir/../tools" ]] && tools_dir="$script_dir/../tools" +[[ ! -d "$script_dir/../lib" && -n "$tools_dir" ]] && echo -e "Please run\nbash \"$tools_dir/config-assemble.sh\" to build the lib directory\n" && exit 1 + +# '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" + +# Define the lib directory one level up from the script directory +lib_dir="$script_dir/../lib/armbian-config" +doc_dir="$script_dir/../share/doc/armbian-config" +json_file="$lib_dir/config.jobs.json" + +# +# Load The Bash procedure Objects +json_data=$(<"$json_file") + + + +# +# Load configng core functions and module options array + +source "$lib_dir/config.functions.sh" + +set_runtime_variables + +set_checkpoint mark "$(check_distro_status)" true + +set_checkpoint mark "Loaded Runtime variables..." true #| show_infobox ; +#set_newt_colors 2 +set_checkpoint mark "Loaded Dialog..." true #| show_infobox ; +source "$lib_dir/config.docs.sh" + +set_checkpoint mark "Loaded Docs..." true #| show_infobox ; +source "$lib_dir/config.system.sh" + +set_checkpoint mark "Loaded System helpers..." true #| show_infobox ; +source "$lib_dir/config.network.sh" + +set_checkpoint mark "Loaded Network helpers..." true #| show_infobox ; +source "$lib_dir/config.software.sh" + +set_checkpoint mark "Loaded Software helpers..." true #| show_infobox ; +# +# Loads the variables from beta armbian-config for runtime handling + +source "$lib_dir/config.runtime.sh" +set_checkpoint mark "Loaded Runtime conditions..." true #| show_infobox ; + + + +case "$1" in +"--help") + if [[ -n "$2" ]]; then + see_cmd_list "$2" + echo "" + exit 0 + fi + + echo "Usage: armbian-config --[option] + 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) + --doc Generate the README.md file + + Examples: + armbian-config --help [cmd||System||Software||Network||Localisation] + armbian-config --cmd help + armbian-config --api help +" + exit 0 + ;; +"--doc") + generate_readme + exit 0 + ;; +"--cmd") + INPUTMODE="cmd" + shift + if [[ -z "$1" || "$1" == "help" ]]; then + see_cmd_list + exit 0 + fi + + args=$(sanitize_input "$@") + execute_command "$args" + exit 0 + ;; +"--api") + shift + if [[ -z "$1" || "$1" == "help" ]]; then + see_use + exit 0 + fi + option="$1" + shift + # echo -e "\"$option\" \"$args\"" + "$option" "$@" + exit 0 + ;; +*) + if [[ $EUID != 0 ]]; then + echo -e "error: Exiting \nTry: 'sudo armbian-config'\n or: 'armbian-config --help' for More info\n\n" + exit 0 + fi + ;; +esac + + + +# +# Generate the top menu with the modified Object data +set_colors 4 + +generate_top_menu "$json_data" + + +set_checkpoint stop + + +# +# Exit the script with a success status code + +# +# Show about this tool on exit +about_armbian_configng + +exit 0 \ No newline at end of file