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

network configuration #60

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions bin/armbian-configng
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ case "$1" in
fi
;;
"--cli")
INPUTMODE="cli"
if [[ $EUID != 0 ]]; then
echo "Error: The --cli option requires root privileges. Please run as root or use sudo."
exit 1
Expand All @@ -82,19 +83,20 @@ case "$1" in
exit 0
;;
"--api")

if [[ $EUID != 0 ]]; then
echo "Error: The --api option requires root privileges. Please run as root or use sudo."
exit 1
fi
fi

shift
if [[ -z "$1" ]]; then
echo "Error: Missing option for --api."
if [[ -z "$1" || "$1" == "help" ]]; then
see_use;
exit 1
fi
option="$1"
shift
args=$(sanitize_input "$@")
# echo -e "\"$option\" \"$args\""
args="$@"
"$option" "$args"
exit 0
;;
Expand Down
9 changes: 5 additions & 4 deletions lib/armbian-configng/config.ng.docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,11 @@ EOF
# TODO: Migrate More features.
#echo " main=help - Display Legacy cli commands."
jq -r --arg script_name "$script_name" '
.menu[] |
.sub[] |
select(.id | startswith("H") | not) |
" --cli " + .id + " - " + .description
def process_item(item):
" --cli " + item.id + " - " + item.description,
(item.sub[]? | process_item(.));
.menu[] |
.sub[]? | process_item(.)
' $json_file
}

Expand Down
69 changes: 68 additions & 1 deletion lib/armbian-configng/config.ng.functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,52 @@ module_options+=(
#
# Function to execute the command
#

function execute_command() {
local id=$1
local commands=$(jq -r --arg id "$id" '.menu[] | .. | objects | select(.id==$id) | .command[]' "$json_file")

# Extract commands
local commands=$(jq -r --arg id "$id" '
.menu[] |
.. |
objects |
select(.id == $id) |
.command[]?' "$json_file")

# Check if a prompt exists
local prompt=$(jq -r --arg id "$id" '
.menu[] |
.. |
objects |
select(.id == $id) |
.prompt?' "$json_file")

# If a prompt exists, display it and wait for user confirmation
if [[ "$prompt" != "null" && $INPUTMODE != "cli" ]]; then
get_user_continue "$prompt" process_input
fi

# Execute each command
for command in "${commands[@]}"; do
[[ -n "$debug" ]] && echo "$command"
eval "$command"
done
}





function execute_command_old() {
local id=$1
#local commands=$(jq -r --arg id "$id" '.menu[] | .. | objects | select(.id==$id) | .command[]' "$json_file")
local commands=$(jq -r --arg id "$id" '
.menu[] |
.. |
objects |
select(.id == $id) |
.command[]?' "$json_file")

for command in "${commands[@]}"; do
# Check if the command is not in the list of restricted commands
[[ -n "$debug" ]] && echo "$command"
Expand Down Expand Up @@ -941,3 +984,27 @@ sanitize_input() {
done
echo "${sanitized_input[@]}"
}



module_options+=(
["get_user_input,author"]="tearran"
["get_user_input,ref_link"]=""
["get_user_input,feature"]="get_user_input"
["get_user_input,desc"]="Get user input from a dialog input box"
["get_user_input,example"]="get_user_input"
["get_user_input,status"]="Pending Review"
["get_user_input,doc_link"]=""
)
#
# @description Get user input from a dialog input box
function get_user_input() {

local choice=$($DIALOG --backtitle "$(uname --all)" --title "$TITLE" --inputbox "$INSTUCTION" 10 50 "$default" 3>&1 1>&2 2>&3)

if [ $? -eq 0 ]; then
echo "$choice"
fi


}
Loading
Loading