From dc1475c64a37c40ff07df1bd3843b28e2292b7e2 Mon Sep 17 00:00:00 2001 From: Hyko Date: Tue, 12 May 2026 18:16:33 -0400 Subject: [PATCH] refactor: extract interactive menus into dedicated index scripts - move apps menu from inline lxs.sh function to apps/index.sh - add tools/index.sh as entry point for tools menu - rename system-tools.sh to system-infos.sh - simplify help text to point users to the interactive menu - update README directory tree to reflect new structure --- README.md | 4 +- apps/index.sh | 86 +++++++++++++++++++++++++++++++++++++++++++ lxs.sh | 58 ++++------------------------- tools/index.sh | 83 +++++++++++++++++++++++++++++++++++++++++ tools/system-infos.sh | 62 ++++--------------------------- 5 files changed, 188 insertions(+), 105 deletions(-) create mode 100755 apps/index.sh create mode 100755 tools/index.sh diff --git a/README.md b/README.md index 857d1e2..9b9e57b 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,15 @@ lxs/ ├── lib/ │ └── common.sh # Shared helpers (colors, loggers, spinner) ├── apps/ # Application installers +│ ├── index.sh # Interactive menu listing the apps below │ ├── coolify.sh │ ├── pterodactyl.sh │ ├── uptime-kuma.sh │ ├── cloudpanel.sh │ └── proxmox.sh └── tools/ # System tools - ├── system-tools.sh + ├── index.sh # Interactive menu listing the tools below + ├── system-infos.sh ├── server-benchmark.sh └── harden.sh ``` diff --git a/apps/index.sh b/apps/index.sh new file mode 100755 index 0000000..668ae67 --- /dev/null +++ b/apps/index.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# LXS - Apps index +# Description: Interactive menu listing the application installers in apps/ +# Author: LXS +# Date: 2025 + +# Load LXS common library (colors, separator, run_spinner, loggers) +LXS_RAW_BASE="${LXS_RAW_BASE:-https://git.hyko.cx/hykocx/lxs/raw/branch/main}" +_lib=$(curl -fsSL "${LXS_RAW_BASE}/lib/common.sh") || { echo "Failed to fetch lib/common.sh" >&2; exit 1; } +eval "$_lib" +unset _lib + +# Run a sibling app script. Prefers a file next to this script (installed +# layout); falls back to downloading from LXS_RAW_BASE. +run_sibling() { + local script_path=$1 + shift + local script_name self_dir resolved src="${BASH_SOURCE[0]}" + script_name=$(basename "$script_path") + + if [ -n "$src" ]; then + resolved=$(readlink -f "$src" 2>/dev/null) \ + || resolved=$(realpath "$src" 2>/dev/null) \ + || resolved="$src" + self_dir=$(dirname "$resolved") + fi + + if [ -n "$self_dir" ] && [ -f "${self_dir}/${script_name}" ]; then + chmod +x "${self_dir}/${script_name}" 2>/dev/null || true + "${self_dir}/${script_name}" "$@" + return $? + fi + + local temp_file exit_code + temp_file=$(mktemp "/tmp/lxs.${script_name%.*}.XXXXXX.sh") + echo -e "${PURPLE}[*] Downloading ${BOLD}${script_name}${NC}${PURPLE}...${NC}" + if curl -fsSL -H "Cache-Control: no-cache" -o "${temp_file}" "${LXS_RAW_BASE}/${script_path}"; then + echo -e "${GREEN}[✓] Downloaded${NC}" + chmod +x "${temp_file}" + "${temp_file}" "$@" + exit_code=$? + rm -f "${temp_file}" + return $exit_code + else + echo -e "${RED}[✗] Failed to download ${script_path}${NC}" + rm -f "${temp_file}" + return 1 + fi +} + +menu_apps() { + while true; do + clear + echo -e "${WHITE}╔═══════════════════════════════════════════════════════╗${NC}" + echo -e "${WHITE}║ APPLICATIONS ║${NC}" + echo -e "${WHITE}╚═══════════════════════════════════════════════════════╝${NC}" + echo "" + echo -e " ${GREEN}[1]${NC} Coolify" + echo -e " ${GREEN}[2]${NC} Pterodactyl Panel" + echo -e " ${GREEN}[3]${NC} Uptime Kuma" + echo -e " ${GREEN}[4]${NC} CloudPanel" + echo -e " ${GREEN}[5]${NC} Proxmox VE Tools" + echo -e " ${RED}[0]${NC} Back" + echo "" + echo -e -n "${BOLD}Choice [0-5]: ${NC}" + read -r choice + + case $choice in + 1) run_sibling "apps/coolify.sh" ;; + 2) run_sibling "apps/pterodactyl.sh" ;; + 3) run_sibling "apps/uptime-kuma.sh" ;; + 4) run_sibling "apps/cloudpanel.sh" ;; + 5) run_sibling "apps/proxmox.sh" ;; + 0) return ;; + *) echo -e "${RED}[✗] Invalid option. Please select 0-5.${NC}"; sleep 1; continue ;; + esac + + if [ "$choice" != "0" ]; then + echo "" + read -r -p "Press Enter to continue..." + fi + done +} + +menu_apps diff --git a/lxs.sh b/lxs.sh index 46f4b70..5e3e749 100755 --- a/lxs.sh +++ b/lxs.sh @@ -252,7 +252,7 @@ cmd_help() { LXS - Linux multi-tool (v${LXS_VERSION}) Usage: - lxs Interactive menu + lxs Interactive menu (browse apps and tools) lxs setup Install lxs and all sub-scripts to ${LXS_INSTALL_DIR} lxs update Update all installed files to latest lxs install Install an application @@ -261,17 +261,7 @@ Usage: lxs version Show version lxs help Show this help -Applications (lxs install ...): - coolify Self-hosted PaaS - pterodactyl Game server management panel - uptime-kuma Monitoring tool - cloudpanel Web hosting control panel - proxmox Proxmox VE management tools - -Tools (lxs tool ...): - system System monitoring and diagnostics - benchmark Server benchmark (CPU/RAM/disk/network) - harden Baseline hardening (UFW + fail2ban + SSH key-only + auto-updates) +Run \`lxs\` for the interactive menu to browse available applications and tools. Source: ${LXS_REPO_URL} EOF @@ -294,7 +284,7 @@ cmd_tool() { local tool="${1:-}" shift || true case "$tool" in - system) download_and_run "tools/system-tools.sh" "$@" ;; + system) download_and_run "tools/system-infos.sh" "$@" ;; benchmark) download_and_run "tools/server-benchmark.sh" "$@" ;; harden) download_and_run "tools/harden.sh" "$@" ;; "") echo -e "${RED}[✗] Missing tool name. Try: lxs help${NC}"; return 1 ;; @@ -381,41 +371,9 @@ cmd_install_self() { } # ═══════════════════════════════════════════════════════════════════════════ -# Interactive menus +# Interactive menu # ═══════════════════════════════════════════════════════════════════════════ -menu_install_apps() { - while true; do - show_header - echo -e "${WHITE}${BOLD}APPLICATIONS${NC}" - echo "" - echo -e " ${GREEN}[1]${NC} Coolify" - echo -e " ${GREEN}[2]${NC} Pterodactyl Panel" - echo -e " ${GREEN}[3]${NC} Uptime Kuma" - echo -e " ${GREEN}[4]${NC} CloudPanel" - echo -e " ${GREEN}[5]${NC} Proxmox VE Tools" - echo -e " ${RED}[0]${NC} Back" - echo "" - echo -e -n "${BOLD}Choice [0-5]: ${NC}" - read -r choice - - case $choice in - 1) download_and_run "apps/coolify.sh" ;; - 2) download_and_run "apps/pterodactyl.sh" ;; - 3) download_and_run "apps/uptime-kuma.sh" ;; - 4) download_and_run "apps/cloudpanel.sh" ;; - 5) download_and_run "apps/proxmox.sh" ;; - 0) return ;; - *) echo -e "${RED}[✗] Invalid option. Please select 0-5.${NC}"; sleep 1 ;; - esac - - if [ "$choice" != "0" ]; then - echo "" - read -r -p "Press Enter to continue..." - fi - done -} - main_menu() { check_os check_remote_version @@ -424,7 +382,7 @@ main_menu() { echo -e "${WHITE}${BOLD}MAIN MENU${NC}" echo "" echo -e " ${GREEN}[1]${NC} Applications" - echo -e " ${CYAN}[2]${NC} System Tools" + echo -e " ${CYAN}[2]${NC} Tools" echo -e " ${GRAY}[u]${NC} Update lxs" echo -e " ${RED}[0]${NC} Exit" echo "" @@ -432,8 +390,8 @@ main_menu() { read -r choice case $choice in - 1) menu_install_apps ;; - 2) download_and_run "tools/system-tools.sh" ;; + 1) download_and_run "apps/index.sh" ;; + 2) download_and_run "tools/index.sh" ;; u|U) cmd_update ;; 0) clear @@ -444,7 +402,7 @@ main_menu() { *) echo -e "${RED}[✗] Invalid option.${NC}"; sleep 1 ;; esac - if [[ "$choice" != "0" && "$choice" != "1" ]]; then + if [[ "$choice" != "0" && "$choice" != "1" && "$choice" != "2" ]]; then echo "" read -r -p "Press Enter to continue..." fi diff --git a/tools/index.sh b/tools/index.sh new file mode 100755 index 0000000..41cb4f2 --- /dev/null +++ b/tools/index.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# LXS - Tools index +# Description: Interactive menu listing the scripts in tools/ +# Author: LXS +# Date: 2025 + +# Load LXS common library (colors, separator, run_spinner, loggers) +LXS_RAW_BASE="${LXS_RAW_BASE:-https://git.hyko.cx/hykocx/lxs/raw/branch/main}" +_lib=$(curl -fsSL "${LXS_RAW_BASE}/lib/common.sh") || { echo "Failed to fetch lib/common.sh" >&2; exit 1; } +eval "$_lib" +unset _lib + +# Run a sibling tool script. Prefers a file next to this script (installed +# layout); falls back to downloading from LXS_RAW_BASE. +run_sibling() { + local script_path=$1 + shift + local script_name self_dir resolved src="${BASH_SOURCE[0]}" + script_name=$(basename "$script_path") + + if [ -n "$src" ]; then + resolved=$(readlink -f "$src" 2>/dev/null) \ + || resolved=$(realpath "$src" 2>/dev/null) \ + || resolved="$src" + self_dir=$(dirname "$resolved") + fi + + # self_dir points at tools/; the install layout puts siblings here too. + if [ -n "$self_dir" ] && [ -f "${self_dir}/${script_name}" ]; then + chmod +x "${self_dir}/${script_name}" 2>/dev/null || true + "${self_dir}/${script_name}" "$@" + return $? + fi + + local temp_file exit_code + temp_file=$(mktemp "/tmp/lxs.${script_name%.*}.XXXXXX.sh") + echo -e "${PURPLE}[*] Downloading ${BOLD}${script_name}${NC}${PURPLE}...${NC}" + if curl -fsSL -H "Cache-Control: no-cache" -o "${temp_file}" "${LXS_RAW_BASE}/${script_path}"; then + echo -e "${GREEN}[✓] Downloaded${NC}" + chmod +x "${temp_file}" + "${temp_file}" "$@" + exit_code=$? + rm -f "${temp_file}" + return $exit_code + else + echo -e "${RED}[✗] Failed to download ${script_path}${NC}" + rm -f "${temp_file}" + return 1 + fi +} + +menu_tools() { + while true; do + clear + echo -e "${WHITE}╔═══════════════════════════════════════════════════════╗${NC}" + echo -e "${WHITE}║ TOOLS ║${NC}" + echo -e "${WHITE}╚═══════════════════════════════════════════════════════╝${NC}" + echo "" + echo -e " ${CYAN}[1]${NC} System Infos" + echo -e " ${PURPLE}[2]${NC} Server Benchmark" + echo -e " ${YELLOW}[3]${NC} Harden Server" + echo -e " ${RED}[0]${NC} Back" + echo "" + echo -e -n "${BOLD}Choice [0-3]: ${NC}" + read -r choice + + case $choice in + 1) run_sibling "tools/system-infos.sh" ;; + 2) run_sibling "tools/server-benchmark.sh" ;; + 3) run_sibling "tools/harden.sh" ;; + 0) return ;; + *) echo -e "${RED}[✗] Invalid option. Please select 0-3.${NC}"; sleep 1; continue ;; + esac + + if [ "$choice" != "0" ]; then + echo "" + read -r -p "Press Enter to continue..." + fi + done +} + +menu_tools diff --git a/tools/system-infos.sh b/tools/system-infos.sh index 2351c79..2b973ed 100755 --- a/tools/system-infos.sh +++ b/tools/system-infos.sh @@ -1,6 +1,6 @@ #!/bin/bash -# LXS - System Tools +# LXS - System Infos # Description: Essential system monitoring and diagnostic tools # Author: LXS # Date: 2025 @@ -10,52 +10,14 @@ LXS_RAW_BASE="${LXS_RAW_BASE:-https://git.hyko.cx/hykocx/lxs/raw/branch/main}" _lib=$(curl -fsSL "${LXS_RAW_BASE}/lib/common.sh") || { echo "Failed to fetch lib/common.sh" >&2; exit 1; } eval "$_lib" unset _lib -export LXS_LOG_FILE="/tmp/lxs_system_tools.log" +export LXS_LOG_FILE="/tmp/lxs_system_infos.log" -# Run a sibling tool script. Prefers a file next to this script (installed -# layout); falls back to downloading from LXS_RAW_BASE. -run_sibling() { - local script_path=$1 - shift - local script_name self_dir resolved src="${BASH_SOURCE[0]}" - script_name=$(basename "$script_path") - - if [ -n "$src" ]; then - resolved=$(readlink -f "$src" 2>/dev/null) \ - || resolved=$(realpath "$src" 2>/dev/null) \ - || resolved="$src" - self_dir=$(dirname "$resolved") - fi - - if [ -n "$self_dir" ] && [ -f "${self_dir}/${script_name}" ]; then - chmod +x "${self_dir}/${script_name}" 2>/dev/null || true - "${self_dir}/${script_name}" "$@" - return $? - fi - - local temp_file exit_code - temp_file=$(mktemp "/tmp/lxs.${script_name%.*}.XXXXXX.sh") - echo -e "${PURPLE}[*] Downloading ${BOLD}${script_name}${NC}${PURPLE}...${NC}" - if curl -fsSL -H "Cache-Control: no-cache" -o "${temp_file}" "${LXS_RAW_BASE}/${script_path}"; then - echo -e "${GREEN}[✓] Downloaded${NC}" - chmod +x "${temp_file}" - "${temp_file}" "$@" - exit_code=$? - rm -f "${temp_file}" - return $exit_code - else - echo -e "${RED}[✗] Failed to download ${script_path}${NC}" - rm -f "${temp_file}" - return 1 - fi -} - -# Menu: System Tools -menu_system_tools() { +# Menu: System Infos +menu_system_infos() { while true; do clear echo -e "${WHITE}╔═══════════════════════════════════════════════════════╗${NC}" - echo -e "${WHITE}║ SYSTEM TOOLS ║${NC}" + echo -e "${WHITE}║ SYSTEM INFOS ║${NC}" echo -e "${WHITE}╚═══════════════════════════════════════════════════════╝${NC}" echo "" echo -e " ${CYAN}[1]${NC} View system informations" @@ -66,11 +28,9 @@ menu_system_tools() { echo -e " ${CYAN}[6]${NC} View system logs (last 50 lines)" echo -e " ${CYAN}[7]${NC} Show top resource-consuming processes" echo -e " ${CYAN}[8]${NC} Check disk health (SMART)" - echo -e " ${PURPLE}[9]${NC} Server Benchmark" - echo -e " ${YELLOW}[10]${NC} Harden Server" echo -e " ${RED}[0]${NC} Exit" echo "" - echo -e -n "${BOLD}Choice [0-10]: ${NC}" + echo -e -n "${BOLD}Choice [0-8]: ${NC}" read -r choice echo "" @@ -306,17 +266,11 @@ menu_system_tools() { fi fi ;; - 9) - run_sibling "tools/server-benchmark.sh" - ;; - 10) - run_sibling "tools/harden.sh" - ;; 0) exit 0 ;; *) - echo -e "${RED}[✗] Invalid option. Please select 0-10.${NC}" + echo -e "${RED}[✗] Invalid option. Please select 0-8.${NC}" sleep 2 continue ;; @@ -329,5 +283,5 @@ menu_system_tools() { done } -menu_system_tools +menu_system_infos