mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-07-07 15:56:53 +00:00
Update config_menu.sh
This commit is contained in:
parent
e09749c6f2
commit
c21b374b49
@ -1,105 +1,179 @@
|
||||
#!/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
|
||||
# Last Updated: 28/01/2025
|
||||
# Version : 1.1
|
||||
# Last Updated: 04/07/2025
|
||||
# ==========================================================
|
||||
|
||||
|
||||
# Configuration ============================================
|
||||
REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main"
|
||||
BASE_DIR="/usr/local/share/proxmenux"
|
||||
CONFIG_FILE="$BASE_DIR/config.json"
|
||||
CACHE_FILE="$BASE_DIR/cache.json"
|
||||
UTILS_FILE="$BASE_DIR/utils.sh"
|
||||
LOCAL_VERSION_FILE="$BASE_DIR/version.txt"
|
||||
INSTALL_DIR="/usr/local/bin"
|
||||
MENU_SCRIPT="menu"
|
||||
VENV_PATH="/opt/googletrans-env"
|
||||
|
||||
if [[ -f "$UTILS_FILE" ]]; then
|
||||
source "$UTILS_FILE"
|
||||
fi
|
||||
|
||||
load_language
|
||||
initialize_cache
|
||||
|
||||
# ==========================================================
|
||||
|
||||
detect_installation_type() {
|
||||
local has_venv=false
|
||||
local has_language=false
|
||||
|
||||
|
||||
if [ -d "$VENV_PATH" ] && [ -f "$VENV_PATH/bin/activate" ]; then
|
||||
has_venv=true
|
||||
fi
|
||||
|
||||
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
local current_language=$(jq -r '.language // empty' "$CONFIG_FILE" 2>/dev/null)
|
||||
if [[ -n "$current_language" && "$current_language" != "null" && "$current_language" != "empty" ]]; then
|
||||
has_language=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$has_venv" = true ] && [ "$has_language" = true ]; then
|
||||
echo "translation"
|
||||
else
|
||||
echo "normal"
|
||||
fi
|
||||
}
|
||||
|
||||
# ==========================================================
|
||||
show_config_menu() {
|
||||
local install_type
|
||||
install_type=$(detect_installation_type)
|
||||
|
||||
while true; do
|
||||
OPTION=$(whiptail --title "$(translate "Configuration Menu")" --menu "$(translate "Select an option:")" 20 70 8 \
|
||||
"1" "$(translate "Change Language")" \
|
||||
"2" "$(translate "Show Version Information")" \
|
||||
"3" "$(translate "Uninstall ProxMenux")" \
|
||||
"4" "$(translate "Return to Main Menu")" 3>&1 1>&2 2>&3)
|
||||
local menu_options=()
|
||||
local option_actions=()
|
||||
|
||||
case $OPTION in
|
||||
1)
|
||||
|
||||
if [ "$install_type" = "translation" ]; then
|
||||
menu_options+=("1" "$(translate "Change Language")")
|
||||
option_actions[1]="change_language"
|
||||
|
||||
menu_options+=("2" "$(translate "Show Version Information")")
|
||||
option_actions[2]="show_version_info"
|
||||
|
||||
menu_options+=("3" "$(translate "Uninstall ProxMenux")")
|
||||
option_actions[3]="uninstall_proxmenu"
|
||||
|
||||
menu_options+=("4" "$(translate "Return to Main Menu")")
|
||||
option_actions[4]="return_main"
|
||||
else
|
||||
|
||||
menu_options+=("1" "Show Version Information")
|
||||
option_actions[1]="show_version_info"
|
||||
|
||||
menu_options+=("2" "Uninstall ProxMenux")
|
||||
option_actions[2]="uninstall_proxmenu"
|
||||
|
||||
menu_options+=("3" "Return to Main Menu")
|
||||
option_actions[3]="return_main"
|
||||
fi
|
||||
|
||||
|
||||
OPTION=$(dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "$(translate "Configuration Menu")" \
|
||||
--menu "$(translate "Select an option:")" 15 60 4 \
|
||||
"${menu_options[@]}" 3>&1 1>&2 2>&3)
|
||||
|
||||
|
||||
case "${option_actions[$OPTION]}" in
|
||||
"change_language")
|
||||
change_language
|
||||
;;
|
||||
2)
|
||||
"show_version_info")
|
||||
show_version_info
|
||||
;;
|
||||
3)
|
||||
"uninstall_proxmenu")
|
||||
uninstall_proxmenu
|
||||
;;
|
||||
4) exec bash <(curl -s "$REPO_URL/scripts/menus/main_menu.sh") ;;
|
||||
*) exec bash <(curl -s "$REPO_URL/scripts/menus/main_menu.sh") ;;
|
||||
"return_main"|"")
|
||||
exec bash <(curl -s "$REPO_URL/scripts/menus/main_menu.sh")
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
# ==========================================================
|
||||
|
||||
change_language() {
|
||||
LANGUAGE=$(whiptail --title "$(translate "Change Language")" --menu "$(translate "Select a new language for the menu:")" 20 70 12 \
|
||||
"en" "$(translate "English (Recommended)")" \
|
||||
local new_language
|
||||
new_language=$(dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "$(translate "Change Language")" \
|
||||
--menu "$(translate "Select a new language for the menu:")" 20 60 6 \
|
||||
"en" "$(translate "English")" \
|
||||
"es" "$(translate "Spanish")" \
|
||||
"fr" "$(translate "French")" \
|
||||
"de" "$(translate "German")" \
|
||||
"it" "$(translate "Italian")" \
|
||||
"pt" "$(translate "Portuguese")" 3>&1 1>&2 2>&3)
|
||||
|
||||
if [ -z "$LANGUAGE" ]; then
|
||||
clear
|
||||
msg_error "$(translate "No language selected.")"
|
||||
if [ -z "$new_language" ]; then
|
||||
dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "$(translate "Language Change")" \
|
||||
--msgbox "\n\n$(translate "No language selected.")" 10 50
|
||||
return
|
||||
fi
|
||||
|
||||
# Update only the language field in the config file
|
||||
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
tmp=$(mktemp)
|
||||
jq --arg lang "$LANGUAGE" '.language = $lang' "$CONFIG_FILE" > "$tmp" && mv "$tmp" "$CONFIG_FILE"
|
||||
jq --arg lang "$new_language" '.language = $lang' "$CONFIG_FILE" > "$tmp" && mv "$tmp" "$CONFIG_FILE"
|
||||
else
|
||||
echo "{\"language\": \"$LANGUAGE\"}" > "$CONFIG_FILE"
|
||||
echo "{\"language\": \"$new_language\"}" > "$CONFIG_FILE"
|
||||
fi
|
||||
clear
|
||||
msg_ok "$(translate "Language changed to") $LANGUAGE"
|
||||
|
||||
# Reload the menu
|
||||
dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "$(translate "Language Change")" \
|
||||
--msgbox "\n\n$(translate "Language changed to") $new_language" 10 50
|
||||
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
curl -s "$REPO_URL/scripts/menus/config_menu.sh" > "$TMP_FILE"
|
||||
chmod +x "$TMP_FILE"
|
||||
|
||||
trap 'rm -f "$TMP_FILE"' EXIT
|
||||
|
||||
exec bash "$TMP_FILE"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# ==========================================================
|
||||
|
||||
show_version_info() {
|
||||
local version info_message temp_file
|
||||
local version info_message install_type
|
||||
install_type=$(detect_installation_type)
|
||||
|
||||
if [ -f "$LOCAL_VERSION_FILE" ]; then
|
||||
version=$(<"$LOCAL_VERSION_FILE")
|
||||
else
|
||||
version="Unknown"
|
||||
fi
|
||||
|
||||
info_message+="$(translate "Current ProxMenux version:") $version\n\n"
|
||||
info_message+="$(translate "Installed components:")\n"
|
||||
|
||||
|
||||
info_message+="$(translate "Installation type:")\n"
|
||||
if [ "$install_type" = "translation" ]; then
|
||||
info_message+="✓ $(translate "Translation Version (Multi-language support)")\n"
|
||||
else
|
||||
info_message+="✓ $(translate "Normal Version (English only - Lightweight)")\n"
|
||||
fi
|
||||
info_message+="\n"
|
||||
|
||||
info_message+="$(translate "Installed components:")\n"
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
while IFS=': ' read -r component value; do
|
||||
[ "$component" = "language" ] && continue
|
||||
@ -125,11 +199,14 @@ show_version_info() {
|
||||
|
||||
info_message+="\n$(translate "ProxMenu files:")\n"
|
||||
[ -f "$INSTALL_DIR/$MENU_SCRIPT" ] && info_message+="✓ $MENU_SCRIPT → $INSTALL_DIR/$MENU_SCRIPT\n" || info_message+="✗ $MENU_SCRIPT\n"
|
||||
[ -f "$CACHE_FILE" ] && info_message+="✓ cache.json → $CACHE_FILE\n" || info_message+="✗ cache.json\n"
|
||||
[ -f "$UTILS_FILE" ] && info_message+="✓ utils.sh → $UTILS_FILE\n" || info_message+="✗ utils.sh\n"
|
||||
[ -f "$CONFIG_FILE" ] && info_message+="✓ config.json → $CONFIG_FILE\n" || info_message+="✗ config.json\n"
|
||||
[ -f "$LOCAL_VERSION_FILE" ] && info_message+="✓ version.txt → $LOCAL_VERSION_FILE\n" || info_message+="✗ version.txt\n"
|
||||
|
||||
|
||||
if [ "$install_type" = "translation" ]; then
|
||||
[ -f "$CACHE_FILE" ] && info_message+="✓ cache.json → $CACHE_FILE\n" || info_message+="✗ cache.json\n"
|
||||
|
||||
info_message+="\n$(translate "Virtual Environment:")\n"
|
||||
if [ -d "$VENV_PATH" ] && [ -f "$VENV_PATH/bin/activate" ]; then
|
||||
info_message+="✓ $(translate "Installed") → $VENV_PATH\n"
|
||||
@ -141,115 +218,110 @@ show_version_info() {
|
||||
|
||||
current_language=$(jq -r '.language // "en"' "$CONFIG_FILE")
|
||||
info_message+="\n$(translate "Current language:")\n$current_language\n"
|
||||
else
|
||||
info_message+="\n$(translate "Language:")\nEnglish (Fixed)\n"
|
||||
fi
|
||||
|
||||
|
||||
# Mostrar con dialog usando un archivo temporal
|
||||
if command -v dialog >/dev/null 2>&1; then
|
||||
tmpfile=$(mktemp)
|
||||
echo -e "$info_message" > "$tmpfile"
|
||||
dialog --title "$(translate "ProxMenux Information")" --clear --textbox "$tmpfile" 20 70
|
||||
dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "$(translate "ProxMenux Information")" \
|
||||
--textbox "$tmpfile" 25 80
|
||||
rm -f "$tmpfile"
|
||||
fi
|
||||
#show_proxmenux_logo
|
||||
}
|
||||
|
||||
|
||||
# ==========================================================
|
||||
|
||||
uninstall_proxmenu() {
|
||||
if ! whiptail --title "Uninstall ProxMenu" --yesno "$(translate "Are you sure you want to uninstall ProxMenu?")" 10 60; then
|
||||
local install_type
|
||||
install_type=$(detect_installation_type)
|
||||
|
||||
if ! dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "Uninstall ProxMenu" \
|
||||
--yesno "\n$(translate "Are you sure you want to uninstall ProxMenu?")" 8 60; then
|
||||
return
|
||||
fi
|
||||
|
||||
# Show checklist for dependencies
|
||||
DEPS_TO_REMOVE=$(whiptail --title "Remove Dependencies" --checklist \
|
||||
"Select dependencies to remove:" 15 60 3 \
|
||||
local deps_to_remove=""
|
||||
|
||||
|
||||
if [ "$install_type" = "translation" ]; then
|
||||
deps_to_remove=$(dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "Remove Dependencies" \
|
||||
--checklist "Select dependencies to remove:" 15 60 4 \
|
||||
"python3-venv" "Python virtual environment" OFF \
|
||||
"python3-pip" "Python package installer" OFF \
|
||||
"python3" "Python interpreter" OFF \
|
||||
"jq" "JSON processor" OFF \
|
||||
3>&1 1>&2 2>&3)
|
||||
else
|
||||
deps_to_remove=$(dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "Remove Dependencies" \
|
||||
--checklist "Select dependencies to remove:" 12 60 2 \
|
||||
"dialog" "Interactive dialog boxes" OFF \
|
||||
"jq" "JSON processor" OFF \
|
||||
3>&1 1>&2 2>&3)
|
||||
fi
|
||||
|
||||
|
||||
(
|
||||
echo "10" ; echo "Removing ProxMenu files..."
|
||||
sleep 1
|
||||
|
||||
echo "Uninstalling ProxMenu..."
|
||||
|
||||
# Remove googletrans if virtual environment exists
|
||||
if [ -f "$VENV_PATH/bin/activate" ]; then
|
||||
echo "Removing googletrans..."
|
||||
echo "30" ; echo "Removing googletrans and virtual environment..."
|
||||
source "$VENV_PATH/bin/activate"
|
||||
pip uninstall -y googletrans >/dev/null 2>&1
|
||||
deactivate
|
||||
fi
|
||||
|
||||
# Remove virtual environment
|
||||
if [ -d "$VENV_PATH" ]; then
|
||||
echo "Removing virtual environment..."
|
||||
rm -rf "$VENV_PATH"
|
||||
fi
|
||||
|
||||
# Remove selected dependencies
|
||||
if [ -n "$DEPS_TO_REMOVE" ]; then
|
||||
echo "Removing selected dependencies..."
|
||||
echo "50" ; echo "Removing ProxMenu files..."
|
||||
rm -f "$INSTALL_DIR/$MENU_SCRIPT"
|
||||
rm -rf "$BASE_DIR"
|
||||
|
||||
# Remove quotes and process each package
|
||||
read -r -a DEPS_ARRAY <<< "$(echo "$DEPS_TO_REMOVE" | tr -d '"')"
|
||||
|
||||
if [ -n "$deps_to_remove" ]; then
|
||||
echo "70" ; echo "Removing selected dependencies..."
|
||||
read -r -a DEPS_ARRAY <<< "$(echo "$deps_to_remove" | tr -d '"')"
|
||||
for dep in "${DEPS_ARRAY[@]}"; do
|
||||
echo "Removing $dep..."
|
||||
|
||||
# Mark package as auto-installed
|
||||
apt-mark auto "$dep" >/dev/null 2>&1
|
||||
|
||||
# Try to remove with apt-get
|
||||
if ! apt-get -y --purge autoremove "$dep" >/dev/null 2>&1; then
|
||||
echo "Failed to remove $dep with apt-get. Trying with dpkg..."
|
||||
if ! dpkg --purge "$dep" >/dev/null 2>&1; then
|
||||
echo "Failed to remove $dep with dpkg. Trying to force removal..."
|
||||
dpkg --force-all --purge "$dep" >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Verify if the package was actually removed
|
||||
if dpkg -l "$dep" 2>/dev/null | grep -q '^ii'; then
|
||||
echo "Warning: Failed to completely remove $dep. You may need to remove it manually."
|
||||
else
|
||||
echo "$dep successfully removed."
|
||||
fi
|
||||
apt-get -y --purge autoremove "$dep" >/dev/null 2>&1
|
||||
done
|
||||
|
||||
# Run autoremove to clean up any leftover dependencies
|
||||
echo "Cleaning up unnecessary packages..."
|
||||
apt-get autoremove -y --purge >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
echo "90" ; echo "Restoring system files..."
|
||||
|
||||
# Restore original .bashrc if backup exists
|
||||
if [ -f /root/.bashrc.bak ]; then
|
||||
echo "$(translate "Restoring original .bashrc...")"
|
||||
mv /root/.bashrc.bak /root/.bashrc
|
||||
fi
|
||||
|
||||
# Restore original MOTD if backup exists
|
||||
[ -f /root/.bashrc.bak ] && mv /root/.bashrc.bak /root/.bashrc
|
||||
if [ -f /etc/motd.bak ]; then
|
||||
echo "$(translate "Restoring original MOTD...")"
|
||||
mv /etc/motd.bak /etc/motd
|
||||
else
|
||||
# Remove custom MOTD line if present
|
||||
sed -i '/This system is optimised by: ProxMenux/d' /etc/motd
|
||||
fi
|
||||
|
||||
echo "100" ; echo "Uninstallation complete!"
|
||||
sleep 1
|
||||
|
||||
# Remove ProxMenu files
|
||||
rm -f "/usr/local/bin/menu"
|
||||
rm -rf "$BASE_DIR"
|
||||
) | dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "Uninstalling ProxMenux" \
|
||||
--gauge "Starting uninstallation..." 10 60 0
|
||||
|
||||
echo "ProxMenu has been uninstalled."
|
||||
|
||||
if [ -n "$DEPS_TO_REMOVE" ]; then
|
||||
echo "The following dependencies have been removed successfully: $DEPS_TO_REMOVE"
|
||||
local final_message="ProxMenux has been uninstalled successfully.\n\n"
|
||||
if [ -n "$deps_to_remove" ]; then
|
||||
final_message+="The following dependencies were removed:\n$deps_to_remove\n\n"
|
||||
fi
|
||||
final_message+="Thank you for using ProxMenux!"
|
||||
|
||||
echo
|
||||
echo "ProxMenux uninstallation complete. Thank you for using it!"
|
||||
echo
|
||||
dialog --clear --backtitle "ProxMenux Configuration" \
|
||||
--title "Uninstallation Complete" \
|
||||
--msgbox "$final_message" 12 60
|
||||
clear
|
||||
exit 0
|
||||
}
|
||||
|
||||
#show_proxmenux_logo
|
||||
# ==========================================================
|
||||
# Main execution
|
||||
show_config_menu
|
Loading…
x
Reference in New Issue
Block a user