From 924577a6f2436641d22a5d9e0ce3a74aadabada6 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Sun, 13 May 2018 09:53:00 +0100
Subject: [PATCH] Prevent usb canary from being activated during upgrades

---
 src/freedombone-upgrade    | 11 +++++++++++
 src/freedombone-usb-canary | 18 ++++++++++--------
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/freedombone-upgrade b/src/freedombone-upgrade
index 33f73ab48..94c408ca5 100755
--- a/src/freedombone-upgrade
+++ b/src/freedombone-upgrade
@@ -61,6 +61,11 @@ if [ $DEVELOPMENT_BRANCH ]; then
     fi
 fi
 
+# upgrading file prevents USB canary from activating
+if [ ! -f /tmp/.upgrading ]; then
+    touch /tmp/.upgrading
+fi
+
 if [ -f /usr/bin/backupdatabases ]; then
     if grep -q "cat /root/dbpass" /usr/bin/backupdatabases; then
         # update to using the password manager
@@ -91,6 +96,7 @@ if [ -d "$PROJECT_DIR" ]; then
         fi
 
         if ! ${PROJECT_NAME} -c "$CONFIGURATION_FILE"; then
+            rm /tmp/.upgrading
             exit 453536
         fi
 
@@ -118,4 +124,9 @@ fi
 # If logging was left on then turn it off
 ${PROJECT_NAME}-logging off
 
+# upgrading file prevents USB canary from activating
+if [ -f /tmp/.upgrading ]; then
+    rm /tmp/.upgrading
+fi
+
 # deliberately there is no 'exit 0' here
diff --git a/src/freedombone-usb-canary b/src/freedombone-usb-canary
index 6fd7f382c..a165fd405 100755
--- a/src/freedombone-usb-canary
+++ b/src/freedombone-usb-canary
@@ -28,12 +28,14 @@
 
 PROJECT_NAME=freedombone
 
-UPTIME=$(awk -F '.' '{print $1}' < "/proc/uptime")
-if [ "$UPTIME" -gt 240 ]; then
-    ADMIN_USER=$(grep 'Admin user' /root/${PROJECT_NAME}-completed.txt | awk -F ':' '{print $2}')
-    MY_EMAIL_ADDRESS=${ADMIN_USER}@$(cat /etc/hostname)
-    echo "USB device connected on ${DEVPATH}" | mail -s "${PROJECT_NAME} USB canary" "${MY_EMAIL_ADDRESS}"
-    echo "${ACTION}" > /tmp/usb-canary
-    echo "${MY_EMAIL_ADDRESS}" >> /tmp/usb-canary
-    date >> /tmp/usb-canary
+if [ ! -f /tmp/.upgrading ]; then
+    UPTIME=$(awk -F '.' '{print $1}' < "/proc/uptime")
+    if [ "$UPTIME" -gt 240 ]; then
+        ADMIN_USER=$(grep 'Admin user' /root/${PROJECT_NAME}-completed.txt | awk -F ':' '{print $2}')
+        MY_EMAIL_ADDRESS=${ADMIN_USER}@$(cat /etc/hostname)
+        echo "USB device connected on ${DEVPATH}" | mail -s "${PROJECT_NAME} USB canary" "${MY_EMAIL_ADDRESS}"
+        echo "${ACTION}" > /tmp/usb-canary
+        echo "${MY_EMAIL_ADDRESS}" >> /tmp/usb-canary
+        date >> /tmp/usb-canary
+    fi
 fi
-- 
GitLab