From 7827d25263da5ca7f2f1150131ed9327827df861 Mon Sep 17 00:00:00 2001
From: toklinke <43620409+toklinke@users.noreply.github.com>
Date: Mon, 27 Jun 2022 20:00:37 +0200
Subject: [PATCH 1/5] update.sh: produce correct exit code for update check

The result of the shell script was always 0.
So the web frontend did not enable the update button.
Now the button is activated whenever an update is available.
---
 update.sh | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/update.sh b/update.sh
index a02a040..7c0cecb 100755
--- a/update.sh
+++ b/update.sh
@@ -70,19 +70,26 @@ if [ $do_check ]; then
 
         if [ "${result}" -eq 0 ]; then
             echo "There is no new version!"
+            exit 0
         elif  [ "${result}" -eq 1 ]; then
-             echo "Your version is newer than the available version!"
+            echo "Your version is newer than the available version!"
+            exit 0
         elif  [ "${result}" -eq 2 ]; then
             echo "There is a new stable version!"
+            exit 1
         elif  [ "${result}" -eq 3 ]; then
             echo "You have an unstable version, but hey it's the newest one"
+            exit 0
         elif  [ "${result}" -eq 4 ]; then
             echo "Your unstable version is newer than the available version!"
+            exit 0
         elif  [ "${result}" -eq 5 ]; then
             echo "There is a new unstable (alpha/beta/rc) version! It is highly experimental and discouraged to be installed!"
+            exit 1
         fi
     else
         echo "Could not read the version from github."
+        exit 0
     fi
 fi
 

From deed55ac11e21eb226147ce762cfe84da8fcb6d8 Mon Sep 17 00:00:00 2001
From: toklinke <43620409+toklinke@users.noreply.github.com>
Date: Mon, 27 Jun 2022 20:01:54 +0200
Subject: [PATCH 2/5] update.sh: replace absolute path by relative path for
 easier testing

This makes it easier to test the script
---
 update.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/update.sh b/update.sh
index 7c0cecb..d8460c8 100755
--- a/update.sh
+++ b/update.sh
@@ -66,7 +66,7 @@ if [ $do_check ]; then
         echo "Your version is: $currentVersion"
         echo "The latest version is: $latestVersion"
 
-        result=$(/bin/bash /opt/hucon/version_compare.sh "${currentVersion}" "${latestVersion}")
+        result=$(/bin/bash ${SCRIPT_DIR}/version_compare.sh "${currentVersion}" "${latestVersion}")
 
         if [ "${result}" -eq 0 ]; then
             echo "There is no new version!"

From e106e07aa1eab480aef075df471e9e4d97c69e48 Mon Sep 17 00:00:00 2001
From: toklinke <43620409+toklinke@users.noreply.github.com>
Date: Mon, 27 Jun 2022 20:03:04 +0200
Subject: [PATCH 3/5] update.sh: download hucon.run to fixed destination path

Previously it ended up at a path based on the current working directory.
When started from the webserver that was `/opt/hucon/webserver/hucon.run`
which got removed by the deploy logic.
So update via web frontend always failed.
Now it is downloaded to `/opt/hucon.run` which is preserved by deploy logic.
---
 update.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/update.sh b/update.sh
index d8460c8..01a3749 100755
--- a/update.sh
+++ b/update.sh
@@ -99,15 +99,15 @@ if [ $do_update ]; then
         echo "Update the system from $currentVersion to $latestVersion"
 
         # remove the old package if needed.
-        if [ -f hucon.run ]; then
-            rm hucon.run
+        if [ -f ${SCRIPT_DIR}/hucon.run ]; then
+            rm ${SCRIPT_DIR}/hucon.run
         fi
 
         # download the new package
         downloadUrl="https://github.com/$UPDATE_SOURCE_REPO/releases/download/$latestVersion/hucon-$latestVersion.run"
 
         # Download the new package
-        wget $downloadUrl -O hucon.run
+        wget $downloadUrl -O ${SCRIPT_DIR}/hucon.run
 
         echo "Check if existing code can be moved to /root/hucon/code..."
         if [[ ! -e /root/hucon/code ]]; then
@@ -121,7 +121,7 @@ if [ $do_update ]; then
         fi
 
         # and install it.
-        sh hucon.run
+        sh ${SCRIPT_DIR}/hucon.run
     else
         echo "You are using the up to date version."
     fi

From c6f5a7826189fb291f1dcd3fc43fdcf8ce1a7eee Mon Sep 17 00:00:00 2001
From: toklinke <43620409+toklinke@users.noreply.github.com>
Date: Mon, 27 Jun 2022 20:05:52 +0200
Subject: [PATCH 4/5] start_server.sh: always start webserver with logging

---
 start_server.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/start_server.sh b/start_server.sh
index 12b60a4..76a66e7 100755
--- a/start_server.sh
+++ b/start_server.sh
@@ -33,11 +33,10 @@ cd $SCRIPT_DIR/webserver
 if [ $DEBUG != 0 ];
 then
     echo "Starting server"
-    $INTERPRETER $PYTHON_PARAMETERS $EXECUTABLE $SCRIPT_PARAMETERS >/var/log/hucon.log 2>/var/log/hucon_err.log &
-else
-    $INTERPRETER $PYTHON_PARAMETERS $EXECUTABLE $SCRIPT_PARAMETERS &
 fi
 
+$INTERPRETER $PYTHON_PARAMETERS $EXECUTABLE $SCRIPT_PARAMETERS >/var/log/hucon.log 2>/var/log/hucon_err.log &
+
 HUCON_PID=$!
 
 echo $HUCON_PID > /var/run/hucon.pid

From ee28c727dfe99f8aeb59e59cffb100c006802cb9 Mon Sep 17 00:00:00 2001
From: toklinke <43620409+toklinke@users.noreply.github.com>
Date: Mon, 27 Jun 2022 20:06:14 +0200
Subject: [PATCH 5/5] start_server.sh: do not run webserver in DEBUG mode by
 default

Debug mode makes update via web frontend impossible
because the debug server detects changed in the python source files.
When they are removed during update
the server (and thus the update process) crashes.
So we need to disable it by default.
---
 start_server.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/start_server.sh b/start_server.sh
index 76a66e7..f3b484c 100755
--- a/start_server.sh
+++ b/start_server.sh
@@ -14,7 +14,7 @@ PYTHON_PARAMETERS="-X utf8"
 SCRIPT_PARAMETERS=""
 INTERPRETER=python3
 
-DEBUG=1
+DEBUG=0
 
 if [ $DEBUG != 0 ];
 then