From 228b5c2e0e90966a5cb5947b0205531c439b99e8 Mon Sep 17 00:00:00 2001 From: yinjiaji Date: Sat, 13 Apr 2024 16:48:41 +0800 Subject: [PATCH 1/3] Add macOS homebrew support for install.sh --- README.md | 2 +- install.sh | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d67033cd3f..13911d5b79 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ 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. Run it as root: `sudo ./install.sh`, or if you use Homebrew on macOS: `sudo bash ./install.sh /opt/homebrew/etc/dnsmasq.d` You can save the installer and run it again to update the list regularly. diff --git a/install.sh b/install.sh index 5a3c2b611f..37237bf6b2 100755 --- a/install.sh +++ b/install.sh @@ -2,6 +2,7 @@ set -e WORKDIR="$(mktemp -d)" +CONFDIR=${1:-"/etc/dnsmasq.d"} SERVERS=(114.114.114.114 114.114.115.115 223.5.5.5 119.29.29.29) # Others: 223.6.6.6 119.28.28.28 # Not using best possible CDN pop: 1.2.4.8 210.2.4.8 @@ -22,20 +23,20 @@ git clone --depth=1 https://gitee.com/felixonmars/dnsmasq-china-list.git "$WORKD echo "Removing old configurations..." for _conf in "${CONF_WITH_SERVERS[@]}" "${CONF_SIMPLE[@]}"; do - rm -f /etc/dnsmasq.d/"$_conf"*.conf + rm -f "$CONFDIR"/"$_conf"*.conf done echo "Installing new configurations..." for _conf in "${CONF_SIMPLE[@]}"; do - cp "$WORKDIR/$_conf.conf" "/etc/dnsmasq.d/$_conf.conf" + cp "$WORKDIR/$_conf.conf" "$CONFDIR/$_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" + cp "$WORKDIR/$_conf.conf" "$CONFDIR/$_conf.$_server.conf" done - sed -i "s|^\(server.*\)/[^/]*$|\1/$_server|" /etc/dnsmasq.d/*."$_server".conf + sed -i "" "s|^\(server.*\)/[^/]*$|\1/$_server|" $CONFDIR/*."$_server".conf done echo "Restarting dnsmasq service..." @@ -47,6 +48,8 @@ elif hash rc-service 2>/dev/null; then rc-service dnsmasq restart elif hash busybox 2>/dev/null && [[ -d "/etc/init.d" ]]; then /etc/init.d/dnsmasq restart +elif hash brew 2>/dev/null; then + brew services restart dnsmasq else echo "Now please restart dnsmasq since I don't know how to do it." fi From f21b5eec07ec08099a6d5e34d1fd8523127a4063 Mon Sep 17 00:00:00 2001 From: yinjiaji Date: Sun, 14 Apr 2024 14:17:58 +0800 Subject: [PATCH 2/3] Fix sed i option in linux & macOS, add macOS default config folder --- README.md | 2 +- install.sh | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 13911d5b79..d67033cd3f 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ 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`, or if you use Homebrew on macOS: `sudo bash ./install.sh /opt/homebrew/etc/dnsmasq.d` +3. Run it as root: `sudo ./install.sh` You can save the installer and run it again to update the list regularly. diff --git a/install.sh b/install.sh index 37237bf6b2..903abd975f 100755 --- a/install.sh +++ b/install.sh @@ -1,8 +1,17 @@ #!/bin/bash set -e +SEDI=(-i) +DEFAULTCONFDIR="/etc/dnsmasq.d" +case "$(uname)" in + Darwin*) + DEFAULTCONFDIR="/opt/homebrew/etc/dnsmasq.d" + SEDI=(-i "") +esac + WORKDIR="$(mktemp -d)" -CONFDIR=${1:-"/etc/dnsmasq.d"} +CONFDIR=${1:-$DEFAULTCONFDIR} +echo "conf dir $CONFDIR" SERVERS=(114.114.114.114 114.114.115.115 223.5.5.5 119.29.29.29) # Others: 223.6.6.6 119.28.28.28 # Not using best possible CDN pop: 1.2.4.8 210.2.4.8 @@ -11,6 +20,7 @@ SERVERS=(114.114.114.114 114.114.115.115 223.5.5.5 119.29.29.29) 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" @@ -36,7 +46,7 @@ for _server in "${SERVERS[@]}"; do cp "$WORKDIR/$_conf.conf" "$CONFDIR/$_conf.$_server.conf" done - sed -i "" "s|^\(server.*\)/[^/]*$|\1/$_server|" $CONFDIR/*."$_server".conf + sed "${SEDI[@]}" "s|^\(server.*\)/[^/]*$|\1/$_server|" $CONFDIR/*."$_server".conf done echo "Restarting dnsmasq service..." From b85544040f3adaa4681bba59df2df6f718bf95ae Mon Sep 17 00:00:00 2001 From: yinjiaji Date: Sun, 14 Apr 2024 14:23:39 +0800 Subject: [PATCH 3/3] Remove no need log --- install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install.sh b/install.sh index 903abd975f..d12a396107 100755 --- a/install.sh +++ b/install.sh @@ -11,7 +11,6 @@ esac WORKDIR="$(mktemp -d)" CONFDIR=${1:-$DEFAULTCONFDIR} -echo "conf dir $CONFDIR" SERVERS=(114.114.114.114 114.114.115.115 223.5.5.5 119.29.29.29) # Others: 223.6.6.6 119.28.28.28 # Not using best possible CDN pop: 1.2.4.8 210.2.4.8