From 5b9a9595a6c66ad2f11206994d76ed97d3f1dab7 Mon Sep 17 00:00:00 2001 From: lichuanyi Date: Sun, 23 Feb 2020 01:40:39 +0800 Subject: [PATCH] fix:install.sh no x right&&macos cp new folder problem&&sed need a white character&&start dnsmasq --- README.md | 3 ++- install.sh | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d67033cd3f7cf..e13354f861954 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/install.sh b/install.sh index a54d84afe517f..a14d5126f9ef7 100755 --- a/install.sh +++ b/install.sh @@ -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" @@ -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..." @@ -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