diff options
author | Maxim Devaev <[email protected]> | 2023-11-28 16:07:44 +0200 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-11-28 16:07:44 +0200 |
commit | 0e1ba765a24b97c359c1b24a9520c9d5965b3a35 (patch) | |
tree | b8885c0515949f8b621998ef9d7aab871f19200d | |
parent | 36a61023d5b4bf40cdd61ad7a2fb13d5f5fa1515 (diff) |
pikvm/pikvm#1174: static wifi config support for kvmd-bootconfig
-rwxr-xr-x | scripts/kvmd-bootconfig | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/scripts/kvmd-bootconfig b/scripts/kvmd-bootconfig index f4051363..d275e490 100755 --- a/scripts/kvmd-bootconfig +++ b/scripts/kvmd-bootconfig @@ -128,12 +128,11 @@ fi # ========== Ethernet ========== -# If the ETH_DHCP is defined, configure eth0 for DHCP -if [ -n "$ETH_DHCP" ]; then - ETH_IFACE="${ETH_IFACE:-eth0}" - cat <<end_of_file > "/etc/systemd/network/$ETH_IFACE.network" +make_dhcp_iface() { + local _iface="$1" + cat <<end_of_file > "/etc/systemd/network/$_iface.network" [Match] -Name=$ETH_IFACE +Name=$_iface [Network] DHCP=yes @@ -145,23 +144,37 @@ ClientIdentifier=mac # https://github.com/pikvm/pikvm/issues/583 RouteMetric=10 end_of_file -fi - -# If the ETH_ADDR is defined, configure a static address on eth0 -if [ -n "$ETH_ADDR" ]; then - ETH_IFACE="${ETH_IFACE:-eth0}" - cat <<end_of_file > "/etc/systemd/network/$ETH_IFACE.network" +} + +make_static_iface() { + local _iface="$1" + local _addr="$2" + local _gw="$3" + local _dns="$4" + cat <<end_of_file > "/etc/systemd/network/$_iface.network" [Match] -Name=$ETH_IFACE +Name=$_iface [Network] -Address=$ETH_ADDR -DNS=$ETH_DNS +Address=$_addr +DNS=$_dns DNSSEC=no [Route] -Gateway=$ETH_GW +Gateway=$_gw end_of_file +} + +# If the ETH_DHCP is defined, configure eth0 for DHCP +if [ -n "$ETH_DHCP" ]; then + ETH_IFACE="${ETH_IFACE:-eth0}" + make_dhcp_iface "$ETH_IFACE" +fi + +# If the ETH_ADDR is defined, configure a static address on eth0 +if [ -n "$ETH_ADDR" ]; then + ETH_IFACE="${ETH_IFACE:-eth0}" + make_static_iface "$ETH_IFACE" "$ETH_ADDR" "$ETH_GW" "$ETH_DNS" fi @@ -178,18 +191,11 @@ fi # If the WIFI_ESSID is defined, configure wlan0 if [ -n "$WIFI_ESSID" ]; then WIFI_IFACE="${WIFI_IFACE:-wlan0}" - cat <<end_of_file > "/etc/systemd/network/$WIFI_IFACE.network" -[Match] -Name=$WIFI_IFACE - -[Network] -DHCP=yes -DNSSEC=no - -# Use same IP by forcing to use MAC address for clientID -[DHCP] -ClientIdentifier=mac -end_of_file + if [ -n "$WIFI_ADDR" ]; then + make_static_iface "$WIFI_IFACE" "$WIFI_ADDR" "$WIFI_GW" "$WIFI_DNS" + else + make_dhcp_iface "$WIFI_IFACE" + fi wpa_passphrase "$WIFI_ESSID" "$WIFI_PASSWD" > "/etc/wpa_supplicant/wpa_supplicant-$WIFI_IFACE.conf" chmod 640 "/etc/wpa_supplicant/wpa_supplicant-$WIFI_IFACE.conf" systemctl enable "wpa_supplicant@$WIFI_IFACE.service" || true |