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

[fix] Non interactive modes ( [Bug]: sanitize_input #324 ) #326

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
69 changes: 47 additions & 22 deletions bin/armbian-config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

tput init
[[ -t 1 ]] && tput init
#
# Language-based variable assignment for script directory path
# This serves as a Rosetta Stone for developers,
Expand All @@ -14,7 +14,7 @@ trap "exit" INT TERM
script_dir="$(dirname "$0")"

[[ -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
[[ ! -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"
Expand All @@ -36,26 +36,23 @@ declare -A module_options
# Load configng core functions and module options array

source "$lib_dir/config.functions.sh"
# TODO move to runtime file
set_runtime_variables
check_distro_status
echo "Loaded Runtime variables..." #| show_infobox ;
#set_newt_colors 2
echo "Loaded Dialog..." #| show_infobox ;
#check_distro_status
#echo "Loaded Runtime variables..." #| show_infobox ;
# TODO
[[ -t 1 ]] && echo "Loaded Dialog..." #| show_infobox ;
source "$lib_dir/config.docs.sh"
echo "Loaded Docs..." #| show_infobox ;
[[ -t 1 ]] && echo "Loaded Docs..." #| show_infobox ;
source "$lib_dir/config.system.sh"
echo "Loaded System helpers..." #| show_infobox ;
[[ -t 1 ]] && echo "Loaded System helpers..." #| show_infobox ;
source "$lib_dir/config.network.sh"
echo "Loaded Network helpers..." #| show_infobox ;
[[ -t 1 ]] && echo "Loaded Network helpers..." #| show_infobox ;
source "$lib_dir/config.software.sh"
echo "Loaded Software helpers..." #| show_infobox ;
[[ -t 1 ]] && echo "Loaded Software helpers..." #| show_infobox ;
#
# Loads the variables from beta armbian-config for runtime handling

source "$lib_dir/config.runtime.sh"
echo "Loaded Runtime conditions..." #| show_infobox ;

clear

case "$1" in
"--help")
Expand All @@ -70,44 +67,67 @@ case "$1" in
--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
--doc Generate the README.md file

Examples:
armbian-config --help [cmd||System||Software||Network||Localisation]
armbian-config --cmd help
armbian-config --cmd help
armbian-config --api help
"
exit 0
;;
"--doc")
# TODO: move --doc to --api
generate_readme
exit 0
;;
"--cmd")
# TODO move source for related groups
# to respective case switch
# Interface group not sepeated and mixed in functions and docs etc..
# TODO Sort and group interface for source file
INPUTMODE="cmd"
shift
if [[ -z "$1" || "$1" == "help" ]]; then
see_cmd_list
exit 0
fi

args=$(sanitize_input "$@")
args="$@"
execute_command "$args"
exit 0
;;
"--api")
# move source for related groups
# to respective case switch
# source "$lib_dir/config.docs.sh"
# TODO remove interface spacifice function from docs into there own group files.
shift
if [[ -z "$1" || "$1" == "help" ]]; then
see_use
exit 0
fi
option="$1"
[[ "$option" == "json" ]] && generate_json_options | jq --tab '.' && exit 0 ;
[[ "$option" == "docs" ]] && generate_readme && exit 0 ;
if [[ -z "$option" || "$option" == "help" ]] ; then
echo "Options:"
echo " json - database in json format"
echo " docs - generate DOCUMEMT.md"
echo ""
exit 0 ;
fi
shift
args=$(sanitize_input "$@")
args="$@"
# echo -e "\"$option\" \"$args\""
"$option" "$args"
exit 0
;;
"--noint")
shift
option="$1"
[[ "$option" == "help" ]] && see_use ; exit 0 ;
shift
args="$@"
"$option" "$args" <&-
exit 0
;;
"main=help" | "main=Help")
see_cli_legacy
echo ""
Expand Down Expand Up @@ -156,6 +176,11 @@ case "$1" in
;;
esac

clear
echo "Almost there ..." #| show_infobox ;
echo "Checking Runtime conditions..." #| show_infobox ;
source "$lib_dir/config.runtime.sh"
echo "Loaded Runtime conditions..." #| show_infobox ;

#
# Generate the top menu with the modified Object data
Expand Down
Loading