Instantly share code, notes, and snippets.

Embed
What would you like to do?
hosts block autofetcher
#!/bin/bash
# fetch the new block list
wget 'https://v.firebog.net/hosts/lists.php?type=all' -O list_all
# reset the old hosts directory
rm -r all_hosts
mkdir all_hosts
# read the file and download into the all_hosts directory
while read a; do
wget -P all_hosts "$a"
done < list_all
# fill the all_blocks file with the fixed up lines of all the hosts files
rm all_blocks
for a in $(command ls -1 all_hosts); do
sed -f fix_host.sed "all_hosts/$a" >> all_blocks
done
# sort and uniq it
sed -f fix_host.sed all_blocks | sort | uniq > all_blocks.uniq
mv all_blocks.uniq all_blocks
/^#/d
/^\s*$/d
s/\s\+/ /g
s/0.0.0.0/127.0.0.1/
/^127.0.0.1/!d
s/[ \t]*$//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment