Skip to content

Instantly share code, notes, and snippets.

@m-manu
Created September 28, 2019 13:40
Show Gist options
  • Save m-manu/906fc6b2fded78213b02717c6b7efbf7 to your computer and use it in GitHub Desktop.
Save m-manu/906fc6b2fded78213b02717c6b7efbf7 to your computer and use it in GitHub Desktop.
Disable ads & disable tracking
function hosts() {
if [ $# -eq 0 ]; then
hosts_file_num_lines=$(wc -l /etc/hosts | awk '{print $1}')
marker_string_frequency=$(grep StevenBlack /etc/hosts | wc -l)
if [ "$marker_string_frequency" -gt 1 ]; then
echo -e $COLOR_GREEN"/etc/hosts file contains entries for AdBlock"$COLOR_RESET" (contains $hosts_file_num_lines lines)"
else
echo -e $COLOR_GREEN"/etc/hosts file is right now pristine"$COLOR_RESET" (contains $hosts_file_num_lines lines)"
fi
elif [ $# -eq 1 ]; then
if [ "$1" = "pristine" ]; then
if [ -f /etc/hosts_pristine ]; then
sudo cp -v /etc/hosts_pristine /etc/hosts
echo -e $COLOR_GREEN"Replaced /etc/hosts file with a pristine one"$COLOR_RESET
else
err "File /etc/hosts_pristine doesn't exist!"
fi
elif [ "$1" = "adblock" ]; then
if [ -f /etc/hosts_pristine -a -f /etc/hosts_adblock ]; then
sudo bash -c 'cat /etc/hosts_pristine /etc/hosts_adblock > /etc/hosts'
echo -e $COLOR_GREEN"Replaced /etc/hosts file with an AdBlock one"$COLOR_RESET
else
err "Either /etc/hosts_pristine or /etc/hosts_adblock (or both) missing!"
fi
elif [ "$1" = "update" ]; then
wc /etc/hosts_adblock
sudo bash -c 'curl https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts > /etc/hosts_adblock'
wc /etc/hosts_adblock
echo -e $COLOR_BLUE"Updated /etc/hosts_adblock from internet"$COLOR_RESET
else
err "Invalid parameter: $1"
fi
else
err "Invalid number of arguments!"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment