diff --git a/linux-managements/menu.sh b/linux-managements/menu.sh new file mode 100644 index 0000000..a53d042 --- /dev/null +++ b/linux-managements/menu.sh @@ -0,0 +1,87 @@ +#!/bin/bash +set -euo pipefail + +RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m' +BLUE='\033[0;34m'; CYAN='\033[0;36m'; BOLD='\033[1m'; NC='\033[0m' + +_NAMES=(); _DESCS=(); _URLS=() +add() { _NAMES+=("$1"); _DESCS+=("$2"); _URLS+=("$3"); } + +# ════════════════════════════════════════════════════════════════════════════════ +# CONFIGURATION — 在此处添加或修改脚本条目 +# 用法: add "<显示名称>" "<脚本说明>" "<脚本 URL>" +# ════════════════════════════════════════════════════════════════════════════════ + +add "Linux 初始化配置" \ + "配置 HTTP 代理、SSH 密钥、安装 Homebrew 及常用软件、配置 Fish Shell、同步 Dotfiles" \ + "https://git.mitsea.com/FlintyLemming/scripts-public/raw/branch/main/linux-managements/setup.sh" + +add "安装 Docker Engine(中国大陆服务器)" \ + "自动检测发行版,经由南洋理工镜像源安装 Docker Engine、Compose、Buildx 等组件" \ + "https://git.mitsea.com/FlintyLemming/scripts-public/raw/branch/main/linux-managements/install-docker.sh" + +add "配置 Snapper 快照" \ + "为 Btrfs 子卷配置 Snapper 自动快照,按天/周/月/年策略保留快照并启用 systemd 定时器" \ + "https://git.mitsea.com/FlintyLemming/scripts-public/raw/branch/main/linux-managements/setup-snapper.sh" + +# ════════════════════════════════════════════════════════════════════════════════ +# 以下为脚本逻辑,无需修改 +# ════════════════════════════════════════════════════════════════════════════════ + +draw_menu() { + echo -e "\n${BOLD}${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}" + echo -e "${BOLD}${BLUE}║ Linux Management Scripts ║${NC}" + echo -e "${BOLD}${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}\n" + + local total="${#_NAMES[@]}" + for (( i=0; i/dev/null; then + bash <(curl -fsSL "$url") + elif command -v wget &>/dev/null; then + bash <(wget -qO- "$url") + else + echo -e "${RED}[ERR]${NC} 未找到 curl 或 wget,无法下载脚本。" >&2 + exit 1 + fi +} + +main() { + local total="${#_NAMES[@]}" + + while true; do + draw_menu + read -rp "请选择要执行的脚本 [0-$total]: " choice + + if [[ "$choice" == "0" ]]; then + echo -e "\n${CYAN}[INFO]${NC} 已退出。\n" + exit 0 + fi + + if ! [[ "$choice" =~ ^[0-9]+$ ]] || (( choice < 1 || choice > total )); then + echo -e "\n${RED}[ERR]${NC} 无效选项,请输入 0 到 $total 之间的数字。\n" + continue + fi + + run_script $(( choice - 1 )) + break + done +} + +main