From e2af746b5a3f85a08fd8e035ca0225c0ffc32b7c Mon Sep 17 00:00:00 2001
From: Adrian Schmitz <a.schmitz@itc.rwth-aachen.de>
Date: Tue, 30 Jan 2024 12:50:06 +0100
Subject: [PATCH] HOTFIX: Use the installed runner for registration

Signed-off-by: Adrian Schmitz <a.schmitz@itc.rwth-aachen.de>
---
 Installer.py | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/Installer.py b/Installer.py
index ede1dda..c410847 100755
--- a/Installer.py
+++ b/Installer.py
@@ -100,13 +100,6 @@ def CLI():
             "default": "utility/runtime",
             "help": "Path where utility files are located. Downscoped users need read access."
         },
-        {
-            "flags": ["-rip", "--runner-install-path"],
-            "type": str,
-            "metavar": "<name>",
-            "default": "utility/runtime/bin",
-            "help": "The path where the runner is installed."
-        },
         {
             "flags": ["-up", "--user-path"],
             "type": str,
@@ -159,6 +152,13 @@ def CLI():
             "default": "./install",
             "help": "The path where the runner is installed."
         },
+        {
+            "flags": ["-rip", "--runner-install-path"],
+            "type": str,
+            "metavar": "<name>",
+            "default": "utility/runtime/bin",
+            "help": "The path where the runner is installed."
+        },
     ]
     }
 
@@ -261,18 +261,24 @@ def install():
         set_utility_permissions(_runner_install_path, ['gitlab-runner'])
         set_utility_permissions(args.rt_utility_path)
 
-
-def add_registration(runner_path=''):
+def runner_registration(runner_path=''):
     # Register Gitlab Runner
     if runner_path: runner_path += '/'
     os.system(
         f'{runner_path}gitlab-runner register --non-interactive --url "{args.registration_url}" --registration-token "{args.registration_token}"\
-                --executor "custom" --description "{args.runner_name}" --tag-list "{args.tag_list}" --run-untagged="false" --locked="false" \
-                --access-level="not_protected"\
-                --custom-prepare-exec="{args.install_path}/main.sh" --custom-config-exec="{args.install_path}/main.sh"\
-                --custom-run-exec="{args.install_path}/main.sh" --custom-cleanup-exec="{args.install_path}/main.sh"\
-                --custom-prepare-args="prepare" --custom-config-args="config"\
-                --custom-run-args="run" --custom-cleanup-args="cleanup"')
+                    --executor "custom" --description "{args.runner_name}" --tag-list "{args.tag_list}" --run-untagged="false" --locked="false" \
+                    --access-level="not_protected"\
+                    --custom-prepare-exec="{args.install_path}/main.sh" --custom-config-exec="{args.install_path}/main.sh"\
+                    --custom-run-exec="{args.install_path}/main.sh" --custom-cleanup-exec="{args.install_path}/main.sh"\
+                    --custom-prepare-args="prepare" --custom-config-args="config"\
+                    --custom-run-args="run" --custom-cleanup-args="cleanup"')
+def add_registration(runner_path=''):
+    from shutil import which
+    if which("gitlab-runner") is None:
+        runner_registration(args.runner_install_path)
+    else:
+        runner_registration(runner_path)
+
     os.system(f"sed -i 's/concurrent = 1/concurrent = {args.concurrency}/g' $HOME/.gitlab-runner/config.toml")
 
 
-- 
GitLab