From cb2c58035e39520f959ed6680f54c21196323303 Mon Sep 17 00:00:00 2001 From: Alexey Rogachevskiy Date: Mon, 31 Aug 2020 16:18:44 +0300 Subject: [PATCH] builder: Add network autoconfiguration (client/AP) --- builder/assets/dhcpcd.exit-hook | 6 ++++++ builder/image-build.sh | 1 + builder/image-network.sh | 7 +++++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 builder/assets/dhcpcd.exit-hook diff --git a/builder/assets/dhcpcd.exit-hook b/builder/assets/dhcpcd.exit-hook new file mode 100644 index 0000000000..9d392b9935 --- /dev/null +++ b/builder/assets/dhcpcd.exit-hook @@ -0,0 +1,6 @@ +# Start dnsmasq if dhcpcd used static config +if [ "$interface" = "wlan0" ] && [ "x$profile" = "xstatic_wlan0" ] && [ "$reason" = "STATIC" ]; then + echo "Using own network, starting dnsmasq" + # Note: We run systemctl in the background to avoid deadlocking on start + systemctl start dnsmasq & +fi diff --git a/builder/image-build.sh b/builder/image-build.sh index 147daa6006..793ed61b03 100755 --- a/builder/image-build.sh +++ b/builder/image-build.sh @@ -107,6 +107,7 @@ ${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} exec ${SCRIPTS_DIR}'/image-software # examples ${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} copy ${SCRIPTS_DIR}'/assets/examples' '/home/pi/' # network setup +${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} copy ${SCRIPTS_DIR}'/assets/dhcpcd.exit-hook' '/etc' ${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} exec ${SCRIPTS_DIR}'/image-network.sh' # avahi setup ${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} copy ${SCRIPTS_DIR}'/assets/avahi-services/sftp-ssh.service' '/etc/avahi/services' diff --git a/builder/image-network.sh b/builder/image-network.sh index 7394b25077..92a207a842 100755 --- a/builder/image-network.sh +++ b/builder/image-network.sh @@ -34,11 +34,14 @@ echo_stamp() { echo -e ${TEXT} } -echo_stamp "#1 Write STATIC to /etc/dhcpcd.conf" +echo_stamp "#1 Enable fallback profile for wlan0 in /etc/dhcpcd.conf" cat << EOF >> /etc/dhcpcd.conf -interface wlan0 +profile static_wlan0 static ip_address=192.168.11.1/24 + +interface wlan0 +fallback static_wlan0 EOF echo_stamp "#2 Set wpa_supplicant country"