-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·163 lines (149 loc) · 4.6 KB
/
install.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
# Install script for adblock
usage() {
echo "Usage: `basename $0` [-d] [-f] [-h]"
echo " -d Install dhclient-exit-hook to switch between local and network DNS server based on the network"
echo " -f Force overwrite of adblock zone file, if it already exists"
echo " -h This help text"
exit ${1:-1}
}
dhclient=false
force=false
while getopts ":dfh" option; do
case $option in
d )
dhclient=true ;;
f )
force=true ;;
h )
usage 0 ;;
* )
usage ;;
esac
done
shift $((OPTIND-1))
layout=unknown
case `uname -s` in
FreeBSD )
layout=freebsd ;;
OpenBSD )
layout=openbsd ;;
Linux )
if test -f /etc/debian_version || test -f /etc/devuan_version; then
layout=debian
fi
;;
esac
if [ $layout = unknown ]; then
echo "Sorry, I don't know how to install adblock on your system." 1>&2
exit 2
fi
# use two stages so that multiple systems can use the same layout.
echo Using $layout layout.
case $layout in
freebsd )
if test -d /usr/local/etc/namedb; then
named_config=/usr/local/etc/namedb
else
named_config=/etc/namedb
fi
named_etc=$named_config
named_etc_subdir=
named_adblock_conf=$named_etc/named-adblock.conf
named_conf=$named_etc/named.conf
named_zone=$named_config/master/adblock
named_restart_cmd="rndc reload"
adblock_dir=/usr/local/sbin
adblock_conf_dir=/usr/local/etc
if $dhclient; then
echo "Don't know where dhclient exit hook file should be placed' 1>&2
exit 1
fi
dhclient_exit_hook=
;;
openbsd )
named_config=/var/named
named_etc=$named_config/etc
named_etc_subdir=etc/
named_adblock_conf=$named_etc/named-adblock.conf
named_conf=$named_etc/named.conf
# openbsd runs bind in chroot, path is relative to chroot here
named_zone=master/adblock
named_restart_cmd="rndc reload"
adblock_dir=/usr/local/sbin
adblock_conf_dir=/etc
if $dhclient; then
echo "Don't know where dhclient exit hook file should be placed' 1>&2
exit 1
fi
dhclient_exit_hook=
;;
debian )
named_config=/etc/bind
named_etc=$named_config
named_etc_subdir=
named_adblock_conf=$named_etc/named.conf.adblock
named_conf=$named_etc/named.conf.local
named_zone=$named_config/db.adblock
if test -x /etc/init.d/bind9; then
init_script=/etc/init.d/bind9
elif test -x /etc/init.d/named; then
init_script=/etc/init.d/named
else
echo "Missing bind9 init script or it is installed in an unsupported location" 1>&2
exit 1
fi
named_restart_cmd="$init_script reload"
adblock_dir=/usr/local/sbin
adblock_conf_dir=/etc
dhclient_exit_hook=/etc/dhcp/dhclient-exit-hooks.d/adblock
;;
esac
cd $(dirname "$0")
install_cmd="install -o root -g root"
eval $install_cmd -d -m 755 $adblock_dir || exit 3
eval $install_cmd -m 755 adblock $adblock_dir || exit 3
eval $install_cmd -d -m 755 $adblock_conf_dir || exit 3
# -i option to sed is nonportable, and does not exist on openbsd in particular
# don't use / as separator as it occurs in paths
if test -f $adblock_conf_dir/adblock.conf; then
if $force; then
install_conf=true
else
install_conf=false
echo "You already have adblock configuration file, $adblock_conf_dir/adblock.conf." 1>&2
echo "To replace it, use the -f option." 1>&2
fi
else
install_conf=true
fi
if $install_conf; then
sed \
-e "s:NAMED_ETC=\".*\":NAMED_ETC=\"$named_etc\":" \
-e "s:NAMED_ADBLOCK_CONF=\"\":NAMED_ADBLOCK_CONF=\"$named_adblock_conf\":" \
-e "s:ADBLOCK_ZONE_FILE=\"\":ADBLOCK_ZONE_FILE=\"$named_zone\":" \
-e "s:NAMED_RESTART_CMD=\".*\":NAMED_RESTART_CMD=\"$named_restart_cmd\":" \
adblock.conf-sample >$adblock_conf_dir/adblock.conf || exit 3
chmod 0644 $adblock_conf_dir/adblock.conf || exit 3
fi
if [ ! -e $named_adblock_conf ]; then
touch $named_adblock_conf || exit 3
fi
if test $dhclient; then
eval $install_cmd -m 755 dhclient-exit-hook $dhclient_exit_hook
fi
if [ $force = false ] && [ -e $named_zone ]; then
echo "You already have adblock zone file, $named_zone." 1>&2
echo "To replace it, use the -f option." 1>&2
else
eval $install_cmd -m 644 named.zone.adblock $named_zone || exit 3
echo "You will probably want to edit the adblock zone file, $named_zone,"
echo "to be appropriate for your network."
fi
if ! fgrep -q "$named_adblock_conf" $named_conf |fgrep -q include ; then
echo
echo "You will need to add a directive to include $named_adblock_conf into your $named_conf."
echo "If you have a standard installation, you can do:"
echo
echo "echo 'include \"$named_adblock_conf\";' >> $named_conf"
fi