From 3fb57a9b571306a9160d0e3070b6f8381428cdeb Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Tue, 9 Jul 2019 12:11:48 +0200 Subject: [PATCH] Centralise network interface checks --- bibliotecha.sh | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/bibliotecha.sh b/bibliotecha.sh index d843782..1dd6e22 100755 --- a/bibliotecha.sh +++ b/bibliotecha.sh @@ -144,13 +144,12 @@ function stop_networking_services { systemctl stop ${services} } -function configure_network_interfaces { - echo "Configuring networking interfaces ..." +function ensure_predictable_network_interfaces { + echo "Ensuring predictable networking interfaces ..." # shellcheck disable=SC2010 # shellcheck disable=SC2155 - ethernet_interface=$(ls /sys/class/net/ | grep en) - local ethernet_filename="/etc/network/interfaces.d/${ethernet_interface}" + local ethernet_interface=$(ls /sys/class/net/ | grep en) if [[ -z "${ethernet_interface}" ]]; then echo "" @@ -161,14 +160,9 @@ function configure_network_interfaces { exit 1 fi - { echo "auto eth0"; - echo "allow-hotplug ${ethernet_interface}"; - echo "iface ${ethernet_interface} inet dhcp"; } > "${ethernet_filename}" - # shellcheck disable=SC2010 # shellcheck disable=SC2155 local wireless_interface=$(ls /sys/class/net/ | grep wl) - local wireless_filename="/etc/network/interfaces.d/${wireless_interface}" if [[ -z "${wireless_interface}" ]]; then echo "" @@ -178,6 +172,24 @@ function configure_network_interfaces { echo "" exit 1 fi +} + +function configure_network_interfaces { + echo "Configuring networking interfaces ..." + + # shellcheck disable=SC2010 + # shellcheck disable=SC2155 + local ethernet_interface=$(ls /sys/class/net/ | grep en) + local ethernet_filename="/etc/network/interfaces.d/${ethernet_interface}" + + { echo "auto eth0"; + echo "allow-hotplug ${ethernet_interface}"; + echo "iface ${ethernet_interface} inet dhcp"; } > "${ethernet_filename}" + + # shellcheck disable=SC2010 + # shellcheck disable=SC2155 + local wireless_interface=$(ls /sys/class/net/ | grep wl) + local wireless_filename="/etc/network/interfaces.d/${wireless_interface}" { echo "auto ${wireless_interface}"; echo "iface ${wireless_interface} inet static"; @@ -193,15 +205,6 @@ function configure_dnsmasq { local wireless_interface=$(ls /sys/class/net/ | grep wl) local wireless_filename="/etc/dnsmasq.d/${wireless_interface}.conf" - if [[ -z "${wireless_interface}" ]]; then - echo "" - echo "Could not determine the wireless interface" - echo "Please ensure you've configure 'predictable network interfaces'" - echo "Please see https://manual.bibliotecha.info/#troubleshooting for more" - echo "" - exit 1 - fi - { echo "bogus-priv" echo "server=/library/10.0.0.1" echo "local=/library/" @@ -222,15 +225,6 @@ function configure_hostapd { local wireless_interface=$(ls /sys/class/net/ | grep wl) local hostapd_filename="/etc/hostapd/hostapd.conf" - if [[ -z "${wireless_interface}" ]]; then - echo "" - echo "Could not determine the wireless interface" - echo "Please ensure you've configure 'predictable network interfaces'" - echo "Please see https://manual.bibliotecha.info/#troubleshooting for more" - echo "" - exit 1 - fi - { echo "interface=${wireless_interface}" echo "ssid=Bibliotecha" echo "hw_mode=g" @@ -393,6 +387,7 @@ function run_installation { install_networking_packages stop_networking_services + ensure_predictable_network_interfaces configure_network_interfaces configure_dnsmasq configure_hostapd