Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

93 cleaning hardening applying common style testing then adding new functions #174

134 changes: 59 additions & 75 deletions bin/armbian-configng
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

tput init
clear
#
# Language-based variable assignment for script directory path
# This serves as a Rosetta Stone for developers,
Expand All @@ -13,15 +14,32 @@ trap "exit" INT TERM
script_dir="$(dirname "$0")"

# Define the lib directory one level up from the script directory
lib_dir="$script_dir/../lib/armbian-configng"
doc_dir="$script_dir/../share/doc/armbian-configng"
json_file="$lib_dir/config.ng.jobs.json"

#
# Load The Bash procedure Objects
json_data=$(<"$json_file")

#
lib_dir="$script_dir/../lib/armbian-config"
doc_dir="$script_dir/../share/doc/armbian-config"
json_file="$lib_dir/config.jobs.json"
modules_dir="$lib_dir/modules"

# Load The Bash procedure Objects
json_data=$(jq '
walk(
# Process only objects
if type == "object" then
# Check if the object has a "status" key and if "status" is "Disabled"
if has("status") and .status == "Disabled" then
empty # Exclude this object from the output
else
. # Otherwise, keep the object as it is
end
else
. # For non-object elements, leave them unchanged
end
)
' "$json_file")



# Check if help or doc otherwise run sudo -E
[[ $EUID != 0 && "$1" != "--help" && "$1" != "--doc" ]] && exec sudo -E "$0" "$@"
# '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 @@ -30,28 +48,36 @@ json_data=$(<"$json_file")
declare -A module_options

#
# Load configng core functions and module options array
# Load config core functions and module options array


source "$lib_dir/config.ng.functions.sh"

source "$lib_dir/config.core.functions.sh"
set_runtime_variables
echo "Loaded Runtime variables..." #| show_infobox ;
#set_newt_colors 2
echo "Loaded Dialog..." #| show_infobox ;
source "$lib_dir/config.ng.docs.sh"
echo "Loaded Docs..." #| show_infobox ;
source "$lib_dir/config.ng.system.sh"
echo "Loaded System helpers..." #| show_infobox ;
source "$lib_dir/config.ng.network.sh"
echo "Loaded Network helpers..." #| show_infobox ;
source "$lib_dir/config.ng.software.sh"
echo "Loaded Software helpers..." #| show_infobox ;
#
# Loads the variables from beta armbian-config for runtime handling
source "$lib_dir/config.core.runtime.sh"
# Function to source modules
source_modules() {
# Iterate over all config.*.sh files in the lib_dir
for file in "$modules_dir/"config.*.sh; do
# Check if the file exists and is a regular file
if [[ -f "$file" ]]; then
echo "Sourcing: $(basename "$file")"
source "$file"
else
echo "Warning: $(basename "$file") does not exist or is not a file."
fi
done

source "$lib_dir/config.ng.runtime.sh"
echo "Loaded Runtime conditions..." #| show_infobox ;
tput reset # Soft reset, clears screen but keeps scrollback

clear
}



# Call the function to source the modules
source_modules
# keep the scrollback
tput reset

case "$1" in
"--help")
Expand All @@ -61,17 +87,17 @@ case "$1" in
exit 0
fi

echo "Usage: armbian-configng --[option]
echo "Usage: armbian-config --[option]
Options:
--help [catagory] Use [catagory] 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-configng --help [cmd||System||Software||Network||Localisation]
armbian-configng --cmd help
armbian-configng --api help
armbian-config --help [cmd||System||Software||Network||Localisation]
armbian-config --cmd help
armbian-config --api help
"
exit 0
;;
Expand Down Expand Up @@ -118,51 +144,9 @@ case "$1" in
"$option" "$args"
exit 0
;;
"main=help" | "main=Help")
see_cli_legacy
echo ""
exit 0
;;
"main="*)
declare -A main_map
main_map=(
# map name to menu category
["System"]="S"
["Software"]="I"
["Network"]="N"
["Localisation"]="L"
)
main_value="${1#main=}"
main_value="${main_map[$main_value]}"

if [ -z "$main_value" ]; then
echo "Error: Invalid List $1"
exit 1
fi
declare -A select_map
# map name to menu number
select_map=(
["Headers"]="04"
["Headers_install"]="04"
["Headers_remove"]="05"
["Firmware"]="06"
["Nightly"]="07"
)
select_value="${2#selection=}"
select_value="${select_map[$select_value]}"
if [ -z "$select_value" ]; then
echo "Error: Invalid Option $2"
exit 1
fi
echo "$main_value""$select_value"
execute_command "$main_value""$select_value"
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

Expand Down
Loading