From 1e807e888caed5d5ef226d9aad471756acc2c083 Mon Sep 17 00:00:00 2001 From: Aminda Suomalainen Date: Thu, 9 May 2024 09:38:25 +0300 Subject: [PATCH] etc: add NetworkManager-resolv.conf-restore.bash --- etc/NetworkManager-resolv.conf-restore.bash | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 etc/NetworkManager-resolv.conf-restore.bash diff --git a/etc/NetworkManager-resolv.conf-restore.bash b/etc/NetworkManager-resolv.conf-restore.bash new file mode 100755 index 00000000..e6d7360c --- /dev/null +++ b/etc/NetworkManager-resolv.conf-restore.bash @@ -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