mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
pikvm/pikvm#1174: static wifi config support for kvmd-bootconfig
This commit is contained in:
parent
36a61023d5
commit
0e1ba765a2
@ -128,12 +128,11 @@ fi
|
|||||||
|
|
||||||
# ========== Ethernet ==========
|
# ========== Ethernet ==========
|
||||||
|
|
||||||
# If the ETH_DHCP is defined, configure eth0 for DHCP
|
make_dhcp_iface() {
|
||||||
if [ -n "$ETH_DHCP" ]; then
|
local _iface="$1"
|
||||||
ETH_IFACE="${ETH_IFACE:-eth0}"
|
cat <<end_of_file > "/etc/systemd/network/$_iface.network"
|
||||||
cat <<end_of_file > "/etc/systemd/network/$ETH_IFACE.network"
|
|
||||||
[Match]
|
[Match]
|
||||||
Name=$ETH_IFACE
|
Name=$_iface
|
||||||
|
|
||||||
[Network]
|
[Network]
|
||||||
DHCP=yes
|
DHCP=yes
|
||||||
@ -145,23 +144,37 @@ ClientIdentifier=mac
|
|||||||
# https://github.com/pikvm/pikvm/issues/583
|
# https://github.com/pikvm/pikvm/issues/583
|
||||||
RouteMetric=10
|
RouteMetric=10
|
||||||
end_of_file
|
end_of_file
|
||||||
|
}
|
||||||
|
|
||||||
|
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=$_iface
|
||||||
|
|
||||||
|
[Network]
|
||||||
|
Address=$_addr
|
||||||
|
DNS=$_dns
|
||||||
|
DNSSEC=no
|
||||||
|
|
||||||
|
[Route]
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
# If the ETH_ADDR is defined, configure a static address on eth0
|
# If the ETH_ADDR is defined, configure a static address on eth0
|
||||||
if [ -n "$ETH_ADDR" ]; then
|
if [ -n "$ETH_ADDR" ]; then
|
||||||
ETH_IFACE="${ETH_IFACE:-eth0}"
|
ETH_IFACE="${ETH_IFACE:-eth0}"
|
||||||
cat <<end_of_file > "/etc/systemd/network/$ETH_IFACE.network"
|
make_static_iface "$ETH_IFACE" "$ETH_ADDR" "$ETH_GW" "$ETH_DNS"
|
||||||
[Match]
|
|
||||||
Name=$ETH_IFACE
|
|
||||||
|
|
||||||
[Network]
|
|
||||||
Address=$ETH_ADDR
|
|
||||||
DNS=$ETH_DNS
|
|
||||||
DNSSEC=no
|
|
||||||
|
|
||||||
[Route]
|
|
||||||
Gateway=$ETH_GW
|
|
||||||
end_of_file
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -178,18 +191,11 @@ fi
|
|||||||
# If the WIFI_ESSID is defined, configure wlan0
|
# If the WIFI_ESSID is defined, configure wlan0
|
||||||
if [ -n "$WIFI_ESSID" ]; then
|
if [ -n "$WIFI_ESSID" ]; then
|
||||||
WIFI_IFACE="${WIFI_IFACE:-wlan0}"
|
WIFI_IFACE="${WIFI_IFACE:-wlan0}"
|
||||||
cat <<end_of_file > "/etc/systemd/network/$WIFI_IFACE.network"
|
if [ -n "$WIFI_ADDR" ]; then
|
||||||
[Match]
|
make_static_iface "$WIFI_IFACE" "$WIFI_ADDR" "$WIFI_GW" "$WIFI_DNS"
|
||||||
Name=$WIFI_IFACE
|
else
|
||||||
|
make_dhcp_iface "$WIFI_IFACE"
|
||||||
[Network]
|
fi
|
||||||
DHCP=yes
|
|
||||||
DNSSEC=no
|
|
||||||
|
|
||||||
# Use same IP by forcing to use MAC address for clientID
|
|
||||||
[DHCP]
|
|
||||||
ClientIdentifier=mac
|
|
||||||
end_of_file
|
|
||||||
wpa_passphrase "$WIFI_ESSID" "$WIFI_PASSWD" > "/etc/wpa_supplicant/wpa_supplicant-$WIFI_IFACE.conf"
|
wpa_passphrase "$WIFI_ESSID" "$WIFI_PASSWD" > "/etc/wpa_supplicant/wpa_supplicant-$WIFI_IFACE.conf"
|
||||||
chmod 640 "/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
|
systemctl enable "wpa_supplicant@$WIFI_IFACE.service" || true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user