From 084fdc10f7e861ce6e83120dc099d2416904af55 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Sat, 24 Oct 2020 01:54:03 +0200 Subject: #988 Fix setserveraddr json handling setserveraddr script modified ogserver.json values with "sed". This caused unwanted changes in database.ip. This commit replaces "sed" with "jq" for modifying ogserver.json, ensuring only rest.ip and wol.interface values change. --- server/bin/setserveraddr | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'server/bin/setserveraddr') diff --git a/server/bin/setserveraddr b/server/bin/setserveraddr index b9249af7..6694e3c4 100755 --- a/server/bin/setserveraddr +++ b/server/bin/setserveraddr @@ -88,13 +88,11 @@ if [ -n "$SERVERIP" ]; then OLDSERVERIP=$ServidorAdm # Checking if configuration files need to be modified. CHANGE=0 - for f in $OPENGNSYS/{etc/ogserver.json,etc/ogAdmRepo.cfg,www/controlacceso.php}; do + for f in $OPENGNSYS/{etc/ogAdmRepo.cfg,www/controlacceso.php}; do # Updating configuration variables (if URL does not contain "localhost"). sed -e "s,\(ServidorAdm\|IPlocal\)=.*,\1=$SERVERIP," \ -e "s,^INTERFACE=.*,INTERFACE=$SERVERDEV," \ -e "s,UrlMenu=https?://\([^/]*\)/\(.*\),UrlMenu=https://$SERVERIP/\2," \ - -e "s/\"ip\": \".*\"/\"ip\": \"$SERVERIP\"/" $SERVERCFG \ - -e "s/\"interface\": \".*\"/\"interface\": \"$SERVERDEV\"/" $SERVERCFG \ -e '/localhost/!s,https\?://[^/]*/\(.*\),https://'$SERVERIP'/\1,' $f >$tmpfile file="${f/./-$SERVERDEV.}" # Copying updated file, if needed. @@ -105,6 +103,18 @@ if [ -n "$SERVERIP" ]; then fi done + f="$OPENGNSYS"/etc/ogserver.json + file="${f/./-$SERVERDEV.}" + step_one=$(mktemp) + jq --arg ip "$SERVERIP" '.rest.ip = $ip' "$file" > "$step_one" + step_two=$(mktemp) + jq --arg iface "$SERVERDEV" '.wol.interface = $iface' "$step_one" > "$step_two" + if [ ! "$f" -ef "$file" ] || ! diff -q "$step_two" "$file" &>/dev/null; then + cp "$step_two" "$file" + ln -f "$file" "$f" + CHANGE=1 + fi + # Processing when something has changed. if [ $CHANGE == 1 ]; then # Config ogClient. -- cgit v1.2.3-18-g5258