From 44de66dd2a5a3954ad544096e2f300e0fe7efd8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20P=C3=A9ch=C3=A8r?= Date: Fri, 10 Oct 2025 15:18:38 +0100 Subject: [PATCH] Create migration to symlink systemd-resolved (#2313) * Backup file if modified since system birth * Symlink /etc/resolv.conf -> systemd-resolve's stub resolver --- migrations/1759355846.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 migrations/1759355846.sh diff --git a/migrations/1759355846.sh b/migrations/1759355846.sh new file mode 100644 index 0000000..40d0098 --- /dev/null +++ b/migrations/1759355846.sh @@ -0,0 +1,21 @@ +echo "Symlink systemd-resolved to /etc/resolv.conf" + +# Backup if /etc/resolv.conf was modified after system birth +system_birth=$(stat -c %W /) +resolvconf_modified=$(stat -c %Y /etc/resolv.conf) + +# Run a backup if resolv.conf isn't a symlink and was modified after install +if [[ -s /etc/resolv.conf ]] && [[ ! -L /etc/resolv.conf ]] && [[ $resolvconf_modified > $system_birth ]]; then + # Backup the destination file (with timestamp) to avoid clobbering (Ex: resolv.conf.bak.1753817951) + backup_file="/etc/resolv.conf.bak.$(date +%s)" + + # Create backup + sudo cp -f /etc/resolv.conf "$backup_file" 2>/dev/null + + # Inform users + echo -e "\e[31mReplaced /etc/resolv.conf with symlink to systemd-resolved. \nSaved backup as ${backup_file}.\e[0m" + echo -e "\e[31mSee https://wiki.archlinux.org/title/Systemd-resolved.\e[0m" +fi + +# Write the symlink +sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf