Skip to content

Instantly share code, notes, and snippets.

@Slamdunk
Last active December 22, 2023 08:15
Show Gist options
  • Save Slamdunk/3f31dd269f6d3bf42c49297eb0bdd379 to your computer and use it in GitHub Desktop.
Save Slamdunk/3f31dd269f6d3bf42c49297eb0bdd379 to your computer and use it in GitHub Desktop.
Debian `hosts` updater for DNS block
#!/bin/sh
set -e
tmp="$(mktemp)"
file="/etc/hosts"
wget --quiet -O "${tmp}" https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling/hosts
if [ ! -s "$file" ]; then
exit 0
fi
sed -i 's/\(\slocalhost\)$/\1 '"$(hostname)"'/g' "${tmp}"
if cmp --silent -- "${file}" "${tmp}"; then
rm --force "${tmp}"
exit 0
fi
chown --reference="${file}" "${tmp}"
chmod --reference="${file}" "${tmp}"
mv --no-target-directory --force "${tmp}" "${file}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment