From 5fcb1dc43970246cec4748ee491f89548f9f8f3b Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Tue, 11 Mar 2025 16:23:32 +0100
Subject: [PATCH] Add online tests.

---
 testing/scripts/_misc.sh              | 15 +++++++++++----
 testing/scripts/setup_desktop.sh      |  1 +
 testing/scripts/setup_secrets_root.sh |  1 +
 testing/scripts/setup_secrets_user.sh |  4 +---
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/testing/scripts/_misc.sh b/testing/scripts/_misc.sh
index 7520e9d..760dda7 100644
--- a/testing/scripts/_misc.sh
+++ b/testing/scripts/_misc.sh
@@ -39,8 +39,15 @@ abort_if_exists() {
 }
 
 abort_if_not_user() {
-if [ `whoami` != "$1" ]; then
-    echo "Must be run as $1."
-    exit 1
-fi
+    if [ `whoami` != "$1" ]; then
+        echo "Must be run as $1."
+        exit 1
+    fi
+}
+
+abort_if_offline() {
+    if ! ping -c1 -W2 1.1.1.1 > /dev/null 2>&1; then
+        echo "Must be run online."
+        exit 1
+    fi
 }
diff --git a/testing/scripts/setup_desktop.sh b/testing/scripts/setup_desktop.sh
index d5b5b14..f954302 100755
--- a/testing/scripts/setup_desktop.sh
+++ b/testing/scripts/setup_desktop.sh
@@ -4,6 +4,7 @@ set -x
 . ./_misc.sh
 
 expect_min_n_args 1 "(system name)" "$@"
+abort_if_offline
 get_system_name_arg "$1"
 MIN_MODULES="all ${system_class_name} ${system_name}"
 
diff --git a/testing/scripts/setup_secrets_root.sh b/testing/scripts/setup_secrets_root.sh
index 413eb0e..2a8f8f2 100755
--- a/testing/scripts/setup_secrets_root.sh
+++ b/testing/scripts/setup_secrets_root.sh
@@ -3,6 +3,7 @@ set -e
 . ./_misc.sh
 
 abort_if_not_user root
+abort_if_offline
 
 # Mount secrets device and copy over its content.
 abort_if_exists "${PATH_SECRETS}"
diff --git a/testing/scripts/setup_secrets_user.sh b/testing/scripts/setup_secrets_user.sh
index cf09477..40ee16e 100755
--- a/testing/scripts/setup_secrets_user.sh
+++ b/testing/scripts/setup_secrets_user.sh
@@ -2,9 +2,6 @@
 set -e
 . ./_misc.sh
 
-# to remind user to go online if not yet done
-# TODO: replace by actual test
-nmtui
 
 BORG_PASSPHRASE="$1"
 PATH_REPOS="${HOME}/repos"
@@ -14,6 +11,7 @@ REMOTE_PATH_REPOS=/var/repos
 NAME_BORGAPP=borgplom
 
 abort_if_not_user "${USERNAME}"
+abort_if_offline
 abort_if_exists "${PATH_USER_SSH}"
 abort_if_exists "${PATH_REPOS}"
 abort_if_exists "${PATH_BORGKEYS}"
-- 
2.30.2