As far as I understand netplan merges all configuration files.
So for those of you who pass by here looking for a general solution I have to offer this based on the current 24.04 LTS Desktop:
#!/bin/bash
Get the names of all interfaces.
Filter interfaces with grep which you don't need.
Could also be done with jq if one wants to spend more time on it.
mapfile -t interfaces < <(
ip -json -pretty link show
| jq -r ".[].ifname"
| grep -vE "(bond|lo|tailscale)"
)
[[ -z "${interfaces[*]}" ]] && {
echo "Error: No interfaces selected."
exit 1
}
Create upper part of the temporary service unit.
tmp_file_netplan="$(mktemp)"
tee "${tmp_file_netplan}" > "/dev/null" << EOF
network:
version: 2
renderer: NetworkManager
ethernets:
EOF
for interface in "${interfaces[@]}"; do
tee -a "${tmp_file_netplan}" > "/dev/null" << EOF
${interface}:
wakeonlan: true
EOF
done
Install the file and apply the new configuration
sudo mv -v "${tmp_file_netplan}" "/etc/netplan/02-wol.yaml"
sudo netplan apply
I had an invocation of gum to interactively select interfaces (gum choose --no-limit). But lets stick to a solution here that works out of the box for every one.
If you are using the Server variant or a different version you have to check the other configuration files if something else than renderer: NetworkManager is used and decide what's best.