Move ensure_newline() into its own file as we need to source it from different places
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
22
advanced/Scripts/utils.sh
Normal file
22
advanced/Scripts/utils.sh
Normal file
@@ -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
|
||||||
|
}
|
@@ -26,6 +26,9 @@ readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
|||||||
PH_TEST="true"
|
PH_TEST="true"
|
||||||
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
|
||||||
|
|
||||||
|
# ensure_newline()
|
||||||
|
source "utils.sh"
|
||||||
|
|
||||||
coltable="/opt/pihole/COL_TABLE"
|
coltable="/opt/pihole/COL_TABLE"
|
||||||
if [[ -f ${coltable} ]]; then
|
if [[ -f ${coltable} ]]; then
|
||||||
source ${coltable}
|
source ${coltable}
|
||||||
|
13
pihole
13
pihole
@@ -20,17 +20,8 @@ PI_HOLE_BIN_DIR="/usr/local/bin"
|
|||||||
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||||
source "${colfile}"
|
source "${colfile}"
|
||||||
|
|
||||||
# Ensure there is a newline at the end of the file passed as argument
|
# ensure_newline()
|
||||||
ensure_newline() {
|
source "utils.sh"
|
||||||
# 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
|
|
||||||
}
|
|
||||||
|
|
||||||
webpageFunc() {
|
webpageFunc() {
|
||||||
source "${PI_HOLE_SCRIPT_DIR}/webpage.sh"
|
source "${PI_HOLE_SCRIPT_DIR}/webpage.sh"
|
||||||
|
Reference in New Issue
Block a user