Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
79 lines
1.8 KiB
Bash
79 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
# Shared helpers for douyinWEB installers (sourced, not executed).
|
|
# shellcheck shell=bash
|
|
|
|
ask() {
|
|
# ask VAR "prompt" "default"
|
|
local var="$1" prompt="$2" def="${3:-}" cur=""
|
|
eval "cur=\${$var-}"
|
|
if [[ -n "$cur" ]]; then
|
|
return 0
|
|
fi
|
|
if [[ -n "$def" ]]; then
|
|
read -r -p "${prompt} [${def}]: " cur
|
|
cur="${cur:-$def}"
|
|
else
|
|
while [[ -z "$cur" ]]; do
|
|
read -r -p "${prompt}: " cur
|
|
done
|
|
fi
|
|
printf -v "$var" '%s' "$cur"
|
|
}
|
|
|
|
ask_secret() {
|
|
local var="$1" prompt="$2" cur=""
|
|
eval "cur=\${$var-}"
|
|
if [[ -n "$cur" ]]; then
|
|
return 0
|
|
fi
|
|
while [[ -z "$cur" ]]; do
|
|
read -r -s -p "${prompt}: " cur
|
|
echo
|
|
done
|
|
printf -v "$var" '%s' "$cur"
|
|
}
|
|
|
|
ask_yn() {
|
|
# ask_yn VAR "prompt" default_y_or_n
|
|
local var="$1" prompt="$2" def="${3:-n}" ans=""
|
|
eval "ans=\${$var-}"
|
|
if [[ -n "$ans" ]]; then
|
|
return 0
|
|
fi
|
|
read -r -p "${prompt} [$([[ "$def" == "y" ]] && echo Y/n || echo y/N)]: " ans
|
|
ans="$(echo "${ans:-$def}" | tr '[:upper:]' '[:lower:]')"
|
|
if [[ "$ans" == "y" || "$ans" == "yes" ]]; then
|
|
printf -v "$var" '%s' "1"
|
|
else
|
|
printf -v "$var" '%s' "0"
|
|
fi
|
|
}
|
|
|
|
load_install_env_files() {
|
|
local f
|
|
for f in /etc/douyinweb.install.env ./install.env ./scripts/install.env; do
|
|
if [[ -f "$f" ]]; then
|
|
# shellcheck disable=SC1090
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
source "$f"
|
|
set +a
|
|
echo "[install] loaded $f"
|
|
fi
|
|
done
|
|
}
|
|
|
|
require_root() {
|
|
[[ "$(id -u)" -eq 0 ]] || { echo "ERROR: run as root" >&2; exit 1; }
|
|
}
|
|
|
|
print_banner() {
|
|
cat <<EOF
|
|
|
|
════════════════════════════════════════
|
|
douyinWEB installer
|
|
shape: ${INSTALL_SHAPE:-?}
|
|
════════════════════════════════════════
|
|
EOF
|
|
}
|