-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-netplan.sh
More file actions
executable file
·68 lines (51 loc) · 2.44 KB
/
setup-netplan.sh
File metadata and controls
executable file
·68 lines (51 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
netplan_dir="/etc/netplan"
# get env vars
netplan_if_name=`printenv NET_IF_NAME`
netplan_if_mac=`printenv NET_IF_MACADDRESS`
netplan_if_mtu=`printenv NET_IF_MTU`
netplan_wifi_if_name=`printenv NET_WIFI_IF_NAME`
netplan_wifi_auth_ssid=`printenv NET_WIFI_AUTH_SSID`
netplan_wifi_auth_pass=`printenv NET_WIFI_AUTH_PASS`
# remove networkmanager control
rm ${netplan_dir}/01-network-manager-all.yaml 2>/dev/null
# remove installer config
rm ${netplan_dir}/00-installer-config.yaml 2>/dev/null
# switch net management to networkd
cp ./01-networkd-all.yaml ${netplan_dir}/
# copy ethernet interface template
net_config_eth="02-net-if-config.yaml"
cp ./${net_config_eth} ${netplan_dir}/
# replace env vars
sed -i "s/\[NET_IF_NAME\]/${netplan_if_name}/g" ${netplan_dir}/${net_config_eth}
sed -i "s/\[NET_IF_MACADDRESS\]/${netplan_if_mac}/g" ${netplan_dir}/${net_config_eth}
sed -i "s/\[NET_IF_MTU\]/${netplan_if_mtu}/g" ${netplan_dir}/${net_config_eth}
# copy wifi interface template
if [ -n "${netplan_wifi_if_name}" ]; then
net_config_wifi="03-net-wifi-config.yaml"
cp ./${net_config_wifi} ${netplan_dir}/
# escape special chars in wifi passphrase
netplan_wifi_auth_pass=$(echo ${netplan_wifi_auth_pass} | sed 's/\\/\\\\\\\\\\\\\\\\\\/g')
# replace env vars
sed -i "s/\[NET_WIFI_IF_NAME\]/${netplan_wifi_if_name}/g" ${netplan_dir}/${net_config_wifi}
sed -i "s/\[NET_WIFI_AUTH_SSID\]/${netplan_wifi_auth_ssid}/g" ${netplan_dir}/${net_config_wifi}
sed -i "s/\[NET_WIFI_AUTH_PASS\]/${netplan_wifi_auth_pass}/g" ${netplan_dir}/${net_config_wifi}
# copy global networkmanager dns config
cp ./wifi-networkmanager-dns.conf /etc/NetworkManager/conf.d/90-dns.conf
chown root:root /etc/NetworkManager/conf.d/90-dns.conf
chmod 600 /etc/NetworkManager/conf.d/90-dns.conf
# copy global networkmanager p2p device config (disable)
cp ./wifi-networkmanager-p2p.conf /etc/NetworkManager/conf.d/91-wifi-p2p.conf
sed -i "s/\[NET_WIFI_IF_NAME\]/${netplan_wifi_if_name}/g" /etc/NetworkManager/conf.d/91-wifi-p2p.conf
chown root:root /etc/NetworkManager/conf.d/91-wifi-p2p.conf
chmod 600 /etc/NetworkManager/conf.d/91-wifi-p2p.conf
# enable ccm, cmac kernel module loading on boot
touch /etc/modules-load.d/wifi.conf
echo "ccm" > /etc/modules-load.d/wifi.conf
echo "cmac" >> /etc/modules-load.d/wifi.conf
fi
# set permissions
chown root:root ${netplan_dir}/*
chmod 600 ${netplan_dir}/*
# apply settings
netplan apply