From 71903eb27f7270b0df6eaf45e2ae507983d36099 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 28 Oct 2019 22:35:01 +0000 Subject: [PATCH 1/8] Add in checks to reset cloned repo to the lastest available release Signed-off-by: Adam Warner --- automated install/basic-install.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c887a6c6..47ecd125 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -408,6 +408,8 @@ make_repo() { # Set named variables for better readability local directory="${1}" local remoteRepo="${2}" + local curdir + # The message to display when this function is running str="Clone ${remoteRepo} into ${directory}" # Display the message and use the color table to preface the message with an "info" indicator @@ -421,10 +423,21 @@ make_repo() { git clone -q --depth 20 "${remoteRepo}" "${directory}" &> /dev/null || return $? # Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git) chmod -R a+rX "${directory}" - + # Make sure we know what directory we are in so we can move back into it + curdir="${PWD}" + # Move into the directory that was passed as an argument + cd "${directory}" &> /dev/null || return 1 + # Check current branch. If it is master, then reset to the latest availible tag. + # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) + curBranch = $(git rev-parse --abbrev-ref HEAD) + if [[ "${curBranch}" == "master" ]]; then #If we're calling make_repo() then it should always be master, we may not need to check. + git reset --hard $(git describe --abbrev=0) || return $? + fi # Show a colored message showing it's status printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" - # Always return 0? Not sure this is correct + + # Move back into the original directory + cd "${curdir}" &> /dev/null || return 1 return 0 } @@ -436,6 +449,7 @@ update_repo() { # This helps prevent the wrong value from being assigned if you were to set the variable as a GLOBAL one local directory="${1}" local curdir + local curBranch # A variable to store the message we want to display; # Again, it's useful to store these in variables in case we need to reuse or change the message; @@ -453,6 +467,12 @@ update_repo() { git clean --quiet --force -d || true # Okay for already clean directory # Pull the latest commits git pull --quiet &> /dev/null || return $? + # Check current branch. If it is master, then reset to the latest availible tag. + # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) + curBranch = $(git rev-parse --abbrev-ref HEAD) + if [[ "${curBranch}" == "master" ]]; then + git reset --hard $(git describe --abbrev=0) || return $? + fi # Show a completion message printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" # Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git) From 62c00ae1d83ecc7b29e1b2f1f31ba75e9f563b51 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 8 Nov 2019 19:11:55 +0000 Subject: [PATCH 2/8] pushd/popd instead of juggling with a variable Signed-off-by: Adam Warner --- automated install/basic-install.sh | 37 +++++++++++------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 47ecd125..d805e927 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -378,17 +378,13 @@ fi is_repo() { # Use a named, local variable instead of the vague $1, which is the first argument passed to this function # These local variables should always be lowercase - local directory="${1}" - # A local variable for the current directory - local curdir + local directory="${1}" # A variable to store the return code - local rc - # Assign the current directory variable by using pwd - curdir="${PWD}" + local rc # If the first argument passed to this function is a directory, if [[ -d "${directory}" ]]; then # move into the directory - cd "${directory}" + pushd "${directory}" &> /dev/null || return 1 # Use git to check if the directory is a repo # git -C is not used here to support git versions older than 1.8.4 git status --short &> /dev/null || rc=$? @@ -398,7 +394,7 @@ is_repo() { rc=1 fi # Move back into the directory the user started in - cd "${curdir}" + popd &> /dev/null || return 1 # Return the code; if one is not set, return 0 return "${rc:-0}" } @@ -408,7 +404,6 @@ make_repo() { # Set named variables for better readability local directory="${1}" local remoteRepo="${2}" - local curdir # The message to display when this function is running str="Clone ${remoteRepo} into ${directory}" @@ -422,11 +417,9 @@ make_repo() { # Clone the repo and return the return code from this command git clone -q --depth 20 "${remoteRepo}" "${directory}" &> /dev/null || return $? # Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git) - chmod -R a+rX "${directory}" - # Make sure we know what directory we are in so we can move back into it - curdir="${PWD}" + chmod -R a+rX "${directory}" # Move into the directory that was passed as an argument - cd "${directory}" &> /dev/null || return 1 + pushd "${directory}" &> /dev/null || return 1 # Check current branch. If it is master, then reset to the latest availible tag. # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) curBranch = $(git rev-parse --abbrev-ref HEAD) @@ -437,7 +430,7 @@ make_repo() { printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" # Move back into the original directory - cd "${curdir}" &> /dev/null || return 1 + popd &> /dev/null || return 1 return 0 } @@ -448,18 +441,14 @@ update_repo() { # but since they are local, their scope does not go beyond this function # This helps prevent the wrong value from being assigned if you were to set the variable as a GLOBAL one local directory="${1}" - local curdir local curBranch # A variable to store the message we want to display; # Again, it's useful to store these in variables in case we need to reuse or change the message; # we only need to make one change here local str="Update repo in ${1}" - - # Make sure we know what directory we are in so we can move back into it - curdir="${PWD}" - # Move into the directory that was passed as an argument - cd "${directory}" &> /dev/null || return 1 + # Move into the directory that was passed as an argument + pushd "${directory}" &> /dev/null || return 1 # Let the user know what's happening printf " %b %s..." "${INFO}" "${str}" # Stash any local commits as they conflict with our working code @@ -478,7 +467,7 @@ update_repo() { # Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git) chmod -R a+rX "${directory}" # Move back into the original directory - cd "${curdir}" &> /dev/null || return 1 + popd &> /dev/null || return 1 return 0 } @@ -517,7 +506,7 @@ resetRepo() { # Use named variables for arguments local directory="${1}" # Move into the directory - cd "${directory}" &> /dev/null || return 1 + pushd "${directory}" &> /dev/null || return 1 # Store the message in a variable str="Resetting repository within ${1}..." # Show the message @@ -528,7 +517,9 @@ resetRepo() { chmod -R a+rX "${directory}" # And show the status printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" - # Returning success anyway? + # Return to where we came from + popd &> /dev/null || return 1 + # Returning success anyway? return 0 } From c8b9e42649d296366adce0da35e08a4e5e629b97 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 8 Nov 2019 19:18:35 +0000 Subject: [PATCH 3/8] Please Codefactor. Signed-off-by: Adam Warner --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d805e927..d2295f96 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -422,7 +422,7 @@ make_repo() { pushd "${directory}" &> /dev/null || return 1 # Check current branch. If it is master, then reset to the latest availible tag. # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) - curBranch = $(git rev-parse --abbrev-ref HEAD) + curBranch=$(git rev-parse --abbrev-ref HEAD) if [[ "${curBranch}" == "master" ]]; then #If we're calling make_repo() then it should always be master, we may not need to check. git reset --hard $(git describe --abbrev=0) || return $? fi @@ -458,7 +458,7 @@ update_repo() { git pull --quiet &> /dev/null || return $? # Check current branch. If it is master, then reset to the latest availible tag. # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) - curBranch = $(git rev-parse --abbrev-ref HEAD) + curBranch=$(git rev-parse --abbrev-ref HEAD) if [[ "${curBranch}" == "master" ]]; then git reset --hard $(git describe --abbrev=0) || return $? fi From 73d9abae3e29ca1ce2c618c8707c4ca35255b06b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 8 Nov 2019 20:58:42 +0000 Subject: [PATCH 4/8] And finally, we please stickler Signed-off-by: Adam Warner --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d2295f96..535fec2d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -424,7 +424,7 @@ make_repo() { # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) curBranch=$(git rev-parse --abbrev-ref HEAD) if [[ "${curBranch}" == "master" ]]; then #If we're calling make_repo() then it should always be master, we may not need to check. - git reset --hard $(git describe --abbrev=0) || return $? + git reset --hard "$(git describe --abbrev=0)" || return $? fi # Show a colored message showing it's status printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" @@ -460,7 +460,7 @@ update_repo() { # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) curBranch=$(git rev-parse --abbrev-ref HEAD) if [[ "${curBranch}" == "master" ]]; then - git reset --hard $(git describe --abbrev=0) || return $? + git reset --hard "$(git describe --abbrev=0)" || return $? fi # Show a completion message printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" From a7e81c8ea0ac63d66dc05ea37bdaa6ee9b5cacb4 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 11 Nov 2019 20:12:31 +0000 Subject: [PATCH 5/8] remove extra space Signed-off-by: Adam Warner --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 535fec2d..f00f7689 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -378,9 +378,9 @@ fi is_repo() { # Use a named, local variable instead of the vague $1, which is the first argument passed to this function # These local variables should always be lowercase - local directory="${1}" + local directory="${1}" # A variable to store the return code - local rc + local rc # If the first argument passed to this function is a directory, if [[ -d "${directory}" ]]; then # move into the directory From 6571a63ffa6b297598d9b89ebdbccc99c2a40980 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 11 Nov 2019 20:36:51 +0000 Subject: [PATCH 6/8] Add --tags to descibe command Signed-off-by: Adam Warner --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f00f7689..f7358fb8 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -424,7 +424,7 @@ make_repo() { # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) curBranch=$(git rev-parse --abbrev-ref HEAD) if [[ "${curBranch}" == "master" ]]; then #If we're calling make_repo() then it should always be master, we may not need to check. - git reset --hard "$(git describe --abbrev=0)" || return $? + git reset --hard "$(git describe --abbrev=0 --tags)" || return $? fi # Show a colored message showing it's status printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" @@ -460,7 +460,7 @@ update_repo() { # In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks) curBranch=$(git rev-parse --abbrev-ref HEAD) if [[ "${curBranch}" == "master" ]]; then - git reset --hard "$(git describe --abbrev=0)" || return $? + git reset --hard "$(git describe --abbrev=0 --tags)" || return $? fi # Show a completion message printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" From 8e5abc1f154f6fa568a73d076f416b8f9f615ea3 Mon Sep 17 00:00:00 2001 From: Jason Cooke Date: Fri, 29 Nov 2019 13:46:05 +1300 Subject: [PATCH 7/8] docs: fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb2179eb..97459442 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ While quite outdated at this point, [this original blog post about Pi-hole](http ----- ## Coverage -- [Lifehacker: Turn A Raspberry Pi Into An Ad Blocker With A Single Command](https://www.lifehacker.com.au/2015/02/turn-a-raspberry-pi-into-an-ad-blocker-with-a-single-command/) (Feburary, 2015) +- [Lifehacker: Turn A Raspberry Pi Into An Ad Blocker With A Single Command](https://www.lifehacker.com.au/2015/02/turn-a-raspberry-pi-into-an-ad-blocker-with-a-single-command/) (February, 2015) - [MakeUseOf: Adblock Everywhere: The Raspberry Pi-Hole Way](http://www.makeuseof.com/tag/adblock-everywhere-raspberry-pi-hole-way/) (March, 2015) - [Catchpoint: Ad-Blocking on Apple iOS9: Valuing the End User Experience](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/) (September, 2015) - [Security Now Netcast: Pi-hole](https://www.youtube.com/watch?v=p7-osq_y8i8&t=100m26s) (October, 2015) From 8a119d72e2dba1551713807295485e8fa9d63bbd Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 9 Dec 2019 12:17:55 +0000 Subject: [PATCH 8/8] Ensure database permissions are set up correctly by the service script. Signed-off-by: DL6ER --- advanced/Templates/pihole-FTL.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 5dbf080e..43f9e184 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -48,6 +48,8 @@ start() { chown pihole:pihole /etc/pihole /etc/pihole/dhcp.leases 2> /dev/null chown pihole:pihole /var/log/pihole-FTL.log /var/log/pihole.log chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port /var/log/pihole.log + # Chown database files to the user FTL runs as. We ignore errors as the files may not (yet) exist + chown pihole:pihole /etc/pihole/pihole-FTL.db /etc/pihole/gravity.db 2> /dev/null echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.piholeFTL if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN+eip "$(which pihole-FTL)"; then su -s /bin/sh -c "/usr/bin/pihole-FTL" "$FTLUSER"