Restarting network isn't mandatory
This commit is contained in:
parent
f4a2be4157
commit
1e6aa7108f
1 changed files with 33 additions and 24 deletions
|
@ -5,8 +5,10 @@
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
action="$1"
|
||||||
hostfile=/etc/hosts
|
hostfile=/etc/hosts
|
||||||
backupfile=$hostfile.orig
|
backupfile=$hostfile.orig
|
||||||
|
blacklistedhostfile=$hostfile.blacklist
|
||||||
|
|
||||||
blacklist=( 'reddit.com'
|
blacklist=( 'reddit.com'
|
||||||
'forums.somethingawful.com'
|
'forums.somethingawful.com'
|
||||||
|
@ -35,29 +37,36 @@ blacklist=( 'reddit.com'
|
||||||
'yelp.com'
|
'yelp.com'
|
||||||
'slashdot.org' )
|
'slashdot.org' )
|
||||||
|
|
||||||
case $1 in
|
function initialize() {
|
||||||
work)
|
[[ ! -e $backupfile ]] && {
|
||||||
[[ -e $backupfile ]] && {
|
\cp $hostfile $backupfile
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
\cp $hostfile $backupfile
|
[[ ! -e $blacklistedhostfile ]] && {
|
||||||
for site in $blacklist; do
|
\cp $hostfile $blacklistedhostfile
|
||||||
print -- "127.0.0.1\t$site"
|
for site in $blacklist; do
|
||||||
print -- "127.0.0.1\twww.$site"
|
print -- "127.0.0.1\t$site"
|
||||||
done >> $hostfile
|
print -- "127.0.0.1\twww.$site"
|
||||||
;;
|
done >> $blacklistedhostfile
|
||||||
play)
|
}
|
||||||
\cp $backupfile $hostfile && \rm $backupfile
|
}
|
||||||
;;
|
|
||||||
*)
|
|
||||||
{
|
|
||||||
print -- "I don't know this option: '$*'"
|
|
||||||
print -- "use ${0:t} work or ${0:t} play"
|
|
||||||
exit 1
|
|
||||||
} >&2
|
|
||||||
esac
|
|
||||||
|
|
||||||
[[ -e /etc/init.d/networking ]] && {
|
function switch_hostfile() {
|
||||||
/etc/init.d/networking stop &&
|
case $action in
|
||||||
/etc/init.d/networking start
|
work)
|
||||||
} >/dev/null >&2
|
\cp $blacklistedhostfile $hostfile
|
||||||
|
;;
|
||||||
|
play|pause)
|
||||||
|
\cp $backupfile $hostfile
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
{
|
||||||
|
print -- "I don't know this option: '$*'"
|
||||||
|
print -- "use ${0:t} work or ${0:t} play"
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# create backupfile and blacklisted file
|
||||||
|
initialize
|
||||||
|
switch_hostfile
|
||||||
|
|
Loading…
Reference in a new issue