From 59fc3804be28b3b26f3c6b333a36e04701be18d9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 16 Mar 2022 20:30:31 +0000 Subject: [PATCH] Make utils.sh posix compatible per request Signed-off-by: Adam Warner --- advanced/Scripts/utils.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index a006d43a..86a7e0b4 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Pi-hole: A black hole for Internet advertisements # (c) 2017 Pi-hole, LLC (https://pi-hole.net) # Network-wide ad blocking via your own hardware. @@ -39,7 +39,7 @@ addOrEditKeyValPair() { file="${3}" fi - if [[ "${value}" != "" ]]; then + if [ "${value}" != "" ]; then # value has a value, so it is a key pair if grep -q "^${key}=" "${file}"; then # Key already exists in file, modify the value @@ -74,23 +74,23 @@ removeKey() { # returns FTL's current telnet API port ####################### getFTLAPIPort(){ - local -r FTLCONFFILE="/etc/pihole/pihole-FTL.conf" - local -r DEFAULT_PORT_FILE="/run/pihole-FTL.port" - local -r DEFAULT_FTL_PORT=4711 + local FTLCONFFILE="/etc/pihole/pihole-FTL.conf" + local DEFAULT_PORT_FILE="/run/pihole-FTL.port" + local DEFAULT_FTL_PORT=4711 local PORTFILE local ftl_api_port - if [[ -f "$FTLCONFFILE" ]]; then + if [ -f "$FTLCONFFILE" ]; then # if PORTFILE is not set in pihole-FTL.conf, use the default path PORTFILE="$( (grep "^PORTFILE=" $FTLCONFFILE || echo "$DEFAULT_PORT_FILE") | cut -d"=" -f2-)" fi - if [[ -s "$PORTFILE" ]]; then + if [ -s "$PORTFILE" ]; then # -s: FILE exists and has a size greater than zero - ftl_api_port=$(<"$PORTFILE") + ftl_api_port=$(cat "${PORTFILE}") # Exploit prevention: unset the variable if there is malicious content - # Verify that the value read from the file is numeric - [[ "$ftl_api_port" =~ [^[:digit:]] ]] && unset ftl_api_port + # Verify that the value read from the file is numeric + expr "$ftl_api_port" : "[^[:digit:]]" > /dev/null && unset ftl_api_port fi # echo the port found in the portfile or default to the default port