Files
ProxMenux/scripts/utilities/system_utils.sh

290 lines
11 KiB
Bash
Raw Normal View History

2025-06-30 18:54:16 +02:00
#!/bin/bash
# ==========================================================
2025-07-02 18:47:08 +02:00
# ProxMenux - A menu-driven script for Proxmox VE management
2025-06-30 18:54:16 +02:00
# ==========================================================
# Author : MacRimi
# Copyright : (c) 2024 MacRimi
2026-01-19 17:15:00 +01:00
# License : (GPL-3.0) (https://github.com/MacRimi/ProxMenux/blob/main/LICENSE)
2026-04-03 10:34:46 +02:00
# Version : 1.2
# Last Updated: 03/04/2026
2025-06-30 18:54:16 +02:00
# ==========================================================
# Description:
2026-04-03 10:34:46 +02:00
# This script provides an interactive system utilities installer with a
2025-06-30 18:54:16 +02:00
# comprehensive dialog-based interface for Proxmox VE and Linux systems.
2026-04-03 10:34:46 +02:00
# It simplifies the installation and management of essential command-line
2025-06-30 18:54:16 +02:00
# tools and utilities commonly used in server environments.
#
# The script offers both individual utility selection and predefined groups
# for different use cases, ensuring administrators can quickly set up their
# preferred toolset without manual package management.
#
# Supported utility categories:
# - Basic utilities: grc, htop, tree, curl, wget
# - Development tools: git, vim, nano, dos2unix
# - Compression tools: zip, unzip, rsync, cabextract
# - Network tools: iperf3, nmap, tcpdump, nethogs, iptraf-ng, sshpass
# - Analysis tools: jq, ncdu, iotop, btop, iftop
2026-04-03 10:34:46 +02:00
# - System tools: plocate, net-tools, ipset, msr-tools
2025-06-30 18:54:16 +02:00
# - Virtualization tools: libguestfs-tools, wimtools, genisoimage, chntpw
# - Download tools: axel, aria2
#
# The script automatically handles package name differences across distributions
# and provides detailed feedback on installation success, warnings, and failures.
#
2025-07-30 18:18:13 +02:00
# Configuration ============================================
LOCAL_SCRIPTS="/usr/local/share/proxmenux/scripts"
2025-06-30 18:54:16 +02:00
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
2025-07-30 18:18:13 +02:00
2025-06-30 18:54:16 +02:00
load_language
initialize_cache
2026-04-03 10:34:46 +02:00
# Load shared utility installation functions
if [[ -f "$LOCAL_SCRIPTS/global/utils-install-functions.sh" ]]; then
source "$LOCAL_SCRIPTS/global/utils-install-functions.sh"
fi
2025-06-30 18:54:16 +02:00
2025-07-30 18:18:13 +02:00
# ==========================================================
2025-06-30 18:54:16 +02:00
install_system_utils() {
show_main_utilities_menu() {
local choice
2025-07-02 18:47:08 +02:00
choice=$(dialog --clear --backtitle "ProxMenux" \
2025-07-30 18:18:13 +02:00
--title "$(translate "Utilities Installation Menu")" \
--menu "$(translate "Select an option"):" 20 70 12 \
"1" "$(translate "Custom selection")" \
"2" "$(translate "Install ALL utilities")" \
"3" "$(translate "Install basic utilities") (grc, htop, tree, curl, wget)" \
"4" "$(translate "Install development tools") (git, vim, nano)" \
"5" "$(translate "Install compression tools") (zip, unzip, rsync)" \
"6" "$(translate "Install terminal multiplexers") (screen, tmux)" \
"7" "$(translate "Install analysis tools") (jq, ncdu, iotop)" \
2026-04-03 10:34:46 +02:00
"8" "$(translate "Install network tools") (iperf3, nethogs, nmap, tcpdump)" \
2025-07-30 18:18:13 +02:00
"9" "$(translate "Verify installations")" \
"0" "$(translate "Return to main menu")" 2>&1 >/dev/tty)
2025-06-30 18:54:16 +02:00
echo "$choice"
}
show_custom_selection() {
2026-04-03 10:34:46 +02:00
local utilities=()
for util_entry in "${PROXMENUX_UTILS[@]}"; do
IFS=':' read -r pkg cmd desc <<< "$util_entry"
utilities+=("$pkg" "$(translate "$desc")" "OFF")
done
2025-06-30 18:54:16 +02:00
local selected
2025-07-02 18:47:08 +02:00
selected=$(dialog --clear --backtitle "ProxMenux" \
2025-07-30 18:18:13 +02:00
--title "$(translate "Select utilities to install")" \
--checklist "$(translate "Use SPACE to select/deselect, ENTER to confirm")" \
25 80 20 "${utilities[@]}" 2>&1 >/dev/tty)
2025-06-30 18:54:16 +02:00
echo "$selected"
}
install_utility_group() {
local group_name="$1"
shift
local utilities=("$@")
2026-04-03 10:34:46 +02:00
2025-06-30 18:54:16 +02:00
clear
2025-07-30 18:18:13 +02:00
show_proxmenux_logo
2025-06-30 18:54:16 +02:00
msg_title "$(translate "Installing group"): $group_name"
2026-04-03 10:34:46 +02:00
2025-07-30 18:18:13 +02:00
if ! ensure_repositories; then
msg_error "$(translate "Failed to configure repositories. Installation aborted.")"
return 1
fi
2026-04-03 10:34:46 +02:00
local failed=0 success=0 warning=0
2025-06-30 18:54:16 +02:00
for util_info in "${utilities[@]}"; do
IFS=':' read -r package command description <<< "$util_info"
2026-04-03 10:34:46 +02:00
install_single_package "$package" "$command" "$description"
case $? in
2025-06-30 18:54:16 +02:00
0) success=$((success + 1)) ;;
1) failed=$((failed + 1)) ;;
2) warning=$((warning + 1)) ;;
esac
2025-08-04 08:52:55 +02:00
sleep 2
2025-06-30 18:54:16 +02:00
done
2026-04-03 10:34:46 +02:00
2025-06-30 18:54:16 +02:00
echo
msg_info2 "$(translate "Installation summary") - $group_name:"
msg_ok "$(translate "Successful"): $success"
[ $warning -gt 0 ] && msg_warn "$(translate "With warnings"): $warning"
[ $failed -gt 0 ] && msg_error "$(translate "Failed"): $failed"
2026-04-03 10:34:46 +02:00
2025-07-02 18:47:08 +02:00
dialog --clear --backtitle "ProxMenux" \
2025-07-30 18:18:13 +02:00
--title "$(translate "Installation Complete")" \
--msgbox "$(translate "Group"): $group_name\n$(translate "Successful"): $success\n$(translate "With warnings"): $warning\n$(translate "Failed"): $failed" 10 50
2025-06-30 18:54:16 +02:00
}
install_selected_utilities() {
local selected="$1"
2026-04-03 10:34:46 +02:00
2025-06-30 18:54:16 +02:00
if [ -z "$selected" ]; then
2025-07-02 18:47:08 +02:00
dialog --clear --backtitle "ProxMenux" \
2025-07-30 18:18:13 +02:00
--title "$(translate "No Selection")" \
--msgbox "$(translate "No utilities were selected")" 8 40
2025-06-30 18:54:16 +02:00
return
fi
2026-04-03 10:34:46 +02:00
2025-06-30 18:54:16 +02:00
clear
2025-07-30 18:18:13 +02:00
show_proxmenux_logo
2025-06-30 18:54:16 +02:00
msg_title "$(translate "Installing selected utilities")"
2025-08-06 22:02:40 +02:00
2025-07-30 18:18:13 +02:00
if ! ensure_repositories; then
msg_error "$(translate "Failed to configure repositories. Installation aborted.")"
return 1
fi
2026-04-03 10:34:46 +02:00
# Build lookup table from global PROXMENUX_UTILS
declare -A pkg_cmd_map pkg_desc_map
for util_entry in "${PROXMENUX_UTILS[@]}"; do
IFS=':' read -r epkg ecmd edesc <<< "$util_entry"
pkg_cmd_map[$epkg]="$ecmd"
pkg_desc_map[$epkg]="$edesc"
done
local failed=0 success=0 warning=0
2025-06-30 18:54:16 +02:00
local selected_array
IFS=' ' read -ra selected_array <<< "$selected"
2026-04-03 10:34:46 +02:00
2025-06-30 18:54:16 +02:00
for util in "${selected_array[@]}"; do
util=$(echo "$util" | tr -d '"')
2026-04-03 10:34:46 +02:00
local verify_command="${pkg_cmd_map[$util]:-$util}"
local description="${pkg_desc_map[$util]:-$util}"
install_single_package "$util" "$verify_command" "$description"
case $? in
2025-06-30 18:54:16 +02:00
0) success=$((success + 1)) ;;
1) failed=$((failed + 1)) ;;
2) warning=$((warning + 1)) ;;
esac
2025-08-04 08:52:55 +02:00
sleep 2
2025-06-30 18:54:16 +02:00
done
2026-04-03 10:34:46 +02:00
2025-07-30 18:18:13 +02:00
hash -r 2>/dev/null
2025-06-30 18:54:16 +02:00
echo
msg_info2 "$(translate "Installation summary"):"
msg_ok "$(translate "Successful"): $success"
[ $warning -gt 0 ] && msg_warn "$(translate "With warnings"): $warning"
[ $failed -gt 0 ] && msg_error "$(translate "Failed"): $failed"
2026-04-03 10:34:46 +02:00
2025-07-02 18:47:08 +02:00
dialog --clear --backtitle "ProxMenux" \
2025-07-30 18:18:13 +02:00
--title "$(translate "Installation Complete")" \
--msgbox "$(translate "Selected utilities installation completed")\n$(translate "Successful"): $success\n$(translate "With warnings"): $warning\n$(translate "Failed"): $failed" 12 60
2025-06-30 18:54:16 +02:00
}
verify_installations() {
clear
show_proxmenux_logo
msg_info "$(translate "Verifying all utilities status")..."
2026-04-03 10:34:46 +02:00
local available=0 missing=0 status_text=""
for util_entry in "${PROXMENUX_UTILS[@]}"; do
IFS=':' read -r pkg cmd desc <<< "$util_entry"
if command -v "$cmd" >/dev/null 2>&1; then
2025-06-30 18:54:16 +02:00
status_text+="\n✓ $cmd - $desc"
available=$((available + 1))
else
status_text+="\n✗ $cmd - $desc"
missing=$((missing + 1))
fi
done
2026-04-03 10:34:46 +02:00
2025-06-30 18:54:16 +02:00
cleanup
2026-04-03 10:34:46 +02:00
2025-06-30 18:54:16 +02:00
local summary="$(translate "Total"): $((available + missing))\n$(translate "Available"): $available\n$(translate "Missing"): $missing"
2026-04-03 10:34:46 +02:00
2025-07-02 18:47:08 +02:00
dialog --clear --backtitle "ProxMenux" \
2025-07-30 18:18:13 +02:00
--title "$(translate "Utilities Verification")" \
--msgbox "$summary$status_text" 25 80
2025-06-30 18:54:16 +02:00
}
2025-07-30 18:18:13 +02:00
# Main menu loop
2025-06-30 18:54:16 +02:00
while true; do
choice=$(show_main_utilities_menu)
case $choice in
1)
selected=$(show_custom_selection)
install_selected_utilities "$selected"
;;
2)
2026-04-03 10:34:46 +02:00
install_utility_group "$(translate "ALL Utilities")" "${PROXMENUX_UTILS[@]}"
2025-07-30 18:18:13 +02:00
;;
2025-06-30 18:54:16 +02:00
3)
basic_utils=(
"grc:grc:Generic Colouriser"
"htop:htop:Process monitor"
"tree:tree:Directory structure"
"curl:curl:Data transfer"
"wget:wget:Web downloader"
)
install_utility_group "$(translate "Basic Utilities")" "${basic_utils[@]}"
;;
4)
dev_utils=(
"git:git:Version control"
"vim:vim:Advanced editor"
"nano:nano:Simple editor"
)
install_utility_group "$(translate "Development Tools")" "${dev_utils[@]}"
;;
5)
compress_utils=(
"zip:zip:ZIP compressor"
"unzip:unzip:ZIP extractor"
"rsync:rsync:File synchronizer"
)
install_utility_group "$(translate "Compression Tools")" "${compress_utils[@]}"
;;
6)
multiplex_utils=(
"screen:screen:Terminal multiplexer"
"tmux:tmux:Advanced multiplexer"
)
install_utility_group "$(translate "Terminal Multiplexers")" "${multiplex_utils[@]}"
;;
7)
analysis_utils=(
"jq:jq:JSON processor"
"ncdu:ncdu:Disk analyzer"
"iotop:iotop:I/O monitor"
)
install_utility_group "$(translate "Analysis Tools")" "${analysis_utils[@]}"
;;
8)
network_utils=(
2026-04-03 10:34:46 +02:00
"iperf3:iperf3:Network bandwidth testing"
"nethogs:nethogs:Network monitor per process"
2025-06-30 18:54:16 +02:00
"nmap:nmap:Network scanner"
"tcpdump:tcpdump:Packet analyzer"
2026-04-03 10:34:46 +02:00
"lsof:lsof:Open files and ports"
2025-06-30 18:54:16 +02:00
)
install_utility_group "$(translate "Network Tools")" "${network_utils[@]}"
;;
9)
verify_installations
;;
0|"")
break
;;
*)
2025-07-02 18:47:08 +02:00
dialog --clear --backtitle "ProxMenux" \
2025-07-30 18:18:13 +02:00
--title "$(translate "Invalid Option")" \
--msgbox "$(translate "Please select a valid option")" 8 40
2025-06-30 18:54:16 +02:00
;;
esac
done
2026-04-03 10:34:46 +02:00
2025-06-30 18:54:16 +02:00
clear
}
2025-07-30 18:18:13 +02:00
install_system_utils