Restarting network isn't mandatory

This commit is contained in:
Yann Esposito (Yogsototh) 2011-11-17 15:19:51 +01:00
parent f4a2be4157
commit 1e6aa7108f

View file

@ -5,8 +5,10 @@
exit 1;
}
action="$1"
hostfile=/etc/hosts
backupfile=$hostfile.orig
blacklistedhostfile=$hostfile.blacklist
blacklist=( 'reddit.com'
'forums.somethingawful.com'
@ -35,19 +37,26 @@ blacklist=( 'reddit.com'
'yelp.com'
'slashdot.org' )
case $1 in
work)
[[ -e $backupfile ]] && {
exit 1
}
function initialize() {
[[ ! -e $backupfile ]] && {
\cp $hostfile $backupfile
}
[[ ! -e $blacklistedhostfile ]] && {
\cp $hostfile $blacklistedhostfile
for site in $blacklist; do
print -- "127.0.0.1\t$site"
print -- "127.0.0.1\twww.$site"
done >> $hostfile
done >> $blacklistedhostfile
}
}
function switch_hostfile() {
case $action in
work)
\cp $blacklistedhostfile $hostfile
;;
play)
\cp $backupfile $hostfile && \rm $backupfile
play|pause)
\cp $backupfile $hostfile
;;
*)
{
@ -56,8 +65,8 @@ play)
exit 1
} >&2
esac
}
[[ -e /etc/init.d/networking ]] && {
/etc/init.d/networking stop &&
/etc/init.d/networking start
} >/dev/null >&2
# create backupfile and blacklisted file
initialize
switch_hostfile