Add reimage bootstrap: deploy.sh, setup_wifi.sh, fix setup.sh enable/reinstall, idempotent DB inserts
This commit is contained in:
@@ -177,9 +177,9 @@ def create_innocuous_macs_db(db_path: str) -> None:
|
||||
]
|
||||
|
||||
conn.executemany("""
|
||||
INSERT INTO mac_profiles (device_type, oui, vendor, device_name,
|
||||
dhcp_hostname, dhcp_vendor_class,
|
||||
ttl, tcp_window, os_family)
|
||||
INSERT OR IGNORE INTO mac_profiles (device_type, oui, vendor, device_name,
|
||||
dhcp_hostname, dhcp_vendor_class,
|
||||
ttl, tcp_window, os_family)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", profiles)
|
||||
|
||||
@@ -317,7 +317,7 @@ def create_os_sigs_db(db_path: str) -> None:
|
||||
]
|
||||
|
||||
conn.executemany("""
|
||||
INSERT INTO signatures (ttl, window, df, mss, os, version)
|
||||
INSERT OR IGNORE INTO signatures (ttl, window, df, mss, os, version)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
""", sigs)
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
# BigBrother remote deploy — push source to a fresh device and run setup.
|
||||
# Usage: bash scripts/deploy.sh [user@host] [--enable-service] [--no-tools] [--reinstall]
|
||||
set -euo pipefail
|
||||
|
||||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; BOLD='\033[1m'; NC='\033[0m'
|
||||
info() { echo -e "${GREEN}[+]${NC} $*"; }
|
||||
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
|
||||
error() { echo -e "${RED}[-]${NC} $*"; exit 1; }
|
||||
step() { echo -e "${CYAN}[*]${NC} ${BOLD}$*${NC}"; }
|
||||
|
||||
TARGET="root@10.0.0.0"
|
||||
SETUP_FLAGS=""
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--enable-service) SETUP_FLAGS="$SETUP_FLAGS --enable-service"; shift ;;
|
||||
--no-tools) SETUP_FLAGS="$SETUP_FLAGS --no-tools"; shift ;;
|
||||
--reinstall) SETUP_FLAGS="$SETUP_FLAGS --reinstall"; shift ;;
|
||||
-h|--help)
|
||||
echo "Usage: $0 [user@host] [--enable-service] [--no-tools] [--reinstall]"
|
||||
echo " user@host Target device (default: root@10.0.0.0)"
|
||||
echo " --enable-service Enable and start bigbrother-core after setup"
|
||||
echo " --no-tools Skip GitHub tool downloads"
|
||||
echo " --reinstall Force reinstall all components"
|
||||
exit 0
|
||||
;;
|
||||
*@*) TARGET="$1"; shift ;;
|
||||
*) error "Unknown option: $1" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
HOST="${TARGET#*@}"
|
||||
|
||||
step "BigBrother remote deploy → ${TARGET}"
|
||||
echo " Source: ${SCRIPT_DIR}"
|
||||
echo " Flags: ${SETUP_FLAGS:-none}"
|
||||
echo ""
|
||||
|
||||
# ── 1. Verify SSH connectivity ───────────────────────────────────────────────
|
||||
step "Checking SSH connectivity..."
|
||||
DEADLINE=$(( $(date +%s) + 30 ))
|
||||
while ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 -o BatchMode=yes "$TARGET" true 2>/dev/null; do
|
||||
if [[ $(date +%s) -ge $DEADLINE ]]; then
|
||||
error "Cannot reach ${TARGET} after 30s. Is the device up and SSH running?"
|
||||
fi
|
||||
warn " Waiting for SSH on ${HOST}..."
|
||||
sleep 3
|
||||
done
|
||||
info "SSH OK"
|
||||
|
||||
# ── 2. Sync source to device ─────────────────────────────────────────────────
|
||||
step "Syncing source to ${HOST}:/tmp/bb-deploy/ ..."
|
||||
rsync -az --delete \
|
||||
--exclude='.git' \
|
||||
--exclude='.venv' \
|
||||
--exclude='storage/' \
|
||||
--exclude='__pycache__' \
|
||||
--exclude='*.pyc' \
|
||||
--exclude='*.db' \
|
||||
-e "ssh -o StrictHostKeyChecking=no" \
|
||||
"${SCRIPT_DIR}/" "${TARGET}:/tmp/bb-deploy/"
|
||||
info "Source synced"
|
||||
|
||||
# ── 3. Run setup ─────────────────────────────────────────────────────────────
|
||||
step "Running setup.sh on ${HOST}..."
|
||||
# shellcheck disable=SC2029
|
||||
ssh -o StrictHostKeyChecking=no -t "$TARGET" "cd /tmp/bb-deploy && bash setup.sh $SETUP_FLAGS"
|
||||
SETUP_EXIT=$?
|
||||
|
||||
if [[ $SETUP_EXIT -ne 0 ]]; then
|
||||
warn "setup.sh exited with code ${SETUP_EXIT}"
|
||||
warn "Check logs: ssh ${TARGET} 'tail -50 /tmp/bb_setup_*.log'"
|
||||
exit $SETUP_EXIT
|
||||
fi
|
||||
|
||||
# ── 4. Final status ──────────────────────────────────────────────────────────
|
||||
echo ""
|
||||
step "Deployment status"
|
||||
ssh -o StrictHostKeyChecking=no "$TARGET" \
|
||||
"systemctl is-active bigbrother-core.service 2>/dev/null && echo 'Service: running' || echo 'Service: not running (use --enable-service to start)'"
|
||||
|
||||
info "Deploy complete. Connect: ssh ${TARGET}"
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
# Write a NetworkManager WiFi profile to an unmounted Armbian SD card.
|
||||
# Run this on the machine where the SD card is mounted BEFORE first boot.
|
||||
#
|
||||
# Usage: bash scripts/setup_wifi.sh SSID PASSPHRASE [MOUNT_POINT]
|
||||
# MOUNT_POINT defaults to /media/$USER/armbi_root
|
||||
set -euo pipefail
|
||||
|
||||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
|
||||
info() { echo -e "${GREEN}[+]${NC} $*"; }
|
||||
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
|
||||
error() { echo -e "${RED}[-]${NC} $*"; exit 1; }
|
||||
|
||||
SSID="${1:-}"
|
||||
PASSPHRASE="${2:-}"
|
||||
MOUNT="${3:-/media/${USER:-root}/armbi_root}"
|
||||
|
||||
[[ -z "$SSID" || -z "$PASSPHRASE" ]] && {
|
||||
echo "Usage: $0 SSID PASSPHRASE [MOUNT_POINT]"
|
||||
echo " MOUNT_POINT defaults to /media/\$USER/armbi_root"
|
||||
exit 1
|
||||
}
|
||||
|
||||
[[ -d "$MOUNT" ]] || error "Mount point not found: $MOUNT — is the SD card mounted?"
|
||||
|
||||
NM_DIR="${MOUNT}/etc/NetworkManager/system-connections"
|
||||
NM_FILE="${NM_DIR}/wifi-bb.nmconnection"
|
||||
|
||||
mkdir -p "$NM_DIR"
|
||||
|
||||
cat > "$NM_FILE" << EOF
|
||||
[connection]
|
||||
id=wifi-bb
|
||||
type=wifi
|
||||
autoconnect=true
|
||||
|
||||
[wifi]
|
||||
mode=infrastructure
|
||||
ssid=${SSID}
|
||||
|
||||
[wifi-security]
|
||||
auth-alg=open
|
||||
key-mgmt=wpa-psk
|
||||
psk=${PASSPHRASE}
|
||||
|
||||
[ipv4]
|
||||
method=auto
|
||||
|
||||
[ipv6]
|
||||
method=disabled
|
||||
EOF
|
||||
|
||||
chmod 600 "$NM_FILE"
|
||||
info "WiFi profile written to ${NM_FILE}"
|
||||
info "SSID: ${SSID}"
|
||||
echo ""
|
||||
info "After first boot, device should connect automatically."
|
||||
warn "If it doesn't connect, SSH in via Ethernet or serial and run:"
|
||||
warn " nmcli dev wifi connect '${SSID}' password '<passphrase>'"
|
||||
echo ""
|
||||
info "Once connected, deploy BigBrother with:"
|
||||
info " bash scripts/deploy.sh root@<DEVICE_IP> --enable-service"
|
||||
Reference in New Issue
Block a user