FEATURE: Complete interactive network configuration for auto-installer

Enhanced network configuration with full user interaction:

WiFi Support:
- Automatic wireless interface detection using iw
- Network scanning with SSID selection
- Security protocol selection (WPA/WPA2, WEP, Open)
- Password input for secured networks

Ethernet Support:
- Automatic ethernet interface detection
- Interface selection from available options

IP Configuration:
- DHCP (automatic) or Static IP options
- Manual IP address, gateway, and DNS server entry
- Validation and configuration storage

Installation Integration:
- Network configuration applied to installed system
- Creates /etc/network/interfaces with user settings
- Configures DNS resolution for static setups
- Preserves WiFi credentials and settings

Package Dependencies:
- Added iw, wpasupplicant, dhcpcd5 for full WiFi support
- Maintains existing comprehensive wireless driver support

The auto-installer now provides complete network setup during installation,
configuring the target system with user-specified network preferences.
parent a10dcc40
......@@ -203,34 +203,208 @@ get_preseed_value() {
fi
}
# Network configuration - ONLY user interaction (optional for offline install)
# Enhanced network configuration for installed system
configure_network() {
print_header "Network Configuration (Optional)"
print_header "Network Configuration for Installed System"
# Network configuration variables
NETWORK_CONFIG=""
SELECTED_INTERFACE=""
WIFI_SSID=""
WIFI_PASSWORD=""
WIFI_SECURITY=""
STATIC_IP=""
STATIC_GATEWAY=""
STATIC_DNS=""
# Skip network config if user doesn't want it
echo ""
echo "Do you want to configure network for the installed system?"
echo -n "(y/n, default=n): "
read -r config_network
case "$config_network" in
y|Y|yes|YES)
;;
*)
print_status "Skipping network configuration - can be done after installation"
return 0
;;
esac
# Detect available interfaces
print_status "Scanning network interfaces..."
# Get ethernet interfaces
ETHERNET_INTERFACES=$(ip link show | grep -E '^[0-9]+:.*e(n|th)' | cut -d: -f2 | tr -d ' ')
# Get wireless interfaces
WIRELESS_INTERFACES=$(iw dev 2>/dev/null | grep Interface | awk '{print $2}' || true)
# Show available interfaces
echo ""
echo "Available network interfaces:"
interface_count=0
for iface in $ETHERNET_INTERFACES; do
interface_count=$((interface_count + 1))
echo " $interface_count. $iface (Ethernet)"
done
# Check if network is already configured
if ping -c 1 8.8.8.8 >/dev/null 2>&1; then
print_status "Network already configured and working"
for iface in $WIRELESS_INTERFACES; do
interface_count=$((interface_count + 1))
echo " $interface_count. $iface (Wireless)"
done
if [ $interface_count -eq 0 ]; then
print_warning "No network interfaces detected"
return 0
fi
print_status "Attempting automatic network configuration..."
# Select interface
echo ""
echo -n "Select interface number (1-$interface_count): "
read -r interface_selection
# Get selected interface name
current_count=0
for iface in $ETHERNET_INTERFACES; do
current_count=$((current_count + 1))
if [ "$current_count" = "$interface_selection" ]; then
SELECTED_INTERFACE="$iface"
INTERFACE_TYPE="ethernet"
break
fi
done
if [ -z "$SELECTED_INTERFACE" ]; then
for iface in $WIRELESS_INTERFACES; do
current_count=$((current_count + 1))
if [ "$current_count" = "$interface_selection" ]; then
SELECTED_INTERFACE="$iface"
INTERFACE_TYPE="wireless"
break
fi
done
fi
if [ -z "$SELECTED_INTERFACE" ]; then
print_error "Invalid interface selection"
return 1
fi
# Get available interfaces
INTERFACES=$(ip link show | grep -E '^[0-9]+:' | grep -v lo | cut -d: -f2 | tr -d ' ')
print_status "Selected interface: $SELECTED_INTERFACE ($INTERFACE_TYPE)"
for INTERFACE in $INTERFACES; do
print_status "Trying DHCP on interface: $INTERFACE"
timeout 10 dhclient "$INTERFACE" 2>/dev/null || continue
# Configure wireless if needed
if [ "$INTERFACE_TYPE" = "wireless" ]; then
print_status "Scanning for wireless networks..."
# Enable interface for scanning
ip link set "$SELECTED_INTERFACE" up
sleep 2
# Test connectivity
if ping -c 1 8.8.8.8 >/dev/null 2>&1; then
print_status "Network configured successfully on $INTERFACE"
return 0
# Scan for networks
AVAILABLE_NETWORKS=$(iw dev "$SELECTED_INTERFACE" scan | grep -E "SSID:" | sed 's/.*SSID: //' | sort -u | head -20)
if [ -n "$AVAILABLE_NETWORKS" ]; then
echo ""
echo "Available wireless networks:"
network_count=0
echo "$AVAILABLE_NETWORKS" | while read -r network; do
network_count=$((network_count + 1))
echo " $network_count. $network"
done
echo ""
echo -n "Select network number or type SSID manually: "
read -r wifi_selection
# Check if it's a number or manual SSID
if echo "$wifi_selection" | grep -q '^[0-9]\+$'; then
WIFI_SSID=$(echo "$AVAILABLE_NETWORKS" | sed -n "${wifi_selection}p")
else
WIFI_SSID="$wifi_selection"
fi
else
echo ""
echo -n "No networks found. Enter SSID manually: "
read -r WIFI_SSID
fi
done
if [ -n "$WIFI_SSID" ]; then
print_status "Selected WiFi network: $WIFI_SSID"
# Ask for security type
echo ""
echo "WiFi Security:"
echo " 1. WPA/WPA2 (most common)"
echo " 2. WEP (legacy)"
echo " 3. Open (no password)"
echo -n "Select security type (1-3, default=1): "
read -r security_choice
case "$security_choice" in
2) WIFI_SECURITY="WEP" ;;
3) WIFI_SECURITY="NONE" ;;
*) WIFI_SECURITY="WPA" ;;
esac
# Ask for password if needed
if [ "$WIFI_SECURITY" != "NONE" ]; then
echo -n "Enter WiFi password: "
read -s WIFI_PASSWORD
echo ""
fi
fi
fi
# Ask for IP configuration method
echo ""
echo "IP Configuration:"
echo " 1. DHCP (automatic)"
echo " 2. Static IP (manual)"
echo -n "Select method (1-2, default=1): "
read -r ip_method
case "$ip_method" in
2)
# Manual IP configuration
echo ""
echo -n "Enter IP address (e.g., 192.168.1.100): "
read -r STATIC_IP
echo -n "Enter gateway (e.g., 192.168.1.1): "
read -r STATIC_GATEWAY
echo -n "Enter DNS server (e.g., 8.8.8.8): "
read -r STATIC_DNS
NETWORK_CONFIG="static"
;;
*)
NETWORK_CONFIG="dhcp"
;;
esac
print_status "Network configuration collected for installed system"
print_status " Interface: $SELECTED_INTERFACE ($INTERFACE_TYPE)"
if [ "$INTERFACE_TYPE" = "wireless" ] && [ -n "$WIFI_SSID" ]; then
print_status " WiFi SSID: $WIFI_SSID"
print_status " WiFi Security: $WIFI_SECURITY"
fi
print_status " IP Method: $NETWORK_CONFIG"
# Store configuration for use during system configuration
cat > /tmp/network_config << EOF
SELECTED_INTERFACE="$SELECTED_INTERFACE"
INTERFACE_TYPE="$INTERFACE_TYPE"
WIFI_SSID="$WIFI_SSID"
WIFI_PASSWORD="$WIFI_PASSWORD"
WIFI_SECURITY="$WIFI_SECURITY"
NETWORK_CONFIG="$NETWORK_CONFIG"
STATIC_IP="$STATIC_IP"
STATIC_GATEWAY="$STATIC_GATEWAY"
STATIC_DNS="$STATIC_DNS"
EOF
print_warning "Network configuration failed - continuing OFFLINE installation"
print_status "Offline installation will work without internet connectivity"
print_status "Network configuration will be applied to installed system"
}
# User confirmation before destructive operations
......@@ -393,6 +567,69 @@ UUID=$ROOT_UUID / ext4 errors=remount-ro 0 1
proc /proc proc defaults 0 0
EOF
# Configure network for installed system if configuration was collected
if [ -f /tmp/network_config ]; then
print_status "Applying network configuration to installed system..."
# Source the network configuration
. /tmp/network_config
if [ -n "$SELECTED_INTERFACE" ]; then
# Create interfaces configuration
cat > "$TARGET_MOUNT/etc/network/interfaces" << NETEOF
# Network configuration applied during installation
auto lo
iface lo inet loopback
auto $SELECTED_INTERFACE
NETEOF
if [ "$INTERFACE_TYPE" = "wireless" ] && [ -n "$WIFI_SSID" ]; then
# Configure WiFi
echo "iface $SELECTED_INTERFACE inet $NETWORK_CONFIG" >> "$TARGET_MOUNT/etc/network/interfaces"
if [ "$NETWORK_CONFIG" = "static" ] && [ -n "$STATIC_IP" ]; then
echo " address $STATIC_IP" >> "$TARGET_MOUNT/etc/network/interfaces"
echo " gateway $STATIC_GATEWAY" >> "$TARGET_MOUNT/etc/network/interfaces"
fi
# WiFi-specific configuration
echo " wireless-essid $WIFI_SSID" >> "$TARGET_MOUNT/etc/network/interfaces"
if [ "$WIFI_SECURITY" != "NONE" ] && [ -n "$WIFI_PASSWORD" ]; then
if [ "$WIFI_SECURITY" = "WPA" ]; then
echo " wpa-passphrase $WIFI_PASSWORD" >> "$TARGET_MOUNT/etc/network/interfaces"
else # WEP
echo " wireless-key $WIFI_PASSWORD" >> "$TARGET_MOUNT/etc/network/interfaces"
fi
fi
print_status "WiFi configuration applied: $WIFI_SSID ($WIFI_SECURITY)"
else
# Configure Ethernet
echo "iface $SELECTED_INTERFACE inet $NETWORK_CONFIG" >> "$TARGET_MOUNT/etc/network/interfaces"
if [ "$NETWORK_CONFIG" = "static" ] && [ -n "$STATIC_IP" ]; then
echo " address $STATIC_IP" >> "$TARGET_MOUNT/etc/network/interfaces"
echo " gateway $STATIC_GATEWAY" >> "$TARGET_MOUNT/etc/network/interfaces"
fi
print_status "Ethernet configuration applied: $SELECTED_INTERFACE ($NETWORK_CONFIG)"
fi
# Configure DNS if static
if [ "$NETWORK_CONFIG" = "static" ] && [ -n "$STATIC_DNS" ]; then
echo "nameserver $STATIC_DNS" > "$TARGET_MOUNT/etc/resolv.conf"
print_status "DNS server configured: $STATIC_DNS"
fi
print_status "Network configuration written to installed system"
fi
else
print_status "No network configuration to apply - using defaults"
fi
# Remove live-specific configurations
rm -f "$TARGET_MOUNT/etc/systemd/system/getty@tty1.service.d/live-config.conf" 2>/dev/null || true
rm -rf "$TARGET_MOUNT/lib/live" 2>/dev/null || true
......
......@@ -87,6 +87,11 @@ dnsmasq
bridge-utils
vlan
# Additional tools for auto-installer network configuration
iw
wpasupplicant
dhcpcd5
# Hardware detection and management
pciutils
usbutils
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment