Update helpers-menu.sh

This commit is contained in:
MacRimi 2025-06-06 00:02:43 +02:00
parent b8bdcf4c71
commit de49d67361

View File

@ -36,7 +36,6 @@ initialize_cache
HELPERS_JSON_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/refs/heads/main/json/helpers_cache.json" 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" METADATA_URL="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/frontend/public/json/metadata.json"
for cmd in curl jq dialog; do for cmd in curl jq dialog; do
if ! command -v "$cmd" >/dev/null; then if ! command -v "$cmd" >/dev/null; then
echo "Missing required command: $cmd" echo "Missing required command: $cmd"
@ -44,23 +43,19 @@ for cmd in curl jq dialog; do
fi fi
done done
CACHE_JSON=$(curl -s "$HELPERS_JSON_URL") CACHE_JSON=$(curl -s "$HELPERS_JSON_URL")
META_JSON=$(curl -s "$METADATA_URL") META_JSON=$(curl -s "$METADATA_URL")
declare -A CATEGORY_NAMES declare -A CATEGORY_NAMES
while read -r id name; do while read -r id name; do
CATEGORY_NAMES[$id]="$name" CATEGORY_NAMES[$id]="$name"
done < <(echo "$META_JSON" | jq -r '.categories[] | "\(.id)\t\(.name)"') done < <(echo "$META_JSON" | jq -r '.categories[] | "\(.id)\t\(.name)"')
declare -A CATEGORY_COUNT declare -A CATEGORY_COUNT
for id in $(echo "$CACHE_JSON" | jq -r '.[].categories[]'); do for id in $(echo "$CACHE_JSON" | jq -r '.[].categories[]'); do
((CATEGORY_COUNT[$id]++)) ((CATEGORY_COUNT[$id]++))
done done
get_type_label() { get_type_label() {
local type="$1" local type="$1"
case "$type" in case "$type" in
@ -72,7 +67,6 @@ get_type_label() {
esac esac
} }
download_script() { download_script() {
local url="$1" local url="$1"
local fallback_pve="${url/misc\/tools\/pve}" local fallback_pve="${url/misc\/tools\/pve}"
@ -92,9 +86,32 @@ download_script() {
fi fi
} }
RETURN_TO_MAIN=false 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() { run_script_by_slug() {
local slug="$1" local slug="$1"
@ -109,19 +126,56 @@ run_script_by_slug() {
name=$(decode "$script_info" ".name") name=$(decode "$script_info" ".name")
desc=$(decode "$script_info" ".desc") desc=$(decode "$script_info" ".desc")
script_url=$(decode "$script_info" ".script_url") 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 if [[ $? -eq 0 ]]; then
download_script "$script_url" download_script "$script_url"
echo echo
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..." msg_success "Press Enter to return to the main menu..."
read -r read -r
RETURN_TO_MAIN=true RETURN_TO_MAIN=true
fi fi
} }
@ -131,14 +185,11 @@ search_and_filter_scripts() {
local search_term="" local search_term=""
while true; do while true; do
search_term=$(dialog --inputbox "Enter search term (leave empty to show all scripts):" \ search_term=$(dialog --inputbox "Enter search term (leave empty to show all scripts):" \
8 65 "$search_term" 3>&1 1>&2 2>&3) 8 65 "$search_term" 3>&1 1>&2 2>&3)
[[ $? -ne 0 ]] && return [[ $? -ne 0 ]] && return
local filtered_json local filtered_json
if [[ -z "$search_term" ]]; then if [[ -z "$search_term" ]]; then
filtered_json="$CACHE_JSON" filtered_json="$CACHE_JSON"
@ -152,7 +203,6 @@ search_and_filter_scripts() {
)]') )]')
fi fi
local count local count
count=$(echo "$filtered_json" | jq length) count=$(echo "$filtered_json" | jq length)
@ -161,7 +211,6 @@ search_and_filter_scripts() {
continue continue
fi fi
while true; do while true; do
declare -A index_to_slug declare -A index_to_slug
local menu_items=() local menu_items=()
@ -179,12 +228,10 @@ search_and_filter_scripts() {
done < <(echo "$filtered_json" | jq -r ' done < <(echo "$filtered_json" | jq -r '
sort_by(.name)[] | [.slug, .name, .type] | @tsv') sort_by(.name)[] | [.slug, .name, .type] | @tsv')
menu_items+=("" "") menu_items+=("" "")
menu_items+=("new_search" "New Search") menu_items+=("new_search" "New Search")
menu_items+=("show_all" "Show All Scripts") menu_items+=("show_all" "Show All Scripts")
local title="Search Results" local title="Search Results"
if [[ -n "$search_term" ]]; then if [[ -n "$search_term" ]]; then
title="Search Results for: '$search_term' ($count found)" title="Search Results for: '$search_term' ($count found)"
@ -192,16 +239,13 @@ search_and_filter_scripts() {
title="All Available Scripts ($count total)" title="All Available Scripts ($count total)"
fi fi
local selected local selected
selected=$(dialog --colors --backtitle "ProxMenux" \ selected=$(dialog --colors --backtitle "ProxMenux" \
--title "$title" \ --title "$title" \
--menu "Select a script or action:" \ --menu "Select a script or action:" \
22 75 15 "${menu_items[@]}" 3>&1 1>&2 2>&3) 22 75 15 "${menu_items[@]}" 3>&1 1>&2 2>&3)
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
return return
fi fi
@ -219,7 +263,6 @@ search_and_filter_scripts() {
return return
;; ;;
*) *)
if [[ -n "${index_to_slug[$selected]}" ]]; then if [[ -n "${index_to_slug[$selected]}" ]]; then
run_script_by_slug "${index_to_slug[$selected]}" run_script_by_slug "${index_to_slug[$selected]}"
[[ "$RETURN_TO_MAIN" == true ]] && { RETURN_TO_MAIN=false; return; } [[ "$RETURN_TO_MAIN" == true ]] && { RETURN_TO_MAIN=false; return; }
@ -230,15 +273,12 @@ search_and_filter_scripts() {
done done
} }
while true; do while true; do
MENU_ITEMS=() MENU_ITEMS=()
MENU_ITEMS+=("search" "Search/Filter Scripts") MENU_ITEMS+=("search" "Search/Filter Scripts")
MENU_ITEMS+=("" "") MENU_ITEMS+=("" "")
for id in $(printf "%s\n" "${!CATEGORY_COUNT[@]}" | sort -n); do for id in $(printf "%s\n" "${!CATEGORY_COUNT[@]}" | sort -n); do
name="${CATEGORY_NAMES[$id]:-Category $id}" name="${CATEGORY_NAMES[$id]:-Category $id}"
count="${CATEGORY_COUNT[$id]}" count="${CATEGORY_COUNT[$id]}"
@ -252,18 +292,15 @@ while true; do
"${MENU_ITEMS[@]}" 3>&1 1>&2 2>&3) || { "${MENU_ITEMS[@]}" 3>&1 1>&2 2>&3) || {
dialog --title "Proxmox VE Helper-Scripts" \ 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 --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 clear
break break
} }
if [[ "$SELECTED" == "search" ]]; then if [[ "$SELECTED" == "search" ]]; then
search_and_filter_scripts search_and_filter_scripts
continue continue
fi fi
while true; do while true; do
declare -A INDEX_TO_SLUG declare -A INDEX_TO_SLUG
SCRIPTS=() SCRIPTS=()
@ -285,7 +322,6 @@ while true; do
SCRIPT_SELECTED="${INDEX_TO_SLUG[$SCRIPT_INDEX]}" SCRIPT_SELECTED="${INDEX_TO_SLUG[$SCRIPT_INDEX]}"
run_script_by_slug "$SCRIPT_SELECTED" run_script_by_slug "$SCRIPT_SELECTED"
[[ "$RETURN_TO_MAIN" == true ]] && { RETURN_TO_MAIN=false; break; } [[ "$RETURN_TO_MAIN" == true ]] && { RETURN_TO_MAIN=false; break; }
done done
done done