Last active
August 23, 2017 19:05
-
-
Save raymanfx/32d2345cdcbe615e51290ceb46e8f051 to your computer and use it in GitHub Desktop.
Spotify adblock host entries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOSTS_FILE="/etc/hosts" | |
# check if we are root | |
USER_ID=`id -u` | |
if [ "$USER_ID" != '0' ]; then | |
echo "This script must be run with root permissions, try again." | |
exit 1 | |
fi | |
ENTRIES="# spotiblock.sh start | |
# Spotify adblock entries | |
127.0.0.1 media-match.com | |
127.0.0.1 adclick.g.doublecklick.net | |
127.0.0.1 www.googleadservices.com | |
127.0.0.1 open.spotify.com | |
127.0.0.1 pagead2.googlesyndication.com | |
127.0.0.1 desktop.spotify.com | |
127.0.0.1 googleads.g.doubleclick.net | |
127.0.0.1 pubads.g.doubleclick.net | |
127.0.0.1 securepubads.g.doubleclick.net | |
127.0.0.1 audio2.spotify.com | |
127.0.0.1 www.omaze.com | |
127.0.0.1 omaze.com | |
127.0.0.1 bounceexchange.com | |
127.0.0.1 core.insightexpressai.com | |
127.0.0.1 content.bitsontherun.com | |
127.0.0.1 s0.2mdn.net | |
127.0.0.1 v.jwpcdn.com | |
127.0.0.1 d2gi7ultltnc2u.cloudfront.net | |
127.0.0.1 crashdump.spotify.com | |
127.0.0.1 adeventtracker.spotify.com | |
127.0.0.1 log.spotify.com | |
127.0.0.1 analytics.spotify.com | |
127.0.0.1 ads-fa.spotify.com | |
# spotiblock.sh end" | |
# check if the script has already been applied | |
updated_entries=false | |
result=`cat $HOSTS_FILE | grep "spotiblock.sh"` | |
if [ "$result" != '' ]; then | |
old_buf="" | |
read_block=false | |
while read -r line; do | |
if [ "$line" == "# spotiblock.sh start" ]; then | |
read_block=true | |
elif [ "$line" == "# spotiblock.sh end" ]; then | |
old_buf="$old_buf$line" | |
break | |
fi | |
if [ $read_block == true ]; then | |
old_buf="$old_buf$line"$'\n' | |
fi | |
done < $HOSTS_FILE | |
if [ "$old_buf" == "$ENTRIES" ] && [ "$1" != "-f" ]; then | |
echo "spotiblock.sh has already been run, entries are up to date." | |
echo "If you really want to run again, force execution using -f." | |
exit 0 | |
fi | |
echo "spotiblock.sh has already been run, updating entries." | |
echo "difference (new+ vs old-):" | |
diff -u <(echo "$old_buf") <(echo "$ENTRIES") | |
remove_line=false | |
while read -r line; do | |
if [ "$line" == "# spotiblock.sh start" ]; then | |
remove_line=true | |
elif [ "$line" == "# spotiblock.sh end" ]; then | |
sed -i '' "/$line/d" $HOSTS_FILE | |
break | |
fi | |
if [ $remove_line == true ]; then | |
sed -i '' "/$line/d" $HOSTS_FILE | |
fi | |
done < $HOSTS_FILE | |
updated_entries=true | |
fi | |
# write entries to hosts file | |
if [ $updated_entries == false ]; then | |
ENTRIES=$'\n'"$ENTRIES" | |
fi | |
echo "$ENTRIES" >> $HOSTS_FILE | |
# check if entries were written successfully | |
result=`cat $HOSTS_FILE | grep "spotiblock.sh"` | |
if [ "$result" == '' ]; then | |
echo "Could not add adblock entries to $HOSTS_FILE!" | |
exit 1 | |
fi | |
echo "Spotify adblock entries successfully written to $HOSTS_FILE!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment