diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh new file mode 100644 index 00000000..5c219919 --- /dev/null +++ b/advanced/Scripts/utils.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# Pi-hole: A black hole for Internet advertisements +# (c) 2020 Pi-hole, LLC (https://pi-hole.net) +# Network-wide ad blocking via your own hardware. +# +# Controller for all pihole scripts and functions. +# +# This file is copyright under the latest version of the EUPL. +# Please see LICENSE file for your rights under this license. + +# Ensure there is a newline at the end of the file passed as argument +ensure_newline() { + # Check if the last line of the passed file is empty, if not, append a newline + # to the file to ensure we can append new content safely using echo "" >> + # later on + [ -n "$(tail -c1 "${1}")" ] && printf '\n' >> "${1}" + # There was also the suggestion of using a sed-magic call here, however, this + # had the drawback to updating all the file timestamps whenever the sed was + # run. This solution only updates the timestamp when actually appending a + # newline +} \ No newline at end of file diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7870355e..93128e26 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -26,6 +26,9 @@ readonly PI_HOLE_FILES_DIR="/etc/.pihole" PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" +# ensure_newline() +source "utils.sh" + coltable="/opt/pihole/COL_TABLE" if [[ -f ${coltable} ]]; then source ${coltable} diff --git a/pihole b/pihole index 48e29e93..644758bc 100755 --- a/pihole +++ b/pihole @@ -20,17 +20,8 @@ PI_HOLE_BIN_DIR="/usr/local/bin" readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE" source "${colfile}" -# Ensure there is a newline at the end of the file passed as argument -ensure_newline() { - # Check if the last line of the passed file is empty, if not, append a newline - # to the file to ensure we can append new content safely using echo "" >> - # later on - [ -n "$(tail -c1 "${1}")" ] && printf '\n' >> "${1}" - # There was also the suggestion of using a sed-magic call here, however, this - # had the drawback to updating all the file timestamps whenever the sed was - # run. This solution only updates the timestamp when actually appending a - # newline -} +# ensure_newline() +source "utils.sh" webpageFunc() { source "${PI_HOLE_SCRIPT_DIR}/webpage.sh"