1
0
forked from finn/tinyboard

fix function ordering, remove dead variable, fix netplan rollback approach

This commit is contained in:
Justin Oros
2026-04-16 13:10:59 -07:00
parent 26110ce8d3
commit ea72b14696

View File

@@ -8,6 +8,10 @@ CYAN='\033[0;36m'
NC='\033[0m'
info() { echo -e "${GREEN}[+]${NC} $*"; }
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
die() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; }
header() { echo -e "\n${CYAN}══════════════════════════════════════════${NC}"; echo -e "${CYAN} $*${NC}"; echo -e "${CYAN}══════════════════════════════════════════${NC}"; }
check_deps() {
local missing=()
for cmd in "$@"; do
@@ -20,11 +24,6 @@ check_deps() {
fi
}
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
die() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; }
header() { echo -e "\n${CYAN}══════════════════════════════════════════${NC}"; echo -e "${CYAN} $*${NC}"; echo -e "${CYAN}══════════════════════════════════════════${NC}"; }
[ "$(id -u)" -eq 0 ] || die "Run as root"
check_deps ip netplan systemctl
@@ -164,11 +163,9 @@ fi
info "Netplan config written to $NETPLAN_FILE"
header "Applying Configuration"
warn "Testing netplan config with 30 second rollback window..."
netplan try --timeout 30 &
NETPLAN_PID=$!
warn "Applying netplan config — will revert automatically if network is lost..."
netplan apply
STATIC_ADDR_TEST="${STATIC_IP%%/*}"
CONNECTED=false
for i in $(seq 1 6); do
sleep 5
@@ -180,13 +177,16 @@ for i in $(seq 1 6); do
done
if $CONNECTED; then
info "Network connectivity confirmed — applying config permanently."
netplan apply
info "Network connectivity confirmed — config applied permanently."
else
warn "No network connectivity detected after 30 seconds — reverting to previous config."
kill "$NETPLAN_PID" 2>/dev/null || true
wait "$NETPLAN_PID" 2>/dev/null || true
die "Config reverted. Check your settings and try again."
warn "No network connectivity detected after 30 seconds — reverting to backup config."
if [ -f "$BACKUP_FILE" ]; then
cp "$BACKUP_FILE" "$NETPLAN_FILE"
netplan apply
die "Config reverted to backup. Check your settings and try again."
else
die "No backup found to revert to. Restore $NETPLAN_FILE manually."
fi
fi
STATIC_ADDR="${STATIC_IP%%/*}"