etc: add NetworkManager-resolv.conf-restore.bash

This commit is contained in:
Aminda Suomalainen 2024-05-09 09:38:25 +03:00
parent 6567488801
commit 1e807e888c
Signed by: Mikaela
SSH Key Fingerprint: SHA256:CXLULpqNBdUKB6E6fLA1b/4SzG0HvKD19PbIePU175Q

View File

@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -x
# I learned that not only systemd-resolved does this, but NetworkManager as
# well. I think it's even less likely I use this than the systemd-resolved
# one, but anyway
# I know there are old versions that used something else, but I don't remember
# that name and they are ancient.
if ! hash nmcli 2>/dev/null; then
echo "You don't seem to have NetworkManager (or nmcli) installed." 1>&2
exit 1
fi
# Require root or exit
if [ "$(id -u)" != "0" ]; then
echo "This script requires root." 1>&2
exit 1
fi
# It's pointless to make a dead symlink as it must be running
systemctl enable --now NetworkManager.service
# In case I am behind the /etc/resolv.conf, it's immutable and read-only,
# which won't allow it to be rewritten.
chattr -V -i /etc/resolv.conf
chmod -v +w /etc/resolv.conf
# It must be removed if it's not a symlink
rm -v /etc/resolv.conf
# and finally making the symlink
ln -sfv /var/run/NetworkManager/resolv.conf /etc/resolv.conf
# Let's just see it's ok
ls -l /etc/resolv.conf
cat /etc/resolv.conf
set +x