From acb0612ea4c1b60ca9be5c3b57a020a75d064743 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Mon, 17 Dec 2018 00:01:04 +0000 Subject: [PATCH] Allow setting up wifi from config Add WPA_ESSID, WPA_PASSWORD and WPA_COUNTRY options to config. --- README.md | 4 ++++ build.sh | 3 +++ stage2/02-net-tweaks/01-run.sh | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 8af1f12..02db69d 100755 --- a/README.md +++ b/README.md @@ -81,6 +81,10 @@ The following environment variables are supported: Password for the first user + * `WPA_ESSID`, `WPA_PASSWORD` and `WPA_COUNTRY` (Default: unset) + + If these are set, they are use to configure `wpa_supplicant.conf`, so that the raspberry pi can automatically connect to a wifi network on first boot. + A simple example for building Raspbian: ```bash diff --git a/build.sh b/build.sh index 4c8c3a3..6d7a8c9 100755 --- a/build.sh +++ b/build.sh @@ -143,6 +143,9 @@ export LOG_FILE="${WORK_DIR}/build.log" export FIRST_USER_NAME=${FIRST_USER_NAME:-pi} export FIRST_USER_PASS=${FIRST_USER_PASS:-raspberry} +export WPA_ESSID +export WPA_PASSWORD +export WPA_COUNTRY export BASE_DIR diff --git a/stage2/02-net-tweaks/01-run.sh b/stage2/02-net-tweaks/01-run.sh index 480f85a..5f30565 100755 --- a/stage2/02-net-tweaks/01-run.sh +++ b/stage2/02-net-tweaks/01-run.sh @@ -16,3 +16,14 @@ chown root:root /boot/dhcpcd.conf ln -s /boot/dhcpcd.conf /etc/dhcpcd.conf EOF +if [ -v WPA_COUNTRY ] +then + echo "country=${WPA_COUNTRY}" >> "${ROOTFS_DIR}/etc/wpa_supplicant/wpa_supplicant.conf" +fi + +if [ -v WPA_ESSID -a -v WPA_PASSWORD ] +then +on_chroot <> "/etc/wpa_supplicant/wpa_supplicant.conf" +EOF +fi