#!/bin/bash set -e OS_TYPE="$(uname -s)" is_windows() { [[ "$OS_TYPE" == MINGW* || "$OS_TYPE" == MSYS* ]]; } BASE_URL="https://cnb.cool/ninvfeng/aibox/docker/-/git/raw/main/scripts" COMPONENTS=(docker nodejs php redis agent-browser openclaw uv openscad tmux ohmyzsh 1panel espidf skill go claude) # 检测是否为国内网络,若是则将默认国外 apt 源替换为国内镜像 setup_china_apt_mirror() { # curl google.com 3秒超时,能正常返回说明可直连外网,无需替换 if curl -sS --connect-timeout 3 --max-time 3 -o /dev/null -w "%{http_code}" https://google.com 2>/dev/null | grep -qE "^(200|301|302)$"; then return fi echo "==> Detected China network, switching apt to mirrors.aliyun.com ..." # 获取发行版代号(如 bookworm、jammy) local codename codename=$(. /etc/os-release && echo "$VERSION_CODENAME") [ -z "$codename" ] && return # 判断发行版类型 local distro distro=$(. /etc/os-release && echo "$ID") if [ "$distro" = "ubuntu" ]; then # 传统 sources.list 格式 if [ -f /etc/apt/sources.list ] && grep -q "archive.ubuntu.com\|security.ubuntu.com" /etc/apt/sources.list; then sed -i 's|archive.ubuntu.com|mirrors.aliyun.com|g; s|security.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list fi # DEB822 格式 for f in /etc/apt/sources.list.d/*.sources; do [ -f "$f" ] && grep -q "archive.ubuntu.com\|security.ubuntu.com" "$f" && \ sed -i 's|archive.ubuntu.com|mirrors.aliyun.com|g; s|security.ubuntu.com|mirrors.aliyun.com|g' "$f" done elif [ "$distro" = "debian" ]; then # 传统 sources.list 格式 if [ -f /etc/apt/sources.list ] && grep -q "deb.debian.org" /etc/apt/sources.list; then sed -i 's|deb.debian.org/debian-security|mirrors.aliyun.com/debian-security|g; s|deb.debian.org/debian|mirrors.aliyun.com/debian|g' /etc/apt/sources.list fi # DEB822 格式 for f in /etc/apt/sources.list.d/*.sources; do [ -f "$f" ] && grep -q "deb.debian.org" "$f" && \ sed -i 's|deb.debian.org/debian-security|mirrors.aliyun.com/debian-security|g; s|deb.debian.org/debian|mirrors.aliyun.com/debian|g' "$f" done fi echo "==> apt mirror switched to mirrors.aliyun.com" } if ! is_windows; then setup_china_apt_mirror fi show_help() { echo "Usage: curl https://shell.ninvfeng.com | bash -s " echo "" echo "Available components:" for c in "${COMPONENTS[@]}"; do echo " - $c" done echo "" echo "Examples:" echo " curl https://shell.ninvfeng.com | bash -s php redis" echo " curl https://shell.ninvfeng.com | bash -s uv" } install_component() { local name="$1" local url="${BASE_URL}/install-${name}.sh" echo "==> Installing ${name} ..." curl -fsSL "$url" | bash # 重新加载 PATH,使刚安装的组件对后续步骤可见 [ -f ~/.bashrc ] && . ~/.bashrc 2>/dev/null || true echo "==> ${name} done." echo "" } if [ $# -eq 0 ]; then show_help exit 0 fi for arg in "$@"; do matched=false for c in "${COMPONENTS[@]}"; do if [ "$arg" = "$c" ]; then matched=true break fi done if [ "$matched" = false ]; then echo "Unknown component: $arg" show_help exit 1 fi install_component "$arg" done