#!/bin/sh # Alpine 5G Router – install/deploy scripts and config to this device # Run from repo root: ./scripts/install.sh # Or from scripts/: ./install.sh (uses script dir to find repo root) # Rev: 1 (see REVISION in repo root) set -e # Repo root (directory containing etc/ and scripts/) ROOT="$(cd "$(dirname "$0")/.." && pwd)" ETC="$ROOT/etc" SCRIPTS="$ROOT/scripts" BIN="/usr/local/bin" INITD="/etc/init.d" IPTABLES_SAVE="/etc/iptables" CONFIG="/etc/5g-router.conf" CONFIG_EXAMPLE="$ETC/5g-router.conf.example" LOG_DIR="/var/log" echo "Installing Alpine 5G Router from $ROOT" # Config: copy example if no config exists if [ ! -f "$CONFIG" ]; then cp "$CONFIG_EXAMPLE" "$CONFIG" echo "Created $CONFIG – please edit APN and interfaces if needed." else echo "Keeping existing $CONFIG" fi # Scripts install -m 755 "$SCRIPTS/connect-5g.sh" "$BIN/connect-5g.sh" install -m 755 "$SCRIPTS/status-5g.sh" "$BIN/status-5g.sh" install -m 755 "$SCRIPTS/modem-status-at.sh" "$BIN/modem-status-at.sh" install -m 755 "$SCRIPTS/healthcheck-5g.sh" "$BIN/healthcheck-5g.sh" install -m 755 "$SCRIPTS/speedtest-5g.sh" "$BIN/speedtest-5g.sh" install -m 755 "$SCRIPTS/rotate-5g-log.sh" "$BIN/rotate-5g-log.sh" install -m 755 "$SCRIPTS/diag-at-port.sh" "$BIN/diag-at-port.sh" install -m 755 "$SCRIPTS/diag-modem-up.sh" "$BIN/diag-modem-up.sh" install -m 755 "$SCRIPTS/troubleshoot-5g.sh" "$BIN/troubleshoot-5g.sh" echo "Installed scripts to $BIN" # Optional: configure_fm350_5g.sh for manual runs if [ -f "$ROOT/configure_fm350_5g.sh" ]; then install -m 755 "$ROOT/configure_fm350_5g.sh" "$BIN/configure_fm350_5g.sh" echo "Installed configure_fm350_5g.sh" fi # OpenRC service install -m 755 "$ETC/init.d/5g-router" "$INITD/5g-router" echo "Installed $INITD/5g-router" # iptables rules (restore at boot – ensure iptables-restore service exists) mkdir -p "$IPTABLES_SAVE" install -m 644 "$ETC/iptables/rules.v4" "$IPTABLES_SAVE/rules.v4" echo "Installed $IPTABLES_SAVE/rules.v4" if [ -d /etc/init.d ] && [ ! -f /etc/init.d/iptables-restore ]; then echo "Tip: enable iptables restore at boot: rc-update add iptables-restore" fi # Log file touch "$LOG_DIR/5g-router.log" 2>/dev/null && chmod 644 "$LOG_DIR/5g-router.log" || true touch "$LOG_DIR/speedtest-5g.log" 2>/dev/null && chmod 644 "$LOG_DIR/speedtest-5g.log" || true # Enable 5g-router at boot if command -v rc-update >/dev/null 2>&1; then rc-update add 5g-router default 2>/dev/null || true echo "Added 5g-router to default runlevel" fi # Web GUI (optional) WEBGUI_SRC="$ROOT/web" WEBGUI_DEST="/usr/local/share/5g-webgui" if [ -d "$WEBGUI_SRC" ] && [ -f "$WEBGUI_SRC/app.py" ]; then mkdir -p "$WEBGUI_DEST" cp -r "$WEBGUI_SRC"/* "$WEBGUI_DEST/" chmod 755 "$WEBGUI_DEST/run.sh" 2>/dev/null || true install -m 755 "$ETC/init.d/5g-webgui" "$INITD/5g-webgui" echo "Installed Web GUI at $WEBGUI_DEST. Enable with: rc-update add 5g-webgui default" echo " Then: apk add python3 py3-flask && service 5g-webgui start" echo " Login at http://:5000 (default: admin/admin, support/support – change passwords)" else echo "Web GUI source not found; skipping." fi echo "" echo "Done. Edit $CONFIG if needed, then: service 5g-router start" echo "Or run once: $BIN/connect-5g.sh" echo "Status: $BIN/status-5g.sh"