From de49d673615e635ee24767da9da80aaa6ee98471 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Fri, 6 Jun 2025 00:02:43 +0200 Subject: [PATCH] Update helpers-menu.sh --- scripts/test/helpers-menu.sh | 96 +++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/scripts/test/helpers-menu.sh b/scripts/test/helpers-menu.sh index 26f8217..95ab32b 100644 --- a/scripts/test/helpers-menu.sh +++ b/scripts/test/helpers-menu.sh @@ -36,7 +36,6 @@ initialize_cache HELPERS_JSON_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/refs/heads/main/json/helpers_cache.json" METADATA_URL="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/frontend/public/json/metadata.json" - for cmd in curl jq dialog; do if ! command -v "$cmd" >/dev/null; then echo "Missing required command: $cmd" @@ -44,23 +43,19 @@ for cmd in curl jq dialog; do fi done - CACHE_JSON=$(curl -s "$HELPERS_JSON_URL") META_JSON=$(curl -s "$METADATA_URL") - declare -A CATEGORY_NAMES while read -r id name; do CATEGORY_NAMES[$id]="$name" done < <(echo "$META_JSON" | jq -r '.categories[] | "\(.id)\t\(.name)"') - declare -A CATEGORY_COUNT for id in $(echo "$CACHE_JSON" | jq -r '.[].categories[]'); do ((CATEGORY_COUNT[$id]++)) done - get_type_label() { local type="$1" case "$type" in @@ -72,7 +67,6 @@ get_type_label() { esac } - download_script() { local url="$1" local fallback_pve="${url/misc\/tools\/pve}" @@ -92,9 +86,32 @@ download_script() { fi } - RETURN_TO_MAIN=false +format_credentials() { + local script_info="$1" + local credentials_info="" + + local has_credentials + has_credentials=$(echo "$script_info" | base64 --decode | jq -r 'has("default_credentials")') + + if [[ "$has_credentials" == "true" ]]; then + local username password + username=$(echo "$script_info" | base64 --decode | jq -r '.default_credentials.username // empty') + password=$(echo "$script_info" | base64 --decode | jq -r '.default_credentials.password // empty') + + if [[ -n "$username" && -n "$password" ]]; then + credentials_info="Username: $username | Password: $password" + elif [[ -n "$username" ]]; then + credentials_info="Username: $username" + elif [[ -n "$password" ]]; then + credentials_info="Password: $password" + fi + fi + + echo "$credentials_info" +} + run_script_by_slug() { local slug="$1" @@ -109,19 +126,56 @@ run_script_by_slug() { name=$(decode "$script_info" ".name") desc=$(decode "$script_info" ".desc") script_url=$(decode "$script_info" ".script_url") - notes=$(decode "$script_info" ".notes | join(\"\n• \" )") + notes=$(decode "$script_info" ".notes | join(\"\n\")") - local msg="\Zb\Z1$name\Zn\n\n$desc" - [[ -n "$notes" ]] && msg+="\n\n\ZbNotes:\Zn\n• $notes" - dialog --clear --colors --backtitle "ProxMenux" --title "$name" --yesno "$msg\n\nExecute this script?" 20 80 + local notes_dialog="" + if [[ -n "$notes" ]]; then + while IFS= read -r line; do + notes_dialog+="• $line\n" + done <<< "$notes" + notes_dialog="${notes_dialog%\\n}" + fi + + + local credentials + credentials=$(format_credentials "$script_info") + + + local msg="\Zb\Z4Descripción:\Zn\n$desc" + [[ -n "$notes_dialog" ]] && msg+="\n\n\Zb\Z4Notes:\Zn\n$notes_dialog" + [[ -n "$credentials" ]] && msg+="\n\n\Zb\Z4Default Credentials:\Zn\n$credentials" + + dialog --clear --colors --backtitle "ProxMenux" --title "$name" --yesno "$msg\n\nExecute this script?" 22 85 if [[ $? -eq 0 ]]; then download_script "$script_url" echo echo + + if [[ -n "$desc" || -n "$notes" || -n "$credentials" ]]; then + echo -e "$TAB\e[1;36mScript Information:\e[0m" + + + + if [[ -n "$notes" ]]; then + echo -e "$TAB\e[1;33mNotes:\e[0m" + while IFS= read -r line; do + [[ -z "$line" ]] && continue + echo -e "$TAB• $line" + done <<< "$notes" + echo + fi + + + if [[ -n "$credentials" ]]; then + echo -e "$TAB\e[1;32mDefault Credentials:\e[0m" + echo "$TAB$credentials" + echo + fi + fi + msg_success "Press Enter to return to the main menu..." read -r - RETURN_TO_MAIN=true fi } @@ -131,14 +185,11 @@ search_and_filter_scripts() { local search_term="" while true; do - search_term=$(dialog --inputbox "Enter search term (leave empty to show all scripts):" \ 8 65 "$search_term" 3>&1 1>&2 2>&3) - [[ $? -ne 0 ]] && return - local filtered_json if [[ -z "$search_term" ]]; then filtered_json="$CACHE_JSON" @@ -152,7 +203,6 @@ search_and_filter_scripts() { )]') fi - local count count=$(echo "$filtered_json" | jq length) @@ -161,7 +211,6 @@ search_and_filter_scripts() { continue fi - while true; do declare -A index_to_slug local menu_items=() @@ -179,12 +228,10 @@ search_and_filter_scripts() { done < <(echo "$filtered_json" | jq -r ' sort_by(.name)[] | [.slug, .name, .type] | @tsv') - menu_items+=("" "") menu_items+=("new_search" "New Search") menu_items+=("show_all" "Show All Scripts") - local title="Search Results" if [[ -n "$search_term" ]]; then title="Search Results for: '$search_term' ($count found)" @@ -192,16 +239,13 @@ search_and_filter_scripts() { title="All Available Scripts ($count total)" fi - local selected selected=$(dialog --colors --backtitle "ProxMenux" \ --title "$title" \ --menu "Select a script or action:" \ 22 75 15 "${menu_items[@]}" 3>&1 1>&2 2>&3) - if [[ $? -ne 0 ]]; then - return fi @@ -219,7 +263,6 @@ search_and_filter_scripts() { return ;; *) - if [[ -n "${index_to_slug[$selected]}" ]]; then run_script_by_slug "${index_to_slug[$selected]}" [[ "$RETURN_TO_MAIN" == true ]] && { RETURN_TO_MAIN=false; return; } @@ -230,15 +273,12 @@ search_and_filter_scripts() { done } - while true; do MENU_ITEMS=() - MENU_ITEMS+=("search" "Search/Filter Scripts") MENU_ITEMS+=("" "") - for id in $(printf "%s\n" "${!CATEGORY_COUNT[@]}" | sort -n); do name="${CATEGORY_NAMES[$id]:-Category $id}" count="${CATEGORY_COUNT[$id]}" @@ -252,18 +292,15 @@ while true; do "${MENU_ITEMS[@]}" 3>&1 1>&2 2>&3) || { dialog --title "Proxmox VE Helper-Scripts" \ --msgbox "\n\n$(translate "Visit the website to discover more scripts, stay updated with the latest updates, and support the project:")\n\nhttps://community-scripts.github.io/ProxmoxVE" 15 70 - clear break } - if [[ "$SELECTED" == "search" ]]; then search_and_filter_scripts continue fi - while true; do declare -A INDEX_TO_SLUG SCRIPTS=() @@ -285,7 +322,6 @@ while true; do SCRIPT_SELECTED="${INDEX_TO_SLUG[$SCRIPT_INDEX]}" run_script_by_slug "$SCRIPT_SELECTED" - [[ "$RETURN_TO_MAIN" == true ]] && { RETURN_TO_MAIN=false; break; } done done \ No newline at end of file