Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some problems for MacOs and readme.md #289

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Automatic Installation (recommended)

1. Fetch the installer from github (or a mirror): `wget https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/install.sh`
2. (Optional) Edit it to use your favorite DNS server and/or another mirror to download the list.
3. Run it as root: `sudo ./install.sh`
3. Grant it executable rights: `chmod +x install.sh`
4. Run it as root: `sudo ./install.sh`

You can save the installer and run it again to update the list regularly.

Expand Down
20 changes: 18 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ 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"
Expand All @@ -33,8 +43,12 @@ for _server in "${SERVERS[@]}"; do
for _conf in "${CONF_WITH_SERVERS[@]}"; do
cp "$WORKDIR/$_conf.conf" "/etc/dnsmasq.d/$_conf.$_server.conf"
done

sed -i "s|^\(server.*\)/[^/]*$|\1/$_server|" /etc/dnsmasq.d/*."$_server".conf
# 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..."
Expand All @@ -44,6 +58,8 @@ 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
Expand Down