forked from finn/tinyboard
fix function ordering, remove dead variable, fix netplan rollback approach
This commit is contained in:
@@ -8,6 +8,10 @@ CYAN='\033[0;36m'
|
|||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
info() { echo -e "${GREEN}[+]${NC} $*"; }
|
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() {
|
check_deps() {
|
||||||
local missing=()
|
local missing=()
|
||||||
for cmd in "$@"; do
|
for cmd in "$@"; do
|
||||||
@@ -20,11 +24,6 @@ check_deps() {
|
|||||||
fi
|
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"
|
[ "$(id -u)" -eq 0 ] || die "Run as root"
|
||||||
|
|
||||||
check_deps ip netplan systemctl
|
check_deps ip netplan systemctl
|
||||||
@@ -164,11 +163,9 @@ fi
|
|||||||
info "Netplan config written to $NETPLAN_FILE"
|
info "Netplan config written to $NETPLAN_FILE"
|
||||||
|
|
||||||
header "Applying Configuration"
|
header "Applying Configuration"
|
||||||
warn "Testing netplan config with 30 second rollback window..."
|
warn "Applying netplan config — will revert automatically if network is lost..."
|
||||||
netplan try --timeout 30 &
|
netplan apply
|
||||||
NETPLAN_PID=$!
|
|
||||||
|
|
||||||
STATIC_ADDR_TEST="${STATIC_IP%%/*}"
|
|
||||||
CONNECTED=false
|
CONNECTED=false
|
||||||
for i in $(seq 1 6); do
|
for i in $(seq 1 6); do
|
||||||
sleep 5
|
sleep 5
|
||||||
@@ -180,13 +177,16 @@ for i in $(seq 1 6); do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if $CONNECTED; then
|
if $CONNECTED; then
|
||||||
info "Network connectivity confirmed — applying config permanently."
|
info "Network connectivity confirmed — config applied permanently."
|
||||||
netplan apply
|
|
||||||
else
|
else
|
||||||
warn "No network connectivity detected after 30 seconds — reverting to previous config."
|
warn "No network connectivity detected after 30 seconds — reverting to backup config."
|
||||||
kill "$NETPLAN_PID" 2>/dev/null || true
|
if [ -f "$BACKUP_FILE" ]; then
|
||||||
wait "$NETPLAN_PID" 2>/dev/null || true
|
cp "$BACKUP_FILE" "$NETPLAN_FILE"
|
||||||
die "Config reverted. Check your settings and try again."
|
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
|
fi
|
||||||
|
|
||||||
STATIC_ADDR="${STATIC_IP%%/*}"
|
STATIC_ADDR="${STATIC_IP%%/*}"
|
||||||
|
|||||||
Reference in New Issue
Block a user