diff --git a/docker/bettercap.yml b/docker/bettercap.yml index cc904bb..c5a2e79 100644 --- a/docker/bettercap.yml +++ b/docker/bettercap.yml @@ -11,10 +11,10 @@ services: set api.rest.username '${BETTERCAP_USER:-opsbox}'; set api.rest.password '${BETTERCAP_PASSWORD:?Set BETTERCAP_PASSWORD in opsbox.env}'; set api.rest.address '${BETTERCAP_UI_ADDR:-${OPSBOX_DOCKER_GATEWAY:-172.17.0.1}}'; - set api.rest.port ${BETTERCAP_API_PORT:-8081}; + set api.rest.port ${BETTERCAP_API_PORT:-8061}; set api.rest.alloworigin '${BETTERCAP_ALLOW_ORIGIN:-https://${OPSBOX_SUB_BETTERCAP:-bettercap}.${OPSBOX_DOMAIN:-opsbox.internal}}'; api.rest on; set ui.address '${BETTERCAP_UI_ADDR:-${OPSBOX_DOCKER_GATEWAY:-172.17.0.1}}'; - set ui.port ${BETTERCAP_UI_PORT:-1600}; + set ui.port ${BETTERCAP_UI_PORT:-8060}; ui on; set gps.device localhost:2947; diff --git a/docker/caddy.yml b/docker/caddy.yml index 48250bd..565bc46 100644 --- a/docker/caddy.yml +++ b/docker/caddy.yml @@ -18,13 +18,19 @@ services: - proxy labels: caddy: ${OPSBOX_SUB_BETTERCAP:-bettercap}.${OPSBOX_DOMAIN:-opsbox.internal} - caddy.reverse_proxy: host.docker.internal:${BETTERCAP_UI_PORT:-1600} + caddy.reverse_proxy: host.docker.internal:${BETTERCAP_UI_PORT:-8060} caddy.tls: internal caddy_1: ${OPSBOX_SUB_BETTERCAP_API:-api.bettercap}.${OPSBOX_DOMAIN:-opsbox.internal} - caddy_1.reverse_proxy: host.docker.internal:${BETTERCAP_API_PORT:-8081} + caddy_1.reverse_proxy: host.docker.internal:${BETTERCAP_API_PORT:-8061} caddy_1.tls: internal + caddy_2: ${OPSBOX_SUB_MESH:-mesh}.${OPSBOX_DOMAIN:-opsbox.internal} + caddy_2.reverse_proxy: https://host.docker.internal:${MESHTASTIC_PORT:-8070} + caddy_2.reverse_proxy.transport: http + caddy_2.reverse_proxy.transport.tls_insecure_skip_verify: "" + caddy_2.tls: internal + networks: proxy: external: true diff --git a/docker/librespeed.yml b/docker/librespeed.yml index 69f2073..26556d4 100644 --- a/docker/librespeed.yml +++ b/docker/librespeed.yml @@ -1,7 +1,7 @@ services: librespeed: image: lscr.io/linuxserver/librespeed:latest - container_name: opsbox-librespeed + container_name: opsbox-speedtest restart: unless-stopped environment: PUID: ${PUID:-1000} @@ -10,7 +10,7 @@ services: volumes: - ${OPSBOX_DATA_ROOT:?Set OPSBOX_DATA_ROOT}/librespeed:/config ports: - - "${LIBRESPEED_BIND:-127.0.0.1}:${LIBRESPEED_PORT:-1900}:80" + - "${LIBRESPEED_BIND:-127.0.0.1}:${LIBRESPEED_PORT:-8010}:80" networks: - proxy labels: diff --git a/docker/maps.yml b/docker/maps.yml index acf0ee8..a1e64ba 100644 --- a/docker/maps.yml +++ b/docker/maps.yml @@ -17,7 +17,7 @@ services: photon: image: rtuszik/photon-docker:latest - container_name: viator-photon + container_name: opsbox-photon restart: unless-stopped profiles: [photon] environment: @@ -36,7 +36,7 @@ services: tileserver: image: maptiler/tileserver-gl:v4.11.0 - container_name: viator-tileserver + container_name: opsbox-tileserver restart: unless-stopped profiles: [tiles] command: ["--config", "/config/config.json"] diff --git a/docker/sdr.yml b/docker/sdr.yml index a92d1e4..757528e 100644 --- a/docker/sdr.yml +++ b/docker/sdr.yml @@ -14,7 +14,7 @@ services: device_cgroup_rules: - "c 189:* rmw" ports: - - "${OPENWEBRX_BIND:-127.0.0.1}:${OPENWEBRX_PORT:-8073}:8073" + - "${OPENWEBRX_BIND:-127.0.0.1}:${OPENWEBRX_PORT:-8040}:8073" networks: - proxy labels: diff --git a/docker/wireguard.yml b/docker/wireguard.yml index 30526fb..be16b62 100644 --- a/docker/wireguard.yml +++ b/docker/wireguard.yml @@ -7,7 +7,7 @@ services: - NET_ADMIN ports: - "51820:51820/udp" - - "${WG_PORTAL_BIND:-127.0.0.1}:${WG_PORTAL_UI_PORT:-8888}:8888/tcp" + - "${WG_PORTAL_BIND:-127.0.0.1}:${WG_PORTAL_UI_PORT:-8050}:8888/tcp" sysctls: - net.ipv4.conf.all.src_valid_mark=1 environment: diff --git a/install.sh b/install.sh index df4187d..e329e48 100644 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ set -Eeuo pipefail # OpsBox bootstrap + installer. Keep the Git URL in one place. OPSBOX_GIT_REPO="${OPSBOX_GIT_REPO:-https://git.zakscode.com/ztimson/opsbox.git}" -OPSBOX_VERSION="1.2.0" +OPSBOX_VERSION="1.3.0" OPSBOX_DIR="${OPSBOX_DIR:-}" CONFIG_DIR="/etc/opsbox" STATE_FILE="$CONFIG_DIR/selections" @@ -47,6 +47,48 @@ trap 'rc=$?; err "Unexpected failure on line $LINENO (exit $rc)"; exit "$rc"' ER require_root() { [[ $EUID -eq 0 ]] || die "Run as root: curl ... | sudo bash"; } +# -------------------------------------------------------------------------------------- +# Port scheme +# Web UIs live in 8010-8090: one block of ten per service family, in install order. +# 8010 LibreSpeed | 8020-8022 Maps (Cartomake, TileServer, Photon) | 8030-8031 Cloud +# 8040 OpenWebRX+ | 8050 WireGuard Portal | 8060-8061 Bettercap (UI, API) +# 8070 Meshtastic | 8090 TAK web UI +# Fixed ports (not configurable, reserved so nothing else can be assigned to them): +# 80/443 Caddy | 2947 gpsd | 8089, 8446 TAK streaming/enrollment | 51820/udp WireGuard +# -------------------------------------------------------------------------------------- +FIXED_PORTS=( + "80|Caddy HTTP" + "443|Caddy HTTPS" + "2947|gpsd" + "8089|TAK streaming (TLS)" + "8446|TAK certificate enrollment" + "51820|WireGuard VPN (UDP)" +) + +reserved_port() { + local p="$1" e + for e in "${FIXED_PORTS[@]}"; do + if [[ "${e%%|*}" == "$p" ]]; then printf '%s' "${e#*|}"; return 0; fi + done + return 1 +} + +# Older installs saved the previous defaults; move them onto the new scheme. +# Only values that still equal the old default are touched (custom choices are kept). +migrate_ports() { + local spec var old new cur + for spec in LIBRESPEED_PORT:1900:8010 HARNESS_PORT:8082:8030 OFFICE_PORT:8083:8031 \ + OPENWEBRX_PORT:8073:8040 WG_PORTAL_UI_PORT:8888:8050 \ + BETTERCAP_UI_PORT:1600:8060 BETTERCAP_API_PORT:8081:8061; do + IFS=: read -r var old new <<<"$spec" + cur="${!var-}" + if [[ "$cur" == "$old" ]]; then + printf -v "$var" '%s' "$new" + log "Port scheme: $var $old -> $new" + fi + done +} + # -------------------------------------------------------------------------------------- # Catalogue of components (alphabetical by tag) # -------------------------------------------------------------------------------------- @@ -56,14 +98,14 @@ COMPONENTS=( "maps|Maps (Cartomake web UI)" "pentest|Pen test suite (host tools + Bettercap)" "personal-cloud|Personal cloud (AI, file editing, notes, ZIM reader)" - "sdr-tools|ADS-B, OpenWebRX+, RTL_433" + "sdr-tools|OpenWebRX+ (SDR receiver)" "speedtest|LibreSpeed speed test" "tak|Tactical awareness kit (OpenTAK Server)" "theme|Terminal prompt theme and login banner" "tools|Tools (btop, jq, tmux)" "vnc|VNC remote desktop" "wireguard|WireGuard VPN" - "wireless-hat|4-in-1 (GPS, Lora, SDR, RTC)" + "wireless-hat|4-in-1 (GPS, Lora, SDR, RTC) + Meshtastic + shared gpsd" "zims|ZIM archives (offline Wikipedia, manuals, ...)" ) for _c in "${COMPONENTS[@]}"; do COMP_LABEL["${_c%%|*}"]="${_c#*|}"; done @@ -121,10 +163,12 @@ init() { # shellcheck disable=SC1090 source "$ENV_FILE" set +a + migrate_ports DATA_ROOT="${OPSBOX_DATA_ROOT:-$DATA_ROOT}" OPSBOX_DATA_ROOT="$DATA_ROOT" ADMIN_USER="${OPSBOX_ADMIN_USER:-$ADMIN_USER}" - OPSBOX_ADMIN_USERNAME="${OPSBOX_ADMIN_USERNAME:-${BETTERCAP_USER:-admin}}" + # One shared account, reused by every service that needs a first user. + OPSBOX_ADMIN_USERNAME="${OPSBOX_ADMIN_USERNAME:-$ADMIN_USER}" OPSBOX_ADMIN_EMAIL="${OPSBOX_ADMIN_EMAIL:-${WG_PORTAL_ADMIN_USER:-admin@opsbox.internal}}" OPSBOX_ADMIN_PASSWORD="${OPSBOX_ADMIN_PASSWORD:-${BETTERCAP_PASSWORD:-${WG_PORTAL_ADMIN_PASSWORD:-${OPENWEBRX_ADMIN_PASSWORD:-}}}}" DOCKER_USER="${DOCKER_REGISTRY_USER:-}" @@ -517,21 +561,21 @@ step_global() { while true; do form_run "Storage, system and registry" \ "Data root holds all Docker/application data. -The administrator is added to the docker group. +The admin account below is entered once and reused for every +service that needs a first user (WireGuard, Bettercap, OpenWebRX+, ...). +The username defaults to the current user, who is added to the docker group. Docker is always installed; images are pulled from $DOCKER_REGISTRY. -(Leave the password blank only if this host is already logged in.)" \ +(Leave the registry password blank only if this host is already logged in.)" \ "DATA_ROOT|Data root (absolute path)|t" \ - "ADMIN_USER|Linux user for docker group|t" \ - "OPSBOX_ADMIN_USERNAME|Shared admin username|t" \ - "OPSBOX_ADMIN_EMAIL|Shared admin email|t" \ - "OPSBOX_ADMIN_PASSWORD|Shared admin password|p" \ + "OPSBOX_ADMIN_USERNAME|Admin username|t" \ + "OPSBOX_ADMIN_EMAIL|Admin email|t" \ + "OPSBOX_ADMIN_PASSWORD|Admin password|p" \ "APT_UPGRADE|Run apt upgrade (yes/no)|t" \ "DOCKER_USER|$DOCKER_REGISTRY username|t" \ "DOCKER_PASS|$DOCKER_REGISTRY password/token|p" || return 1 err="" DATA_ROOT="${DATA_ROOT%/}" [[ "$DATA_ROOT" == /* ]] || err+="Data root must be an absolute path.\n" - id "$ADMIN_USER" >/dev/null 2>&1 || err+="User '$ADMIN_USER' does not exist.\n" [[ -n "$OPSBOX_ADMIN_USERNAME" ]] || err+="An administrator username is required.\n" [[ "$OPSBOX_ADMIN_EMAIL" =~ ^[^[:space:]@]+@[^[:space:]@]+\.[^[:space:]@]+$ ]] || err+="Enter a valid administrator email address.\n" [[ -n "$OPSBOX_ADMIN_PASSWORD" ]] || err+="An administrator password is required.\n" @@ -549,25 +593,25 @@ Docker is always installed; images are pulled from $DOCKER_REGISTRY. # ---- Step 4: network (Caddy + every service, one screen) ----------------------------- build_net_rows() { NET_ROWS=() - local add='NET_ROWS+=("$1|$2|$3|$4|$5|$6|$7")' net_add() { NET_ROWS+=("$1|$2|$3|$4|$5|$6|$7"); } - contains speedtest && net_add SPEEDTEST "LibreSpeed" speedtest 1900 LIBRESPEED_BIND LIBRESPEED_PORT no || true - contains tak && net_add OPENTAK "TAK Server (web UI)" tak 8090 OTS_WEB_BIND OTS_WEB_PORT no || true + # key | label | default subdomain | default port | bind var ("-" = host service) | port var | needs host name when no Caddy + contains speedtest && net_add SPEEDTEST "LibreSpeed" speedtest 8010 LIBRESPEED_BIND LIBRESPEED_PORT no || true contains maps && net_add MAPS "Cartomake (maps UI)" maps 8020 CARTOMAKE_BIND CARTOMAKE_PORT no || true - [[ "${MAP_PHOTON:-no}" == yes ]] && net_add GEOCODE "Photon geocoder" geocode 8022 PHOTON_BIND PHOTON_PORT yes || true [[ "${MAP_TILESERVER:-no}" == yes ]] && net_add TILES "TileServer GL" tiles 8021 TILESERVER_BIND TILESERVER_PORT yes || true + [[ "${MAP_PHOTON:-no}" == yes ]] && net_add GEOCODE "Photon geocoder" geocode 8022 PHOTON_BIND PHOTON_PORT yes || true if contains personal-cloud; then - net_add HARNESS "AI harness" home 8082 WEB_BIND HARNESS_PORT yes - net_add OFFICE "OnlyOffice" office 8083 WEB_BIND OFFICE_PORT yes + net_add HARNESS "AI harness" home 8030 WEB_BIND HARNESS_PORT yes + net_add OFFICE "OnlyOffice" office 8031 WEB_BIND OFFICE_PORT yes fi - contains sdr-tools && net_add SDR "SDR tools (OpenWebRX+)" sdr 8073 OPENWEBRX_BIND OPENWEBRX_PORT no || true - contains wireguard && net_add WGPORTAL "WireGuard Portal" vpn 8888 - WG_PORTAL_UI_PORT no || true + contains sdr-tools && net_add SDR "SDR tools (OpenWebRX+)" sdr 8040 OPENWEBRX_BIND OPENWEBRX_PORT no || true + contains wireguard && net_add WGPORTAL "WireGuard Portal" vpn 8050 - WG_PORTAL_UI_PORT no || true if contains pentest; then - net_add BETTERCAP "Bettercap UI" bettercap 1600 - BETTERCAP_UI_PORT no - net_add BETTERCAP_API "Bettercap API" api.bettercap 8081 - BETTERCAP_API_PORT no + net_add BETTERCAP "Bettercap UI" bettercap 8060 - BETTERCAP_UI_PORT no + net_add BETTERCAP_API "Bettercap API" api.bettercap 8061 - BETTERCAP_API_PORT no fi + contains wireless-hat && net_add MESH "Meshtastic (web UI)" mesh 8070 - MESHTASTIC_PORT no || true + contains tak && net_add OPENTAK "TAK Server (web UI)" tak 8090 OTS_WEB_BIND OTS_WEB_PORT no || true unset -f net_add - : "$add" } step_network() { @@ -576,7 +620,7 @@ step_network() { if ((n == 0)); then USE_CADDY=no; return 10; fi local uc="${USE_CADDY:-yes}" dom="$OPSBOX_DOMAIN" local -a net_sub=() net_port=() args=() vals=() - local i key label dsub dport bindv portv need sv lw=0 col y out err lines cols h fh w + local i key label dsub dport bindv portv need sv lw=0 col y out err lines cols h fh w r for ((i = 0; i < n; i++)); do IFS='|' read -r key label dsub dport bindv portv need <<<"${NET_ROWS[i]}" sv="OPSBOX_SUB_$key" @@ -587,8 +631,8 @@ step_network() { ((lw < 22)) && lw=22 || true col=$((lw + 3)) lines="$(tlines)"; cols="$(tcols)" - h=$((n + 14)); ((h > lines)) && h=$lines || true - fh=$((h - 12)); ((fh < 4)) && fh=4 || true + h=$((n + 15)); ((h > lines)) && h=$lines || true + fh=$((h - 13)); ((fh < 4)) && fh=4 || true w=$((col + 52)); ((w < 80)) && w=80 || true; ((w > cols)) && w=$cols || true while true; do args=("Use Caddy (yes/no):" 1 1 "$uc" 1 "$col" 6 6 0 @@ -604,7 +648,8 @@ step_network() { no = you already run a reverse proxy: services are published on the host ports below for it to forward to; . is the public name used in links between services. -Columns: service | subdomain | host port" "$h" "$w" "$fh" "${args[@]}" 3>&1 1>&2 2>&3)" || return 1 +Columns: service | subdomain | host port +Reserved (cannot be used): 80, 443, 2947, 8089, 8446, 51820" "$h" "$w" "$fh" "${args[@]}" 3>&1 1>&2 2>&3)" || return 1 mapfile -t vals <<<"$out" uc="${vals[0]-}"; dom="${vals[1]-}" for ((i = 0; i < n; i++)); do @@ -619,7 +664,13 @@ Columns: service | subdomain | host port" "$h" "$w" "$fh" "${args[@]}" 3>&1 1>& IFS='|' read -r key label dsub dport bindv portv need <<<"${NET_ROWS[i]}" net_sub[i]="${net_sub[i],,}" valid_sub "${net_sub[i]}" || err+="$label: invalid subdomain '${net_sub[i]}'\n" - valid_port "${net_port[i]}" || err+="$label: invalid port '${net_port[i]}'\n" + if valid_port "${net_port[i]}"; then + if r="$(reserved_port "$((10#${net_port[i]}))")"; then + err+="$label: port ${net_port[i]} is reserved for $r\n" + fi + else + err+="$label: invalid port '${net_port[i]}'\n" + fi [[ -n "${seen_s[${net_sub[i]}]:-}" ]] && err+="$label: subdomain '${net_sub[i]}' is used twice\n" || true [[ -n "${seen_p[${net_port[i]}]:-}" ]] && err+="$label: port '${net_port[i]}' is used twice\n" || true seen_s[${net_sub[i]}]=1; seen_p[${net_port[i]}]=1 @@ -648,6 +699,7 @@ Columns: service | subdomain | host port" "$h" "$w" "$fh" "${args[@]}" 3>&1 1>& } # ---- Step 5: per-service configuration screens --------------------------------------- +# Services that need a first account all take it from the shared OPSBOX_ADMIN_* values. cfg_bettercap() { BETTERCAP_USER="$OPSBOX_ADMIN_USERNAME" BETTERCAP_PASSWORD="$OPSBOX_ADMIN_PASSWORD" @@ -659,22 +711,15 @@ cfg_bettercap() { fi } +# No form: the shared admin account and the UI port (Network step) are all it needs. cfg_wireguard() { - local err WG_PORTAL_ADMIN_USER="$OPSBOX_ADMIN_EMAIL" WG_PORTAL_ADMIN_PASSWORD="$OPSBOX_ADMIN_PASSWORD" - WG_PORTAL_UI_PORT="${WG_PORTAL_UI_PORT:-8888}" - while true; do - form_run "WireGuard Portal" "Uses the shared OpsBox administrator account.\nThe web UI is routed through Caddy when enabled; UDP 51820 is used for VPN clients." \ - "WG_PORTAL_UI_PORT|Web UI port|t" || return 1 - err="" - valid_port "$WG_PORTAL_UI_PORT" || err+="Web UI port must be between 1 and 65535.\n" - [[ -z "$err" ]] && break - msg "$err" - done + WG_PORTAL_UI_PORT="${WG_PORTAL_UI_PORT:-8050}" WG_PORTAL_EXTERNAL_URL="https://${OPSBOX_SUB_WGPORTAL:-vpn}.$OPSBOX_DOMAIN" WG_PORTAL_WEB_SESSION_SECRET="${WG_PORTAL_WEB_SESSION_SECRET:-$(openssl rand -hex 32)}" WG_PORTAL_WEB_CSRF_SECRET="${WG_PORTAL_WEB_CSRF_SECRET:-$(openssl rand -hex 32)}" + return 0 } cfg_openwebrx() { @@ -750,9 +795,9 @@ cfg_hat() { HAT_GPS="${HAT_GPS:-yes}"; HAT_LORA="${HAT_LORA:-yes}"; HAT_RTC="${HAT_RTC:-no}"; HAT_PPS="${HAT_PPS:-no}" local -a sel=() out="$(dlg --title "Wireless HAT" --ok-label "Next" --cancel-label "$BACK" --separate-output --checklist \ - "Hardware overlays to enable (a reboot is required afterwards)." 16 92 4 \ - gps "GPS UART (also removes the Linux serial console)" "$([[ $HAT_GPS == yes ]] && echo on || echo off)" \ - lora "LoRa SX1262 on SPI1 (spi1-1cs overlay)" "$([[ $HAT_LORA == yes ]] && echo on || echo off)" \ + "Hardware to enable (a reboot is required afterwards).\nGPS is served by a shared gpsd; LoRa installs and configures Meshtastic." 17 92 4 \ + gps "GPS UART + shared gpsd (also removes the Linux serial console)" "$([[ $HAT_GPS == yes ]] && echo on || echo off)" \ + lora "LoRa SX1262 on SPI1 + Meshtastic (spi1-1cs overlay)" "$([[ $HAT_LORA == yes ]] && echo on || echo off)" \ rtc "HAT PCF85063A RTC (skip if a Pi/PiSugar RTC is in use)" "$([[ $HAT_RTC == yes ]] && echo on || echo off)" \ pps "GPS PPS input on GPIO6 (needs HAT switch SW1-2 ON)" "$([[ $HAT_PPS == yes ]] && echo on || echo off)" \ 3>&1 1>&2 2>&3)" || return 1 @@ -830,6 +875,7 @@ step_summary() { sum_add "SYSTEM" sum_add " Data root: $DATA_ROOT" sum_add " Docker group user: $ADMIN_USER" + sum_add " Shared admin: $OPSBOX_ADMIN_USERNAME <$OPSBOX_ADMIN_EMAIL> (used by every service below)" sum_add " apt upgrade: $APT_UPGRADE" sum_add " Registry login: $DOCKER_USER @ $DOCKER_REGISTRY" if ((${#NET_ROWS[@]})); then @@ -841,10 +887,24 @@ step_summary() { sv="OPSBOX_SUB_$key" if [[ "$USE_CADDY" == yes ]]; then if [[ "$key" == WGPORTAL ]]; then sum_add " $(printf '%-24s' "$label") https://${!sv}.$OPSBOX_DOMAIN (container:8888)" + elif [[ "$bindv" == "-" ]]; then sum_add " $(printf '%-24s' "$label") https://${!sv}.$OPSBOX_DOMAIN (host service :${!portv})" else sum_add " $(printf '%-24s' "$label") https://${!sv}.$OPSBOX_DOMAIN (127.0.0.1:${!portv})"; fi else sum_add " $(printf '%-24s' "$label") ${!sv}.$OPSBOX_DOMAIN (host port ${!portv})"; fi done fi + # Fixed ports other than the web UIs above. + local fixed="" + [[ "$USE_CADDY" == yes ]] && fixed+=" 80, 443/tcp Caddy"$'\n' || true + contains tak && fixed+=" 8089, 8446/tcp TAK streaming / certificate enrollment"$'\n' || true + contains wireguard && fixed+=" 51820/udp WireGuard VPN clients"$'\n' || true + if contains wireless-hat && [[ "${HAT_GPS:-no}" == yes ]]; then + fixed+=" 2947/tcp gpsd (localhost + Docker gateway only)"$'\n' + fi + if [[ -n "$fixed" ]]; then + sum_add "" + sum_add "FIXED PORTS (not configurable)" + SUM+="$fixed" + fi if ((${#SEL_DL[@]})); then sum_add "" sum_add "DOWNLOADS" @@ -861,18 +921,18 @@ step_summary() { sum_add "" sum_add "SERVICE SETTINGS" contains pentest && sum_add " Bettercap: user '$BETTERCAP_USER'${BETTERCAP_UI_ADDR:+, listen $BETTERCAP_UI_ADDR}" || true - contains sdr-tools && sum_add " SDR tools: ADS-B, OpenWebRX+, RTL_433; OpenWebRX admin '$OPENWEBRX_ADMIN_USER'" || 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 wireless-hat && sum_add " Wireless HAT: GPS=$HAT_GPS LoRa=$HAT_LORA RTC=$HAT_RTC PPS=$HAT_PPS" || 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 sum_add " OpenTAKServer: Upstream creates its own initial administrator; change its default password on first login." fi - if contains sdr-tools; then + if contains wireless-hat && [[ "${HAT_GPS:-no}" == yes ]]; then sum_add "" - sum_add "NOTE: one RTL-SDR can only be claimed by one SDR service at a time." - sum_add " Use separate receivers or configure only one service to use the HAT tuner." + sum_add "NOTE: gpsd owns the GPS UART. Clients connect to gpsd (port 2947); software that" + sum_add " needs a serial device gets its own PTY: /run/gps/ (Meshtastic: /run/gps/meshtastic)." fi sum_add "" sum_add "A reboot is recommended afterwards if hardware overlays or kernel modules change." @@ -908,12 +968,8 @@ persist_config() { fi if contains sdr-tools; then OPENWEBRX_IMAGE="${OPENWEBRX_IMAGE:-slechev/openwebrxplus-softmbe:latest}" - SDR_OPENWEBRX=yes; SDR_ADSB=yes; SDR_RTL433=yes save_env OPENWEBRX_ADMIN_USER OPENWEBRX_ADMIN_PASSWORD OPENWEBRX_IMAGE - else - SDR_OPENWEBRX=no; SDR_ADSB=no; SDR_RTL433=no fi - save_env SDR_OPENWEBRX SDR_ADSB SDR_RTL433 if contains wireguard; then WG_PORTAL_EXTERNAL_URL="https://${OPSBOX_SUB_WGPORTAL:-vpn}.$OPSBOX_DOMAIN" WG_PORTAL_WEB_SESSION_SECRET="${WG_PORTAL_WEB_SESSION_SECRET:-$(openssl rand -hex 32)}" @@ -1197,7 +1253,7 @@ install_wireguard() { if [[ "$USE_CADDY" == yes ]]; then log "Web UI: $url (Caddy internal HTTPS)" else - log "Web UI: http://$(hostname -I | awk '{print $1}'):${WG_PORTAL_UI_PORT:-8888}" + log "Web UI: http://$(hostname -I | awk '{print $1}'):${WG_PORTAL_UI_PORT:-8050}" fi log "WireGuard UDP: port 51820" log "Initial administrator: $WG_PORTAL_ADMIN_USER" @@ -1336,10 +1392,9 @@ os.chmod(tmp, 0o644); os.replace(tmp, path) PY systemctl enable --now docker || return 1 systemctl restart docker || return 1 - docker login register_docker_binfmt || return 1 docker network inspect opsbox_proxy >/dev/null 2>&1 || docker network create opsbox_proxy >/dev/null - usermod -aG docker "$ADMIN_USER" + if id "$ADMIN_USER" >/dev/null 2>&1; then usermod -aG docker "$ADMIN_USER"; fi } docker_logged_in() { grep -qs "\"$DOCKER_REGISTRY\"" /root/.docker/config.json; } @@ -1401,6 +1456,13 @@ compose_stack() { OPSBOX_DATA_ROOT="$DATA_ROOT" "${args[@]}" "$@" up -d } +# Gateway of the default Docker bridge (what host.docker.internal resolves to). +docker_gateway() { + local gw + gw="$(docker network inspect bridge --format '{{(index .IPAM.Config 0).Gateway}}' 2>/dev/null || true)" + printf '%s' "${gw:-172.17.0.1}" +} + # ---- container services --------------------------------------------------------------- install_speedtest() { compose_stack librespeed docker/librespeed.yml "$ENV_FILE"; } @@ -1422,6 +1484,8 @@ install_opentak() { env_put "$dir/.env" OPSBOX_DOMAIN "$OPSBOX_DOMAIN" env_put "$dir/.env" OPSBOX_SUB_OPENTAK "${OPSBOX_SUB_OPENTAK:-tak}" + # 8089 (TAK streaming) and 8446 (certificate enrollment) are fixed host ports; + # they are reserved in the Network step so nothing else can be given them. cat > "$dir/docker-compose.override.yml" <, +# fed with gpsd's NMEA stream by a socat service (one PTY per consumer, because +# a PTY can only be read by one process). Add another with: +# systemctl enable --now opsbox-gps-pty@ +install_gpsd() { + local dev="$1" devices gw + apt_install gpsd gpsd-clients socat || return 1 + devices="$dev" + if [[ "$HAT_PPS" == yes ]]; then devices+=" /dev/pps0"; fi + gw="$(docker_gateway)" + + cat > /etc/default/gpsd < /etc/systemd/system/gpsd.socket.d/opsbox.conf < /etc/systemd/system/opsbox-gps-pty@.service <<'UNIT' +[Unit] +Description=OpsBox gpsd NMEA pseudo-terminal (/run/gps/%i) +After=gpsd.socket +Wants=gpsd.socket + +[Service] +ExecStartPre=/bin/mkdir -p /run/gps +ExecStartPre=-/bin/rm -f /run/gps/%i +ExecStart=/usr/bin/socat -d PTY,link=/run/gps/%i,raw,echo=0,mode=0666 "EXEC:/usr/bin/gpspipe -r" +Restart=always +RestartSec=2 + +[Install] +WantedBy=multi-user.target +UNIT + + systemctl daemon-reload || return 1 + systemctl enable gpsd.socket gpsd.service 2>/dev/null || true + systemctl restart gpsd.socket || return 1 + systemctl restart gpsd.service || warn "gpsd did not start yet; it will after the reboot (UART overlay needs it)." + log "Shared gpsd ready on 127.0.0.1:2947 and $gw:2947 (device: $devices)." +} + +# Meshtastic per the HackerGadgets HAT guide (Debian 12/13 Beta repo, SX1262 on SPI1). +install_meshtastic() { + local ver conf=/etc/meshtasticd/config.yaml port="${MESHTASTIC_PORT:-8070}" gps_link="" + local keyring=/etc/apt/trusted.gpg.d/network_Meshtastic_beta.gpg + + [[ "$(dpkg --print-architecture)" == arm64 ]] || { err "Meshtastic's Debian repo needs a 64-bit OS; on 32-bit use Meshtastic's Raspbian instructions."; return 1; } + ver="$(. /etc/os-release && echo "${VERSION_ID:-}")" + [[ "$ver" == 12 || "$ver" == 13 ]] || { err "Meshtastic supports Debian 12/13 only (found '${ver:-unknown}')."; return 1; } + + apt_install curl gnupg || return 1 + echo "deb http://download.opensuse.org/repositories/network:/Meshtastic:/beta/Debian_${ver}/ /" \ + > /etc/apt/sources.list.d/network:Meshtastic:beta.list + curl -fsSL "https://download.opensuse.org/repositories/network:Meshtastic:beta/Debian_${ver}/Release.key" \ + -o "$TMP_DIR/meshtastic.key" || return 1 + gpg --dearmor < "$TMP_DIR/meshtastic.key" > "$TMP_DIR/meshtastic.gpg" || return 1 + install -m 0644 "$TMP_DIR/meshtastic.gpg" "$keyring" + apt-get update || return 1 + apt_install meshtasticd || return 1 + + if [[ "$HAT_GPS" == yes ]]; then gps_link=/run/gps/meshtastic; fi + + mkdir -p /etc/meshtasticd + if [[ -f "$conf" ]]; then + [[ -e "$conf.bak" ]] || cp -a "$conf" "$conf.bak" + else + touch "$conf" + fi + + # Remove any existing top-level Lora/GPS/Webserver blocks (a duplicate YAML key stops + # meshtasticd from starting), then append ours. + python3 - "$conf" "$HAT_LORA" "$gps_link" "$port" <<'PY' || return 1 +import re, sys +path, lora, gps, port = sys.argv[1:5] +managed = ['Webserver'] + (['Lora'] if lora == 'yes' else []) + (['GPS'] if gps else []) +pat = re.compile(r'^(%s):' % '|'.join(managed)) +out, skip = [], False +for line in open(path).read().splitlines(): + if pat.match(line): + skip = True + continue + if skip and (not line.strip() or line[0] in ' \t'): + continue + skip = False + out.append(line) +while out and not out[-1].strip(): + out.pop() +blocks = [] +if lora == 'yes': + blocks.append("Lora:\n Module: sx1262\n DIO2_AS_RF_SWITCH: true\n DIO3_TCXO_VOLTAGE: true\n" + " IRQ: 26\n Busy: 24\n Reset: 25\n spidev: spidev1.0") +if gps: + blocks.append("GPS:\n SerialPath: %s" % gps) +blocks.append("Webserver:\n Port: %s\n RootPath: /usr/share/meshtasticd/web" % port) +open(path, 'w').write('\n'.join(out) + '\n\n' + '\n\n'.join(blocks) + '\n') +PY + + # GPS comes from the shared gpsd through its own PTY; start it before meshtasticd. + if [[ -n "$gps_link" ]]; then + mkdir -p /etc/systemd/system/meshtasticd.service.d + cat > /etc/systemd/system/meshtasticd.service.d/opsbox-gps.conf <<'DROPIN' +[Unit] +Wants=opsbox-gps-pty@meshtastic.service +After=opsbox-gps-pty@meshtastic.service +DROPIN + systemctl daemon-reload + systemctl enable --now opsbox-gps-pty@meshtastic.service || warn "Could not start the Meshtastic GPS PTY service." + fi + + systemctl daemon-reload + if [[ "$HAT_LORA" == yes ]]; then + systemctl enable meshtasticd || return 1 + if [[ -e /dev/spidev1.0 ]]; then + systemctl restart meshtasticd || return 1 + else + warn "/dev/spidev1.0 does not exist yet; meshtasticd will start after the reboot." + fi + else + systemctl disable --now meshtasticd 2>/dev/null || true + log "LoRa not selected: meshtasticd installed but left disabled." + fi + if [[ "$USE_CADDY" == yes ]]; then + log "Meshtastic web UI: https://${OPSBOX_SUB_MESH:-mesh}.$OPSBOX_DOMAIN (via Caddy; direct: https://localhost:$port)" + else + log "Meshtastic web UI: https://localhost:$port (self-signed certificate)" + fi + log "Set Config -> LoRa -> Region in the web UI before transmitting." +} + install_hat() { apt_install git i2c-tools minicom util-linux-extra gpsd gpsd-clients chrony pps-tools rtl-sdr || return 1 - local model pi5=no + local model pi5=no gps_path=/dev/ttyS0 model="$(tr -d '\0' /dev/null || true)" - [[ "$model" == *"Raspberry Pi 5"* ]] && pi5=yes + if [[ "$model" == *"Raspberry Pi 5"* || "$model" == *"Compute Module 5"* ]]; then pi5=yes; gps_path=/dev/ttyAMA0; fi local boot=/boot/firmware/config.txt cmd=/boot/firmware/cmdline.txt [[ -f "$boot" ]] || boot=/boot/config.txt [[ -f "$cmd" ]] || cmd=/boot/cmdline.txt @@ -1584,7 +1792,10 @@ install_hat() { if [[ "$HAT_PPS" == yes ]]; then grep -q '^dtoverlay=pps-gpio,gpiopin=6' "$boot" || echo 'dtoverlay=pps-gpio,gpiopin=6' >> "$boot" fi - warn "Hardware overlays were written. Reboot is required. Meshtasticd radio-region and GPSD-to-Meshtastic PTY sharing are not configured automatically by this release." + + if [[ "$HAT_GPS" == yes ]]; then install_gpsd "$gps_path" || return 1; fi + if [[ "$HAT_LORA" == yes || "$HAT_GPS" == yes ]]; then install_meshtastic || return 1; fi + warn "Hardware overlays were written. Reboot is required." } install_zims() {