From a39e2342c6756d015a1c9f2150306ff309b258e4 Mon Sep 17 00:00:00 2001
From: Felix Tomski <tomski@itc.rwth-aachen.de>
Date: Tue, 7 Nov 2023 10:49:27 +0100
Subject: [PATCH] Fix installer with downscope disabled

---
 Installer.py | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/Installer.py b/Installer.py
index 652af03..930aae3 100755
--- a/Installer.py
+++ b/Installer.py
@@ -186,7 +186,7 @@ def CLI():
 
     parser = argparse.ArgumentParser(prog='Aixcellenz CI Driver Installer')
     add_parameters(parser, parameters['global'])
-    subparsers = parser.add_subparsers(help='sub-command help')
+    subparsers = parser.add_subparsers(dest='cmd_name', help='sub-command help')
 
     for cmd in subcommands:
         subcmd_parser = subparsers.add_parser(cmd, help=f'{cmd} help', aliases=subcommands[cmd]['aliases'])
@@ -200,13 +200,17 @@ def CLI():
     args_to_expand = ['runner_install_path', 'shell_installation', 'mapping_path',
                       'public_key_path', 'key_path', 'log_path', 'rt_utility_path']
     for arg in args_to_expand:
-        vars(ret)[arg] = os.path.expandvars(os.path.expanduser(vars(ret)[arg]))
-        if not os.path.isabs(vars(ret)[arg]):
-            vars(ret)[arg] = os.path.join(ret.install_path, vars(ret)[arg])
-
-    ret.shell_file = os.path.expandvars(os.path.expanduser(ret.shell_file))
-    if not os.path.isabs(ret.shell_file):
-        ret.shell_file = os.path.join(ret.rt_utility_path, ret.shell_file)
+        try:
+            vars(ret)[arg] = os.path.expandvars(os.path.expanduser(vars(ret)[arg]))
+            if not os.path.isabs(vars(ret)[arg]):
+                vars(ret)[arg] = os.path.join(ret.install_path, vars(ret)[arg])
+        except KeyError as _:
+            pass
+
+    if ret.cmd_name == 'install':
+        ret.shell_file = os.path.expandvars(os.path.expanduser(ret.shell_file))
+        if not os.path.isabs(ret.shell_file):
+            ret.shell_file = os.path.join(ret.rt_utility_path, ret.shell_file)
 
     return ret
 
@@ -275,8 +279,9 @@ def install():
     with open(args.shell_file, "a") as shell_fp:
         shell_fp.writelines(f"export PATH=$PATH:{_runner_install_path}\n")
 
-    set_utility_permissions(_runner_install_path, ['gitlab-runner'])
-    set_utility_permissions(args.rt_utility_path)
+    if args.downscope:
+        set_utility_permissions(_runner_install_path, ['gitlab-runner'])
+        set_utility_permissions(args.rt_utility_path)
 
 
 def add_registration(runner_path=''):
-- 
GitLab