Wireguard password fix + deffer downloads until last

This commit is contained in:
2026-11-23 21:40:24 -05:00
parent e34f60436c
commit 4cf20fc3b4
2 changed files with 156 additions and 33 deletions
+1
View File
@@ -13,6 +13,7 @@ services:
environment:
WG_PORTAL_CORE_ADMIN_USER: "${WG_PORTAL_ADMIN_USER}"
WG_PORTAL_CORE_ADMIN_PASSWORD: "${WG_PORTAL_ADMIN_PASSWORD}"
WG_PORTAL_AUTH_MIN_PASSWORD_LENGTH: "${WG_PORTAL_AUTH_MIN_PASSWORD_LENGTH:-8}"
WG_PORTAL_WEB_EXTERNAL_URL: "${WG_PORTAL_EXTERNAL_URL}"
WG_PORTAL_WEB_SESSION_SECRET: "${WG_PORTAL_WEB_SESSION_SECRET}"
WG_PORTAL_WEB_CSRF_SECRET: "${WG_PORTAL_WEB_CSRF_SECRET}"
+155 -33
View File
@@ -29,6 +29,11 @@ NET_ROWS=()
ZIM_ORDER=()
DL_LOADED=""
SUM=""
DOWNLOAD_QUEUE="$CONFIG_DIR/download-queue"
DOWNLOAD_LOG="$CONFIG_DIR/download.log"
DOWNLOAD_COUNT=0
AI_IMPORT="${AI_IMPORT:-no}"
AI_READY=no
declare -A COMP_LABEL=() SEL_DL=() ZIM_NAME=() ZIM_REASON=() ZIM_TITLE=() ZIM_BYTES=() ZIM_URL=() ZIM_MANUAL=()
@@ -98,7 +103,7 @@ COMPONENTS=(
"fallback-ap|Fallback wireless access point"
"maps|Maps (Cartomake web UI)"
"pentest|Pen test suite (host tools + Bettercap)"
"personal-cloud|Personal cloud (AI, file editing, notes, ZIM reader)"
"personal-cloud|AI, file editing, notes, ZIMs"
"sdr-tools|OpenWebRX+ (SDR receiver)"
"speedtest|LibreSpeed speed test"
"tak|Tactical awareness kit (OpenTAK Server)"
@@ -181,7 +186,8 @@ contains() { local needle="$1" x; for x in "${SELECTED[@]}"; do [[ "$x" == "$nee
ensure_prereqs() {
log "Installing installer prerequisites (dialog, curl, python3)..."
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends dialog curl python3 ca-certificates openssl >/dev/null
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
dialog curl aria2 python3 ca-certificates openssl >/dev/null
}
save_env() {
@@ -723,13 +729,12 @@ cfg_wireguard() {
return 0
}
# Fixed image reference; change it here when intentionally upgrading/changing the image.
OPENWEBRX_IMAGE="slechev/openwebrxplus-softmbe:latest"
cfg_openwebrx() {
OPENWEBRX_ADMIN_USER="$OPSBOX_ADMIN_USERNAME"
OPENWEBRX_ADMIN_PASSWORD="$OPSBOX_ADMIN_PASSWORD"
OPENWEBRX_IMAGE="${OPENWEBRX_IMAGE:-slechev/openwebrxplus-softmbe:latest}"
form_run "OpenWebRX+" "Uses the shared OpsBox administrator username and password." \
"OPENWEBRX_IMAGE|Docker image|t" || return 1
[[ -n "$OPENWEBRX_IMAGE" ]] || { msg "Docker image is required."; return 1; }
}
cfg_fallback_ap() {
@@ -792,7 +797,7 @@ cfg_ai() {
form_run "Local AI (LiteRT)" "Model downloads can be several GB." \
"AI_DIR|Install directory|t" \
"AI_REPO|Hugging Face model repository|t" \
"AI_IMPORT|Download model now (yes/no)|t" || return 1
"AI_IMPORT|Download model in final phase (yes/no)|t" || return 1
err=""
[[ "$AI_DIR" == /* ]] || err+="Install directory must be absolute.\n"
[[ -n "$AI_REPO" ]] || err+="Model repository is required.\n"
@@ -944,7 +949,7 @@ step_summary() {
contains pentest && sum_add " Bettercap: user '$BETTERCAP_USER'${BETTERCAP_UI_ADDR:+, listen $BETTERCAP_UI_ADDR}" || true
contains sdr-tools && sum_add " OpenWebRX+: admin '$OPENWEBRX_ADMIN_USER'" || true
contains fallback-ap && sum_add " Fallback AP: SSID '$FALLBACK_AP_SSID' on $FALLBACK_AP_IFACE ($FALLBACK_AP_CIDR), check=$FALLBACK_AP_CHECK_MODE" || true
contains ai && sum_add " Local AI: $AI_REPO in $AI_DIR (download now: $AI_IMPORT)" || true
contains ai && sum_add " Local AI: $AI_REPO in $AI_DIR (download in final phase: $AI_IMPORT)" || true
contains wireless-hat && sum_add " Wireless HAT: GPS=$HAT_GPS LoRa=$HAT_LORA RTC=$HAT_RTC PPS=$HAT_PPS (Meshtastic Beta repo)" || true
contains wireguard && sum_add " WireGuard: WireGuard Portal admin '$WG_PORTAL_ADMIN_USER'" || true
if contains tak; then
@@ -988,7 +993,6 @@ persist_config() {
save_env BETTERCAP_USER BETTERCAP_PASSWORD BETTERCAP_UI_ADDR BETTERCAP_UI_PORT BETTERCAP_API_PORT BETTERCAP_ALLOW_ORIGIN
fi
if contains sdr-tools; then
OPENWEBRX_IMAGE="${OPENWEBRX_IMAGE:-slechev/openwebrxplus-softmbe:latest}"
save_env OPENWEBRX_ADMIN_USER OPENWEBRX_ADMIN_PASSWORD OPENWEBRX_IMAGE
fi
if contains wireguard; then
@@ -1003,7 +1007,7 @@ persist_config() {
OFFICE_JWT_SECRET="${OFFICE_JWT_SECRET:-$(openssl rand -hex 32)}"
save_env OFFICE_JWT_SECRET
fi
if contains ai; then save_env AI_DIR AI_REPO; fi
if contains ai; then save_env AI_DIR AI_REPO AI_IMPORT; fi
if contains wireless-hat; then save_env HAT_GPS HAT_LORA HAT_RTC HAT_PPS; fi
}
@@ -1263,11 +1267,17 @@ HOOK
install_wireguard() {
local url="${WG_PORTAL_EXTERNAL_URL:-https://${OPSBOX_SUB_WGPORTAL:-vpn}.$OPSBOX_DOMAIN}"
local password_length="${#WG_PORTAL_ADMIN_PASSWORD}"
WG_PORTAL_BIND="${WG_PORTAL_BIND:-$([[ "$USE_CADDY" == yes ]] && echo 127.0.0.1 || echo 0.0.0.0)}"
# Never require a longer password than the shared admin password already configured.
WG_PORTAL_AUTH_MIN_PASSWORD_LENGTH=8
if ((password_length > 0 && password_length < WG_PORTAL_AUTH_MIN_PASSWORD_LENGTH)); then
WG_PORTAL_AUTH_MIN_PASSWORD_LENGTH="$password_length"
fi
mkdir -p "$DATA_ROOT/wg-portal/data" "$DATA_ROOT/wg-portal/config"
chmod 0700 "$DATA_ROOT/wg-portal" "$DATA_ROOT/wg-portal/config" "$DATA_ROOT/wg-portal/data"
save_env WG_PORTAL_BIND
save_env WG_PORTAL_BIND WG_PORTAL_AUTH_MIN_PASSWORD_LENGTH
compose_stack wg-portal docker/wireguard.yml "$ENV_FILE" || return 1
log "WireGuard Portal is running."
@@ -1413,6 +1423,7 @@ os.chmod(tmp, 0o644); os.replace(tmp, path)
PY
systemctl enable --now docker || return 1
systemctl restart docker || return 1
docker login # Login to public repo for public images
register_docker_binfmt || return 1
docker network inspect opsbox_proxy >/dev/null 2>&1 || docker network create opsbox_proxy >/dev/null
if id "$ADMIN_USER" >/dev/null 2>&1; then usermod -aG docker "$ADMIN_USER"; fi
@@ -1595,9 +1606,8 @@ OVERRIDE
(cd "$dir" && docker compose up -d)
}
install_maps() {
local dataset url archive target expected available urlvar ext
apt_install unzip || return 1
queue_map_downloads() {
local dataset url archive expected available urlvar
for dataset in satellite vector contours; do
case "$dataset" in
satellite) [[ "$MAP_SATELLITE" == yes ]] || continue; expected=$((186*GB));;
@@ -1613,15 +1623,34 @@ install_maps() {
fi
mkdir -p "$DATA_ROOT/maps/tiles/$dataset" "$DATA_ROOT/maps/.downloads"
archive="$DATA_ROOT/maps/.downloads/$dataset.download"
if ! curl -fL --retry 3 -C - "$url" -o "$archive"; then rm -f "$archive"; return 1; fi
if [[ -e "$DATA_ROOT/maps/tiles/$dataset/$dataset.mbtiles" ]]; then
log "$dataset tiles already exist; skipped."
continue
fi
queue_download "$url" "$archive" "$dataset map dataset"
done
}
install_maps() {
local dataset archive target urlvar url ext
apt_install unzip || return 1
for dataset in satellite vector contours; do
case "$dataset" in
satellite) [[ "$MAP_SATELLITE" == yes ]] || continue;;
vector) [[ "$MAP_VECTOR" == yes ]] || continue;;
contours) [[ "$MAP_CONTOURS" == yes ]] || continue;;
esac
archive="$DATA_ROOT/maps/.downloads/$dataset.download"
target="$DATA_ROOT/maps/tiles/$dataset"
[[ -s "$archive" ]] || { warn "$dataset map archive was not downloaded; skipping."; continue; }
if unzip -tq "$archive" >/dev/null 2>&1; then
if ! unzip -oq "$archive" -d "$target"; then rm -f "$archive"; return 1; fi
unzip -oq "$archive" -d "$target" || return 1
rm -f "$archive"
else
urlvar="MAP_URL_${dataset^^}"; url="${!urlvar:-}"
ext="${url%%\?*}"; ext="${ext##*.}"
if [[ "$ext" == mbtiles ]]; then mv "$archive" "$target/$dataset.mbtiles"
else mv "$archive" "$target/$(basename "${url%%\?*}")"; fi
if [[ "$ext" == mbtiles ]]; then mv -f "$archive" "$target/$dataset.mbtiles"
else mv -f "$archive" "$target/$(basename "${url%%\?*}")"; fi
fi
done
mkdir -p "$DATA_ROOT/maps/tileserver"
@@ -1648,7 +1677,7 @@ install_pentest() {
OPSBOX_DOCKER_GATEWAY="$(docker_gateway)"
save_env OPSBOX_DOCKER_GATEWAY
curl -fL --retry 3 --retry-delay 2 \
https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfinstall \
https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb \
-o "$TMP_DIR/msfinstall" || return 1
chmod 0700 "$TMP_DIR/msfinstall"
"$TMP_DIR/msfinstall" || return 1
@@ -1691,7 +1720,7 @@ install_sdr_tools() {
install_ai() {
apt_install curl ca-certificates || return 1
local dir="$AI_DIR" repo="$AI_REPO" user=opsbox-ai
local dir="$AI_DIR" user=opsbox-ai
id "$user" >/dev/null 2>&1 || useradd --system --home "$dir" --create-home --shell /usr/sbin/nologin "$user"
mkdir -p "$dir"
chown -R "$user:$user" "$dir"
@@ -1700,10 +1729,16 @@ install_ai() {
env UV_INSTALL_DIR=/usr/local/bin sh "$TMP_DIR/uv-install.sh" || return 1
fi
runuser -u "$user" -- bash -lc "cd '$dir' && /usr/local/bin/uv venv --python=3.13 --seed && /usr/local/bin/uv pip install --python .venv/bin/python litert-cli-nightly litert-lm-nightly" || return 1
if [[ "$AI_IMPORT" == yes ]]; then
runuser -u "$user" -- bash -lc "cd '$dir' && .venv/bin/litert-lm import --from-huggingface-repo '$repo'" || return 1
fi
warn "LiteRT serving flags/API differ by release. The model runtime is installed, but no unverified systemd API command was generated."
AI_READY=yes
warn "LiteRT is installed. The model import is queued for the final download phase."
warn "LiteRT serving flags/API differ by release; no unverified systemd API command was generated."
}
install_ai_model() {
local dir="$AI_DIR" repo="$AI_REPO"
[[ "$AI_READY" == yes ]] || return 1
log "Downloading and importing LiteRT model: $repo"
runuser -u opsbox-ai -- bash -lc "cd '$dir' && .venv/bin/litert-lm import --from-huggingface-repo '$repo'"
}
# ---- Wireless HAT: shared gpsd + Meshtastic ------------------------------------------
@@ -1883,22 +1918,100 @@ install_hat() {
}
install_zims() {
local slug title bytes url filename part v
local slug title url filename final v
mkdir -p "$DATA_ROOT/zims"
for slug in "${ZIM_ORDER[@]}"; do
dl_has "z_$slug" || continue
title="${ZIM_TITLE[$slug]}"; bytes="${ZIM_BYTES[$slug]}"; url="${ZIM_URL[$slug]}"
title="${ZIM_TITLE[$slug]}"; url="${ZIM_URL[$slug]}"
if [[ "${ZIM_MANUAL[$slug]}" == yes ]]; then
v="MZIM_$slug"; url="${!v:-}"
[[ "$url" =~ ^https?:// ]] || { warn "No URL given for ${ZIM_NAME[$slug]}; skipping."; continue; }
fi
filename="$(basename "${url%%\?*}")"
[[ "$filename" == *.zim ]] || filename="$slug.zim"
if [[ -e "$DATA_ROOT/zims/$filename" ]]; then warn "$filename already exists; skipped."; continue; fi
log "Downloading $title ($(zim_size_gb "$bytes"))..."
part="$DATA_ROOT/zims/$filename.part"
if curl -fL --retry 3 -C - "$url" -o "$part"; then mv "$part" "$DATA_ROOT/zims/$filename"
else rm -f "$part"; FAILED+=("ZIM: $title"); fi
final="$DATA_ROOT/zims/$filename"
if [[ -e "$final" ]]; then warn "$filename already exists; skipped."; continue; fi
queue_download "$url" "$final.part" "ZIM: $title"
done
}
queue_download() {
local url="$1" output="$2" label="$3" dir name
[[ "$url" =~ ^https?:// ]] || return 1
dir="$(dirname "$output")"; name="$(basename "$output")"
mkdir -p "$dir"
{
printf '%s\n' "$url"
printf ' dir=%s\n' "$dir"
printf ' out=%s\n\n' "$name"
} >> "$DOWNLOAD_QUEUE"
DOWNLOAD_COUNT=$((DOWNLOAD_COUNT + 1))
log "Queued $label"
}
run_download_manager() {
local aria_pid="" ai_pid="" failed=0
if [[ -s "$DOWNLOAD_QUEUE" ]]; then
apt_install aria2 || return 1
log "Starting $DOWNLOAD_COUNT resumable asset downloads (up to 4 at once)..."
fi
if [[ -s "$DOWNLOAD_QUEUE" || ( "$AI_IMPORT" == yes && "$AI_READY" == yes ) ]]; then
: > "$DOWNLOAD_LOG"
dlg --title "OpsBox downloads - live progress" --tailboxbg "$DOWNLOAD_LOG" 20 100 || true
else
log "No large asset downloads selected."
return 0
fi
# LiteRT uses its Hugging Face downloader/cache, while aria2 handles map and ZIM
# assets. Run both together so the model transfer does not block the asset queue.
if [[ -s "$DOWNLOAD_QUEUE" ]]; then
aria2c --input-file="$DOWNLOAD_QUEUE" --continue=true --auto-file-renaming=false \
--allow-overwrite=true --max-concurrent-downloads=4 --split=4 \
--max-connection-per-server=4 --min-split-size=10M \
--summary-interval=1 --console-log-level=notice \
--download-result=full --human-readable=true >> "$DOWNLOAD_LOG" 2>&1 &
aria_pid=$!
fi
if [[ "$AI_IMPORT" == yes && "$AI_READY" == yes ]]; then
install_ai_model >> "$DOWNLOAD_LOG" 2>&1 &
ai_pid=$!
fi
if [[ -n "$aria_pid" ]]; then
if wait "$aria_pid"; then
rm -f "$DOWNLOAD_QUEUE"
log "Queued map/ZIM downloads completed."
else
warn "One or more map/ZIM downloads failed. Partial files were kept for resume."
failed=1
fi
fi
if [[ -n "$ai_pid" ]]; then
if wait "$ai_pid"; then
log "LiteRT model downloaded and imported."
else
warn "LiteRT model download/import failed. Check $DOWNLOAD_LOG and rerun to retry."
failed=1
fi
fi
return "$failed"
}
finish_zim_downloads() {
local slug title url filename part final v
for slug in "${ZIM_ORDER[@]}"; do
dl_has "z_$slug" || continue
title="${ZIM_TITLE[$slug]}"; url="${ZIM_URL[$slug]}"
if [[ "${ZIM_MANUAL[$slug]}" == yes ]]; then
v="MZIM_$slug"; url="${!v:-}"
[[ "$url" =~ ^https?:// ]] || continue
fi
filename="$(basename "${url%%\?*}")"
[[ "$filename" == *.zim ]] || filename="$slug.zim"
part="$DATA_ROOT/zims/$filename.part"; final="$DATA_ROOT/zims/$filename"
if [[ -s "$part" ]]; then mv -f "$part" "$final"
elif [[ ! -e "$final" ]]; then FAILED+=("ZIM: $title"); fi
done
}
@@ -1910,6 +2023,8 @@ main() {
wizard
persist_config
mkdir -p "$DATA_ROOT"
: > "$DOWNLOAD_QUEUE"
DOWNLOAD_COUNT=0
if [[ "$APT_UPGRADE" == yes ]]; then
log "Applying system upgrades..."
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y
@@ -1930,10 +2045,17 @@ main() {
contains pentest && run_docker_component "Pen Test Suite" install_pentest || true
contains speedtest && run_docker_component "LibreSpeed" install_speedtest || true
contains tak && run_docker_component "TAK Server" install_opentak || true
contains maps && run_docker_component "Maps" install_maps || true
contains personal-cloud && run_docker_component "Personal Cloud" install_personal_cloud || true
contains sdr-tools && run_docker_component "SDR tools" install_sdr_tools || true
contains zims && run_component "ZIM Archives" install_zims || true
# Large map/ZIM assets are queued after service setup and downloaded concurrently.
contains maps && queue_map_downloads || true
contains zims && install_zims || true
run_component "Downloads" run_download_manager || true
# Finalize any successful assets even if another concurrent download failed.
contains zims && finish_zim_downloads || true
if contains maps && [[ "$DOCKER_OK" == yes ]]; then
run_docker_component "Maps" install_maps || true
fi
[[ "$DOCKER_OK" == yes ]] && export_caddy_ca || true
local x report=$'Installation finished.\n\nSucceeded:\n'