From 5889d6abc223303766077ac5c75257b16b7adcb1 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 05 Aug 2014 14:44:22 -0400 Subject: installers/pc: Rewrite network configuration --- diff --git a/installers/data/pc.sh b/installers/data/pc.sh index 0818437..d86e48d 100644 --- a/installers/data/pc.sh +++ b/installers/data/pc.sh @@ -47,30 +47,98 @@ _select() printf '\nConfigure the network' printf '\n=====================\n\n' -printf 'Hostname: ' +printf 'Hostname (e.g. "proteanos"): ' _read -r hostname printf '%s\n' "${hostname}" >/etc/hostname -printf 'Network configuration method:\n' -_select 'Static' 'DHCP' -if [ "x${select_result}" = 'xStatic' ]; then - printf 'Network interface (e.g. "eth0"): ' - _read -r netiface - printf 'Network address (e.g. "192.168.1.2"): ' - _read -r netaddr - printf 'Network mask (e.g. "255.255.255.0"): ' - _read -r netmask - printf 'Network gateway (e.g. "192.168.1.1"): ' - _read -r netgw - cat >/etc/network/interfaces.local </etc/network/interfaces.local + printf 'auto lo\niface lo inet loopback\n\n' >&3 + while true; do + printf 'Interface (e.g. "eth0" or "wlan0") or empty to finish: ' + _read -r net_iface + [ "x${net_iface}" = 'x' ] && break + case "${net_iface%%[0-9]}" in + eth|wlan);; + *) printf 'Unknown interface type\n';; + esac + printf 'Interface configuration:\n' + _select 'DHCP' 'Static' + if [ "x${select_result}" = 'xStatic' ]; then + net_static=true + printf 'auto %s\niface %s inet static\n' \ + "${net_iface}" "${net_iface}" >&3 + printf 'Address: (e.g. "192.168.1.2"): ' + _read -r net_addr + printf '\taddress %s\n' "${net_addr}" >&3 + printf 'Network mask: (e.g. "255.255.255.0"): ' + _read -r net_mask + printf '\tnetmask %s\n' "${net_mask}" >&3 + printf 'Default gateway: (e.g. "%s") or empty: ' \ + '192.168.1.1' + _read -r net_gateway + if [ "x${net_gateway}" != 'x' ]; then + printf '\tgateway %s\n' "${net_gateway}" >&3 + fi + printf 'DNS servers: (e.g. "192.168.1.1 10.0.0.1"): ' + _read -r net_dns + net_dns="$(printf '%s\n' "${net_dns}" | \ + sed 's/[^0-9. ]//g')" + exec 4>/etc/resolv.conf + for net_ns in ${net_dns}; do + printf 'nameserver %s\n' "${net_ns}" >&4 + done + exec 4>&- + printf 'Enable DHCP server:\n' + _select 'Yes' 'No' + if [ "x${select_result}" = 'xYes' ]; then + printf 'Start host address (e.g. "%s"): ' \ + '192.168.1.100' + _read -r net_dhcpd_start + printf '\tdhcpd-start %s\n' "${net_dhcpd_start}" \ + >&3 + printf 'End host address (e.g. "%s"): ' \ + '192.168.1.254' + _read -r net_dhcpd_end + printf '\tdhcpd-end %s\n' "${net_dhcpd_end}" >&3 + printf 'Lease time (e.g. "864000"): ' + _read -r net_dhcpd_lease + printf '\tdhcpd-option lease %s\n' \ + "${net_dhcpd_lease}" >&3 + fi + fi + case "${net_iface%%[0-9]}" in wlan) + if ${net_static}; then + printf 'Wi-Fi configuration:\n' + _select 'Access point' 'Client' + if [ "x${select_result}" = 'xClient' ]; then + printf '\twpa-mode 0\n' >&3 + else + printf '\twpa-mode 2\n' >&3 + fi + else + # Force client mode with DHCP. + printf '\twpa-mode 0\n' >&3 + fi + printf 'ESSID (name): ' + _read -r net_wpa_ssid + printf '\twpa-ssid %s\n' "${net_wpa_ssid}" >&3 + printf 'Security:\n' + _select 'None' 'WPA2-PSK' + if [ "x${select_result}" = 'xWPA2-PSK' ]; then + printf '\twpa-proto RSN\n' >&3 + printf '\twpa-key-mgmt WPA-PSK\n' >&3 + printf 'Pre-shared key (passphrase): ' + _read -r net_wpa_psk + printf '\twpa-psk %s\n' "${net_wpa_psk}" >&3 + else + printf '\twpa-key-mgmt NONE\n' >&3 + fi + ;; + esac + done + exec 3>&- fi printf '\nSet up users and passwords' -- cgit v0.9.1