Created
September 21, 2017 02:50
-
-
Save tucq88/a653e7147ca3cfffea4ae908f9309d75 to your computer and use it in GitHub Desktop.
De-procrastinate
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
# 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 |
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 | |
## 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