ProxMenux/install_proxmenux.sh

188 lines
5.7 KiB
Bash
Raw Normal View History

2024-12-20 18:54:00 +01:00
#!/bin/bash
2025-02-02 19:21:58 +01:00
# ==========================================================
# 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
# ==========================================================
# Description:
# This script installs and configures ProxMenux, a menu-driven
# tool for managing Proxmox VE.
#
# - Ensures the script is run with root privileges.
# - Displays an installation confirmation prompt.
# - Installs required dependencies:
# - whiptail (for interactive terminal menus)
# - curl (for downloading remote files)
# - jq (for handling JSON data)
# - Python 3 and virtual environment (for translations)
# - Configures the Python virtual environment and installs googletrans.
# - Creates necessary directories for storing ProxMenux data.
# - Downloads required files from GitHub, including:
# - Cache file (`cache.json`) for translation caching.
# - Utility script (`utils.sh`) for core functions.
# - Main script (`menu.sh`) to launch ProxMenux.
# - Sets correct permissions for execution.
# - Displays final instructions on how to start ProxMenux.
#
# This installer ensures a smooth setup process and prepares
# the system for running ProxMenux efficiently.
# ==========================================================
2025-02-02 19:41:11 +01:00
2025-02-02 19:21:58 +01:00
# Configuration ============================================
2024-12-20 18:54:00 +01:00
REPO_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main"
2025-02-02 19:21:58 +01:00
UTILS_URL="https://raw.githubusercontent.com/MacRimi/ProxMenux/main/scripts/utils.sh"
2024-12-20 21:44:20 +01:00
INSTALL_DIR="/usr/local/bin"
2024-12-20 21:41:34 +01:00
BASE_DIR="/usr/local/share/proxmenux"
2025-02-02 19:21:58 +01:00
CACHE_FILE="$BASE_DIR/cache.json"
UTILS_FILE="$BASE_DIR/utils.sh"
2024-12-20 21:41:34 +01:00
LOCAL_VERSION_FILE="$BASE_DIR/version.txt"
2024-12-20 21:44:20 +01:00
MENU_SCRIPT="menu.sh"
2024-12-20 21:41:34 +01:00
2025-01-09 21:37:09 +01:00
2025-02-02 19:21:58 +01:00
if ! source <(curl -sSf "$UTILS_URL"); then
echo "$(translate 'Error: Could not load utils.sh from') $UTILS_URL"
exit 1
fi
2025-02-02 19:41:11 +01:00
2025-02-02 19:21:58 +01:00
# ==========================================================
2024-12-20 21:44:20 +01:00
if [ "$(id -u)" -ne 0 ]; then
2025-02-02 19:21:58 +01:00
msg_error "This script must be run as root."
exit 1
fi
2025-02-02 19:41:11 +01:00
2025-02-02 19:21:58 +01:00
show_proxmenu_logo
2025-02-02 19:41:11 +01:00
2025-02-02 19:52:10 +01:00
echo -e "${YW}To function correctly, ProxMenu needs to install the following components:${CL}"
2025-02-02 19:21:58 +01:00
echo -e "${TAB}- whiptail (if not already installed)"
echo -e "${TAB}- curl (if not already installed)"
echo -e "${TAB}- jq (if not already installed)"
echo -e "${TAB}- Python 3 (if not already installed)"
echo -e "${TAB}- Virtual environment for Google Translate"
echo -e "${TAB}- ProxMenu scripts and configuration files"
echo
2025-02-02 19:52:10 +01:00
read -p "Do you want to proceed with the installation? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
msg_warn "Installation cancelled."
exit 1
fi
2025-02-02 19:41:11 +01:00
2024-12-20 18:54:00 +01:00
2025-02-03 23:08:37 +01:00
# Install dependencies =====================================
2025-02-02 19:21:58 +01:00
msg_info "Checking system dependencies..."
2025-01-09 21:37:09 +01:00
2025-02-03 23:08:37 +01:00
DEPS=("whiptail" "curl" "jq" "python3" "python3-venv" "python3-pip")
for pkg in "${DEPS[@]}"; do
if ! dpkg -l | grep -qw "$pkg"; then
msg_info "Installing $pkg..."
if apt-get update && apt-get install -y "$pkg"; then
msg_ok "$pkg installed successfully."
else
msg_error "Failed to install $pkg. Please install it manually."
exit 1
fi
2025-02-02 19:21:58 +01:00
else
2025-02-03 23:08:37 +01:00
msg_ok "$pkg is already installed."
2025-02-02 19:21:58 +01:00
fi
2025-02-03 23:08:37 +01:00
done
2025-02-02 19:21:58 +01:00
2025-02-03 23:08:37 +01:00
# Set up virtual environment ==============================
2025-01-12 17:08:33 +01:00
2025-02-03 23:31:15 +01:00
# msg_info "Setting up the virtual environment for translations..."
2025-02-03 23:08:37 +01:00
2025-02-03 23:31:15 +01:00
#mkdir -p /opt
#chmod 755 /opt
if [ ! -d "$VENV_PATH" ] || [ ! -f "$VENV_PATH/bin/activate" ]; then
msg_info "Creating the virtual environment..."
python3 -m venv --system-site-packages "$VENV_PATH"
2025-02-03 23:17:31 +01:00
if [ ! -f "$VENV_PATH/bin/activate" ]; then
msg_error "Failed to create virtual environment. Please check your Python installation."
2025-02-02 19:21:58 +01:00
exit 1
fi
2025-02-03 23:17:31 +01:00
fi
2025-02-03 23:08:37 +01:00
2025-02-03 23:31:15 +01:00
2025-02-03 23:17:31 +01:00
source "$VENV_PATH/bin/activate"
2025-02-03 23:31:15 +01:00
pip install --upgrade pip
2025-02-03 23:17:31 +01:00
if pip install --break-system-packages --no-cache-dir googletrans==4.0.0-rc1; then
msg_ok "Virtual environment configured and googletrans installed."
2025-02-02 19:21:58 +01:00
else
2025-02-03 23:17:31 +01:00
msg_error "Failed to install googletrans. Please check your internet connection."
2025-02-03 23:20:42 +01:00
if [ -n "$VIRTUAL_ENV" ]; then
deactivate
fi
2025-02-03 23:17:31 +01:00
exit 1
2025-02-02 19:21:58 +01:00
fi
2025-01-12 17:08:33 +01:00
2025-02-03 23:31:15 +01:00
2025-02-03 23:20:42 +01:00
if [ -n "$VIRTUAL_ENV" ]; then
deactivate
fi
2025-02-03 23:17:31 +01:00
2025-02-03 23:08:37 +01:00
# Download necessary files =================================
msg_ok "Necessary directories created."
2025-02-02 19:21:58 +01:00
mkdir -p "$BASE_DIR"
2024-12-20 21:44:20 +01:00
2025-02-02 19:21:58 +01:00
2025-02-03 23:08:37 +01:00
FILES=(
"$CACHE_FILE $REPO_URL/lang/cache.json"
"$UTILS_FILE $REPO_URL/scripts/utils.sh"
"$INSTALL_DIR/$MENU_SCRIPT $REPO_URL/$MENU_SCRIPT"
"$LOCAL_VERSION_FILE $REPO_URL/version.txt"
)
2025-02-02 19:21:58 +01:00
2025-02-03 23:08:37 +01:00
for file in "${FILES[@]}"; do
IFS=" " read -r dest url <<< "$file"
msg_info "Downloading ${dest##*/}..."
if wget -qO "$dest" "$url"; then
msg_ok "${dest##*/} downloaded successfully."
else
msg_error "Failed to download ${dest##*/}. Check your Internet connection."
exit 1
fi
done
2024-12-20 18:54:00 +01:00
2024-12-20 21:41:34 +01:00
2025-02-03 23:08:37 +01:00
chmod +x "$INSTALL_DIR/$MENU_SCRIPT"
2025-02-02 19:21:58 +01:00
2025-02-03 23:08:37 +01:00
# Installation complete ====================================
2025-02-02 19:21:58 +01:00
echo
echo -e "${YW}╭─────────────────────────────────────────────────────╮${CL}"
echo -e "${YW}${CL} ${GN}🌟 ProxMenux has been installed successfull 🌟 ${CL} ${YW}${CL}"
echo -e "${YW}╰─────────────────────────────────────────────────────╯${CL}"
echo
echo -ne "${GN}"
type_text "To run ProxMenu, simply execute this command in the console or terminal:"
echo -e "${YWB} menu.sh${CL}"
echo
2024-12-20 18:54:00 +01:00
2025-02-03 23:08:37 +01:00
if [ -f "$BASE_DIR/install_proxmenux.sh" ]; then
rm -f "$BASE_DIR/install_proxmenux.sh"
fi
2024-12-20 21:44:20 +01:00
exit 0