This commit is contained in:
eric
2026-03-29 01:17:00 -05:00
parent af927c6dca
commit 8bce529255
10 changed files with 775 additions and 300 deletions

View File

@@ -16,6 +16,23 @@ log() {
printf '[%s] %s\n' "$INSTALL_TAG" "$*"
}
# 网络/镜像波动时重试(不退出整段安装)
retry_run() {
local max="${1:-3}"
local delay="${2:-3}"
shift 2
local n=0
while [ "$n" -lt "$max" ]; do
if "$@"; then
return 0
fi
n=$((n + 1))
log "retry ${n}/${max} failed command: $*"
sleep "$delay"
done
return 1
}
ensure_root() {
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
exec sudo -E bash "$0" "$@"
@@ -38,6 +55,13 @@ apt_update_once() {
apt_install() {
apt_update_once
if apt-get install -y --no-install-recommends "$@"; then
return 0
fi
log "apt install failed; trying dpkg --configure -a and apt -f install"
export DEBIAN_FRONTEND=noninteractive
dpkg --configure -a 2>/dev/null || true
apt-get -f install -y || true
apt-get install -y --no-install-recommends "$@"
}
@@ -123,7 +147,10 @@ ensure_live_user() {
useradd -m -s /bin/bash live
fi
echo "live:12345678" | chpasswd
usermod -aG sudo,audio,video,plugdev,render,gpio,spidev,pwm,i2c,docker live 2>/dev/null || true
usermod -aG sudo,audio,video,plugdev,render,gpio,spidev,pwm,i2c live 2>/dev/null || true
if getent group docker >/dev/null 2>&1; then
usermod -aG docker live 2>/dev/null || true
fi
}
install_base_packages() {
@@ -153,9 +180,23 @@ install_nodejs() {
return 0
fi
fi
log "Installing Node.js 20"
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt_install nodejs
log "Installing Node.js (prefer 20.x from NodeSource)"
if retry_run 3 5 bash -c 'curl -fsSL https://deb.nodesource.com/setup_20.x | bash -'; then
apt_install nodejs || true
else
log "NodeSource unavailable; using distribution nodejs"
apt_install nodejs npm || apt_install nodejs || true
fi
if have node; then
major="$(node -p "process.versions.node.split('.')[0]" 2>/dev/null || echo 0)"
case "$major" in
''|*[!0-9]*) log "WARN: could not parse Node major version" ;;
*) [ "$major" -lt 20 ] && log "WARN: Node major=$major (web-console expects >=20); upgrade manually if build fails" ;;
esac
return 0
fi
log "WARN: Node.js not installed; web-console build may fail on this distro"
return 0
}
install_docker_stack() {
@@ -174,13 +215,26 @@ install_docker_stack() {
prepare_python_runtime() {
log "Preparing Python virtual environment"
chown -R live:live "$ROOT_DIR"
as_live "python3 -m venv .venv"
as_live ". .venv/bin/activate && pip install --upgrade pip && pip install -r requirements.txt"
as_live "python3 -m venv .venv" || {
log "venv create failed; retry once with --clear"
rm -rf "$ROOT_DIR/.venv"
as_live "python3 -m venv .venv" || log "WARN: venv still failed"
}
if ! as_live ". .venv/bin/activate && pip install --upgrade pip && pip install -r requirements.txt"; then
log "pip install failed; retry with --no-cache-dir"
as_live ". .venv/bin/activate && pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt" || \
log "WARN: Python deps incomplete; control plane may fail until fixed manually"
fi
}
prepare_web_console() {
log "Building web console"
as_live "cd web-console && if [ -f package-lock.json ]; then npm ci; else npm install; fi && npm run build"
if as_live "cd web-console && if [ -f package-lock.json ]; then npm ci; else npm install; fi && npm run build"; then
return 0
fi
log "web console build failed; cleaning node_modules and retrying"
as_live "cd web-console && rm -rf node_modules .next && npm install && npm run build" || \
log "WARN: web console build still failed — service may serve stale assets until rebuilt"
}
install_live_console_service() {
@@ -383,20 +437,25 @@ install_shellcrash() {
return 0
fi
log "Installing ShellCrash"
local url
local url ok=0
rm -f /tmp/install_shellcrash.sh
for url in \
'https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@dev' \
'https://raw.githubusercontent.com/juewuy/ShellCrash/dev'
do
if wget -q --no-check-certificate -O /tmp/install_shellcrash.sh "$url/install_en.sh" && [ -s /tmp/install_shellcrash.sh ]; then
if retry_run 2 4 wget -q --no-check-certificate -O /tmp/install_shellcrash.sh "$url/install_en.sh" && [ -s /tmp/install_shellcrash.sh ]; then
ok=1
break
fi
done
if [ ! -s /tmp/install_shellcrash.sh ]; then
log "ShellCrash installer download failed"
return 1
if [ "$ok" != "1" ] || [ ! -s /tmp/install_shellcrash.sh ]; then
log "ShellCrash installer download failed — continuing hub install (proxy later or set ENABLE_SHELLCRASH=0)"
return 0
fi
if ! printf '1\n1\n1\n1\n' | bash /tmp/install_shellcrash.sh; then
log "ShellCrash install script returned error — continuing; configure manually under $SHELLCRASH_DIR if needed"
return 0
fi
printf '1\n1\n1\n1\n' | bash /tmp/install_shellcrash.sh
}
install_browser_stack() {
@@ -438,8 +497,8 @@ install_neko_browser() {
mkdir -p "$neko_prof"
chmod 777 "$neko_prof" 2>/dev/null || true
export NEKO_HTTP_PORT="${NEKO_HTTP_PORT:-9200}"
export NEKO_USER_PASS="${NEKO_USER_PASS:-live}"
export NEKO_ADMIN_PASS="${NEKO_ADMIN_PASS:-admin}"
export NEKO_USER_PASS="${NEKO_USER_PASS:-12345678}"
export NEKO_ADMIN_PASS="${NEKO_ADMIN_PASS:-12345678}"
export NEKO_PROFILE_HOST_DIR="$neko_prof"
export NEKO_DESKTOP_SCREEN="${NEKO_DESKTOP_SCREEN:-1920x1080@30}"
export NEKO_WEBRTC_EPR="${NEKO_WEBRTC_EPR:-52000-52100}"