Update build.func

This commit is contained in:
CanbiZ 2025-09-19 11:03:21 +02:00
parent 1ac0e0e792
commit a03d46f5b2

View File

@ -2372,47 +2372,43 @@ EOF
if [ "$var_os" != "alpine" ]; then
msg_info "Waiting for network in LXC container"
sleep 2
for i in {1..10}; do
# 1. Primary check: ICMP ping (fastest, but may be blocked by ISP/firewall)
if pct exec "$CTID" -- ping -c1 -W1 deb.debian.org >/dev/null 2>&1; then
msg_ok "Network in LXC is reachable (ping)"
break
# --- Check 1: Has CT an IP? ---
ip_in_lxc=$(pct exec "$CTID" -- ip -4 addr show dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
if [ -z "$ip_in_lxc" ]; then
msg_warn "No IP in LXC yet (try $i/10) waiting..."
sleep 3
continue
fi
# Wait and retry if not reachable yet
if [ "$i" -lt 10 ]; then
if [ "$i" -le 3 ]; then
sleep 2
else
msg_warn "No network in LXC yet (try $i/10) waiting..."
sleep 3
fi
else
# After 10 unsuccessful ping attempts, try HTTP connectivity via wget as fallback
msg_warn "Ping failed 10 times. Trying HTTP connectivity check (wget) as fallback..."
if pct exec "$CTID" -- wget -q --spider http://deb.debian.org; then
msg_ok "Network in LXC is reachable (wget fallback)"
else
msg_error "No network in LXC after all checks."
read -r -p "Set fallback DNS (1.1.1.1/8.8.8.8)? [y/N]: " choice
case "$choice" in
[yY]*)
pct set "$CTID" --nameserver 1.1.1.1
pct set "$CTID" --nameserver 8.8.8.8
# Final attempt with wget after DNS change
if pct exec "$CTID" -- wget -q --spider http://deb.debian.org; then
msg_ok "Network reachable after DNS fallback"
else
msg_error "Still no network/DNS in LXC! Aborting customization."
exit_script
fi
;;
*)
msg_error "Aborted by user no DNS fallback set."
exit_script
;;
esac
fi
# --- Check 2: Can reach gateway? ---
if ! pct exec "$CTID" -- ping -c1 -W1 "$GATEWAY" >/dev/null 2>&1; then
msg_warn "CT $CTID has IP $ip_in_lxc but cannot reach gateway $GATEWAY (try $i/10)"
sleep 3
continue
fi
# --- Check 3: Can resolve DNS? ---
if pct exec "$CTID" -- getent hosts deb.debian.org >/dev/null 2>&1; then
msg_ok "Network in LXC is reachable (DNS OK, IP $ip_in_lxc)"
break
else
msg_warn "CT $CTID has IP $ip_in_lxc, gateway OK, but DNS failed (try $i/10)"
sleep 3
fi
# --- End of loop fallback ---
if [ "$i" -eq 10 ]; then
msg_warn "DNS still failing after 10 attempts. Applying fallback resolv.conf..."
pct exec "$CTID" -- bash -c 'echo "nameserver 1.1.1.1" > /etc/resolv.conf && echo "nameserver 8.8.8.8" >> /etc/resolv.conf'
if pct exec "$CTID" -- getent hosts deb.debian.org >/dev/null 2>&1; then
msg_ok "Network reachable after DNS fallback"
else
msg_error "Still no DNS/network in LXC! Aborting customization."
exit_script
fi
fi
done
fi