-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.sh
executable file
·76 lines (60 loc) · 2.04 KB
/
cmd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
get_script_dir () {
# In case this script is symbolically linked from elsewhere
# Taken from https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
SOURCE=$1
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
}
export -f get_script_dir
SCRIPT_DIR=$(get_script_dir "${BASH_SOURCE[0]}")
source "${SCRIPT_DIR}/_shared.sh"
ciao () {
case "$1" in
list)
cat $F
return 0
;;
add)
echo "${2}" >> $F
;;
remove)
sed -i '' "/${2/\./\\.}/d" $F
;;
on)
touch $STATE
;;
off)
rm -rf $STATE
;;
*)
echo "$HELP_TEXT"
return 0
;;
esac
$SCRIPT_DIR/trigger.sh
}
HELP_TEXT="\
$CMD $VERSION
manage a list of _blocked domains_.
A _blocked domain_ will not receive any network requests.
Usage: $CMD <command> [<args>]
Available commands are:
list see the list of blocked domains
add <domain> add a new domain (like google.com) to the list of blocked domains
remove <domain> remove domain from the list of blocked domains [NOTE: must exactly match previous entries]
on start blocking requests to stored internet domains
off stop blocking requests. Restores /etc/hosts to original state.
Examples:
$CMD add facebook.com
$CMD remove facebook.com
$CMD off
$CMD on
NOTE! requests for added domains will be re-directed to:
IPv4 127.0.0.1
IPV6 fe80::1%lo0
For full documentation, see: https://github.com/adamtait/$CMD#readme"