-
Notifications
You must be signed in to change notification settings - Fork 940
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·68 lines (59 loc) · 2.47 KB
/
install.sh
File metadata and controls
executable file
·68 lines (59 loc) · 2.47 KB
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
#!/bin/bash
set -e
WORKDIR="$(mktemp -d)"
SERVERS=(114.114.114.114 114.114.115.115 180.76.76.76)
# Not using best possible CDN pop: 1.2.4.8 210.2.4.8 223.5.5.5 223.6.6.6
# Dirty cache: 119.29.29.29 182.254.116.116
CONF_WITH_SERVERS=(accelerated-domains.china google.china apple.china)
CONF_SIMPLE=(bogus-nxdomain.china)
echo "Downloading latest configurations..."
git clone --depth=1 https://gitee.com/felixonmars/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://pagure.io/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://github.com/felixonmars/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://bitbucket.org/felixonmars/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://gitlab.com/felixonmars/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://codehub.devcloud.huaweicloud.com/dnsmasq-china-list00001/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 https://code.aliyun.com/felixonmars/dnsmasq-china-list.git "$WORKDIR"
#git clone --depth=1 http://repo.or.cz/dnsmasq-china-list.git "$WORKDIR"
echo "Removing old configurations..."
for _conf in "${CONF_WITH_SERVERS[@]}" "${CONF_SIMPLE[@]}"; do
rm -f /etc/dnsmasq.d/"$_conf"*.conf
done
# In MacOs,command cp will not create an empty folder if it doesn't exist,
# so command below will fail.
# cp "$WORKDIR/$_conf.conf" "/etc/dnsmasq.d/$_conf.conf"
KERNAL_TYPE="$(uname -a|awk '{print $1}')"
if [ "$KERNAL_TYPE" = "Darwin" ];then
if [ ! -d "/etc/dnsmasq.d" ]; then
mkdir /etc/dnsmasq.d
fi
fi
echo "Installing new configurations..."
for _conf in "${CONF_SIMPLE[@]}"; do
cp "$WORKDIR/$_conf.conf" "/etc/dnsmasq.d/$_conf.conf"
done
for _server in "${SERVERS[@]}"; do
for _conf in "${CONF_WITH_SERVERS[@]}"; do
cp "$WORKDIR/$_conf.conf" "/etc/dnsmasq.d/$_conf.$_server.conf"
done
# It need a white character after sed -i on MacOs.
if [ "$KERNAL_TYPE" = "Darwin" ];then
sed -i "" "s|^\(server.*\)/[^/]*$|\1/$_server|" /etc/dnsmasq.d/*."$_server".conf
else
sed -i "s|^\(server.*\)/[^/]*$|\1/$_server|" /etc/dnsmasq.d/*."$_server".conf
fi
done
echo "Restarting dnsmasq service..."
if hash systemctl 2>/dev/null; then
systemctl restart dnsmasq
elif hash service 2>/dev/null; then
service dnsmasq restart
elif hash rc-service 2>/dev/null; then
rc-service dnsmasq restart
elif hash brew 2>/dev/null; then
sudo brew services restart dnsmasq # for macos
else
echo "Now please restart dnsmasq since I don't know how to do it."
fi
echo "Cleaning up..."
rm -r "$WORKDIR"