ProxMenux/scripts/menus/menu_Helper_Scripts.sh

184 lines
10 KiB
Bash
Raw Normal View History

2025-02-09 14:29:28 +01:00
#!/bin/bash
# ==========================================================
# ProxMenu - A menu-driven script for Proxmox VE management
# ==========================================================
# Author : MacRimi
# Copyright : (c) 2024 MacRimi
# License : MIT (https://raw.githubusercontent.com/MacRimi/ProxMenux/main/LICENSE)
# Version : 1.0
2025-02-09 15:56:14 +01:00
# Last Updated: 28/01/2025
2025-02-09 14:29:28 +01:00
# ==========================================================
# Description:
# This script provides a simple and efficient way to access and execute essential Proxmox VE scripts
# from the Community Scripts project (https://community-scripts.github.io/ProxmoxVE/).
#
# It serves as a convenient tool to run key automation scripts that simplify system management,
# continuing the great work and legacy of tteck in making Proxmox VE more accessible.
# A streamlined solution for executing must-have tools in Proxmox VE.
# ==========================================================
# Configuration ============================================
REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main"
BASE_DIR="/usr/local/share/proxmenux"
UTILS_FILE="$BASE_DIR/utils.sh"
VENV_PATH="/opt/googletrans-env"
if [[ -f "$UTILS_FILE" ]]; then
source "$UTILS_FILE"
fi
load_language
initialize_cache
2025-05-05 09:14:49 +02:00
show_proxmenux_logo
2025-02-09 14:29:28 +01:00
# ==========================================================
# Base URL community-scripts
BASE_URL="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc"
2025-03-05 23:18:56 +01:00
BASE_URL2="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main"
2025-02-09 14:29:28 +01:00
2025-04-27 19:05:36 +02:00
download_script() {
local url="$1"
local fallback_pve="${url/misc/tools\/pve}"
local fallback_addon="${url/misc/tools\/addon}"
local fallback_copydata="${url/misc/tools\/copy-data}"
if curl --silent --head --fail "$url" >/dev/null; then
bash <(curl -s "$url")
elif curl --silent --head --fail "$fallback_pve" >/dev/null; then
bash <(curl -s "$fallback_pve")
elif curl --silent --head --fail "$fallback_addon" >/dev/null; then
bash <(curl -s "$fallback_addon")
elif curl --silent --head --fail "$fallback_copydata" >/dev/null; then
bash <(curl -s "$fallback_copydata")
else
msg_error "$(translate 'Error: Failed to download the script.')\033[0m"
msg_error "\n$(translate 'Tried URLs:')\n- $url\n- $fallback_pve\n- $fallback_addons\n- $fallback_copydata\n"
msg_success "$(translate "Press Enter to return to menu...")"
read -r
fi
}
2025-02-09 14:29:28 +01:00
2025-02-09 15:56:14 +01:00
# Array with script names, URLs, categories, and descriptions
2025-02-09 14:29:28 +01:00
scripts=(
2025-05-05 09:28:43 +02:00
"Proxmox VE LXC IP-Tag§Containers§$BASE_URL/add-lxc-iptag.sh§Description:\n\nThis script automatically adds IP address as tags to LXC containers using a Systemd service.\n\nThe service also updates the tags if a LXC IP address is changed. Configuration: nano /opt/lxc-iptag/iptag.conf. iptag.service must be restarted after change.\n\n\\The Proxmox Node must contain ipcalc and net-tools. apt-get install -y ipcalc net-tools"
"Add Netbird to LXC§Networking§$BASE_URL/add-netbird-lxc.sh§Description:\n\nNetBird combines a configuration-free peer-to-peer private network and a centralized access control system.\n\nAfter the script finishes, reboot the LXC then run netbird up in the LXC console.\n\n\\The script only works in Debian/Ubuntu, not in Alpine!"
"Add Tailscale to LXC§Networking§$BASE_URL/add-tailscale-lxc.sh§Description:\n\nTailscale enables secure communication between devices over the internet.\n\nIt creates a virtual private network (VPN).\n\n\\After the script finishes, reboot the LXC then run tailscale up in the LXC console."
"Proxmox VE LXC Cleaner§Maintenance§$BASE_URL/clean-lxcs.sh§Description:\n\nDelete logs, cache, and repopulate apt lists."
"Proxmox VE Host Backup§Security§$BASE_URL/host-backup.sh§Description:\n\nVersatile backup utility for user-specified paths.\n\nA backup is rendered ineffective when it remains stored on the host."
"Add hardware Acceleration LXC§Containers§$BASE_URL/hw-acceleration.sh§Description:\n\nEnables IGPU hardware acceleration for LXC containers."
"Proxmox Clean Orphaned LVM§Maintenance§$BASE_URL/clean-orphaned-lvm.sh§Description:\n\nIdentifies and safely removes orphaned LVM volumes."
"Install Crowdsec§Security§$BASE_URL/crowdsec.sh§Description:\n\nCollaborative IPS to detect and share malicious behavior signals."
"Proxmox VE LXC Filesystem Trim§Maintenance§$BASE_URL/fstrim.sh§Description:\n\nManages unused SSD blocks for LXC containers (ext4 only)."
"Install Glances§Monitoring§$BASE_URL/glances.sh§Description:\n\nCross-platform system monitoring tool."
"Proxmox VE Kernel Clean§Maintenance§$BASE_URL/kernel-clean.sh§Description:\n\nRemoves unused kernels to free disk and clean GRUB menu."
"Proxmox VE Kernel Pin§System§$BASE_URL/kernel-pin.sh§Description:\n\nManage kernel pinning and unpinning."
"Container LXC Deletion§Containers§$BASE_URL/lxc-delete.sh§Description:\n\nInteractive LXC deletion with safe shutdown and confirmation."
"Proxmox VE Processor Microcode§System§$BASE_URL/microcode.sh§Description:\n\nUpdates firmware for hardware bug fixes and performance."
"Proxmox VE Netdata§Monitoring§$BASE_URL/netdata.sh§Description:\n\nReal-time performance monitoring via Netdata."
"Install Olivetin§Applications§$BASE_URL/olivetin.sh§Description:\n\nWeb interface to execute preconfigured commands.\n\nConfig: /etc/OliveTin/config.yaml"
"Proxmox VE Post Install§System§$BASE_URL/post-pve-install.sh§Description:\n\nManages Proxmox sources, disables nag, enables test repo.\n\n\\Recommended to answer yes (y) to all."
"Proxmox VE CPU Scaling Governor§System§$BASE_URL/scaling-governor.sh§Description:\n\nOptimizes CPU frequency for power or performance."
"Proxmox VE Cron LXC Updater§Maintenance§$BASE_URL/cron-update-lxcs.sh§Description:\n\nAdds crontab to update all LXCs every Sunday at midnight.\n\nTo exclude LXCs, edit the crontab:\n\n0 0 * * 0 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /bin/bash -c '$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/pve/update-lxcs-cron.sh)' -s 103 111 >>/var/log/update-lxcs-cron.log 2>/dev/null"
"Proxmox VE LXC Updater§Maintenance§$BASE_URL/update-lxcs.sh§Description:\n\nUpdates all LXC containers across various distros, skipping templates."
"Proxmox Backup Server§Security§$BASE_URL2/ct/proxmox-backup-server.sh§Description:\n\nEnterprise backup solution for VMs, CTs and physical hosts.\n\nSet root password if using autologin: passwd root"
2025-02-09 14:29:28 +01:00
)
2025-05-05 09:28:43 +02:00
2025-02-09 14:29:28 +01:00
show_menu() {
declare -A category_order
category_order["System"]=1
category_order["Maintenance"]=2
category_order["Containers"]=3
category_order["Applications"]=4
category_order["Monitoring"]=5
category_order["Networking"]=6
category_order["Security"]=7
2025-02-09 15:56:14 +01:00
custom_sort() {
2025-05-05 09:28:43 +02:00
while IFS='§' read -r name category url description; do
2025-02-09 15:56:14 +01:00
category=$(echo "$category" | xargs)
order=${category_order[$category]:-999}
printf "%d|%s|%s|%s|%s\n" "$order" "$name" "$category" "$url" "$description"
2025-02-09 14:29:28 +01:00
done | sort -n | cut -d'|' -f2-
}
2025-02-09 15:56:14 +01:00
while true; do
2025-02-09 14:29:28 +01:00
IFS=$'\n' sorted_scripts=($(printf "%s\n" "${scripts[@]}" | custom_sort))
unset IFS
HEADER=$(printf " %-57s %-20s" "$(translate "Name")" "$(translate "Category")")
menu_items=()
for script in "${sorted_scripts[@]}"; do
2025-02-09 15:56:14 +01:00
IFS='|' read -r name category url description <<< "$script"
translated_category=$(translate "$category")
padded_name=$(printf "%-57s" "$name")
menu_items+=("$padded_name" "$translated_category")
2025-02-09 14:29:28 +01:00
done
menu_items+=("$(translate "Return to Main Menu")" "")
2025-02-25 18:17:24 +01:00
cleanup
2025-02-09 14:29:28 +01:00
script_selection=$(whiptail --title "$(translate "Essential Proxmox VE Helper-Scripts")" \
--menu "\n$HEADER\n\n$(translate "Select a script to execute")" 25 78 16 \
"${menu_items[@]}" 3>&1 1>&2 2>&3)
2025-02-09 15:56:14 +01:00
if [ -n "$script_selection" ]; then
script_selection=$(echo "$script_selection" | xargs)
if [ "$script_selection" = "$(translate "Return to Main Menu")" ]; then
2025-02-09 14:29:28 +01:00
2025-02-09 15:56:14 +01:00
whiptail --title "Proxmox VE Helper-Scripts" \
2025-03-05 23:24:29 +01:00
--msgbox "$(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
2025-02-09 14:29:28 +01:00
2025-02-09 15:56:14 +01:00
exec bash <(curl -s "$REPO_URL/scripts/menus/main_menu.sh")
fi
2025-02-09 14:29:28 +01:00
for script in "${sorted_scripts[@]}"; do
IFS='|' read -r name category url description <<< "$script"
if [ "$name" = "$script_selection" ]; then
selected_url="$url"
2025-02-09 15:56:14 +01:00
selected_description=$(translate "$description")
2025-02-09 14:29:28 +01:00
break
fi
done
if [ -n "$selected_url" ]; then
if whiptail --title "$(translate "Script Information")" \
--yes-button "$(translate "Accept")" \
--no-button "$(translate "Cancel")" \
2025-02-09 16:53:08 +01:00
--yesno "$selected_description" 20 78; then
2025-02-09 15:56:14 +01:00
msg_info2 "$(translate "Executing script:") $script_selection"
2025-02-09 14:29:28 +01:00
sleep 2
2025-04-27 19:05:36 +02:00
download_script "$selected_url"
2025-02-09 14:29:28 +01:00
msg_ok "$(translate "Script completed.")"
msg_success "$(translate "Press Enter to return to the main menu...")"
2025-02-09 15:56:14 +01:00
read -r
2025-02-09 14:29:28 +01:00
else
msg_info2 "$(translate "Script execution cancelled.")"
sleep 2
fi
else
echo "$(translate "Error: Could not find the selected script URL.")"
2025-02-09 15:56:14 +01:00
read -rp "$(translate "Press Enter to continue...")"
2025-02-09 14:29:28 +01:00
fi
else
2025-02-09 15:56:14 +01:00
exec bash <(curl -s "$REPO_URL/scripts/menus/main_menu.sh")
2025-02-09 14:29:28 +01:00
fi
done
}
2025-02-25 19:14:55 +01:00
2025-02-25 18:17:24 +01:00
if [[ "$LANGUAGE" != "en" ]]; then
msg_lang "$(translate "Generating automatic translations...")"
fi
2025-02-09 14:29:28 +01:00
show_menu