Skip to content

Instantly share code, notes, and snippets.

@tucq88
Created September 21, 2017 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tucq88/a653e7147ca3cfffea4ae908f9309d75 to your computer and use it in GitHub Desktop.
Save tucq88/a653e7147ca3cfffea4ae908f9309d75 to your computer and use it in GitHub Desktop.
De-procrastinate
# News
kenh14.vn
dantri.vn
vnexpress.net
genk.vn
tinhte.vn
nhattao.vn
# Social
www.facebok.com
facebook.com
# Entertainment
comicvn.net
vechai.info
truyentranh.com
#!/bin/bash
## Variables
## Block
function block {
cp list.txt list.tmp.txt
sed -i '/^$/d' list.tmp.txt # Delete blank lines
sed -i '/^#/! s/^/127.0.0.1 / ' list.tmp.txt # Append blocking address (localhost)
sed -i '1i ### DE-PROCRASTINATING - START ###' list.tmp.txt # Add header
sed -i '$a ### DE-PROCRASTINATING - STOP ###' list.tmp.txt # Add footer
sed r /etc/hosts list.tmp.txt > hosts.tmp # Add to host tmp
mv hosts.tmp /etc/hosts # Override actual host
rm -rf list.tmp.txt hosts.tmp # Cleanup
echo 'Get focus!!!'
}
function unblock {
sed -i '/### DE-PROCRASTINATING - START ###/,/### DE-PROCRASTINATING - STOP ###/d' /etc/hosts
echo 'Time to play'
}
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root, use sudo "$0" instead" 1>&2
exit 1
fi
if grep -q "### DE-PROCRASTINATING - START ###" /etc/hosts
then
unblock
else
block
fi
/usr/sbin/apachectl restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment