From ffbe0446ccd75a5a4f3ce57eced490a93c50ce8a Mon Sep 17 00:00:00 2001 From: darkdragon-001 Date: Mon, 21 Nov 2022 18:55:39 +0100 Subject: [PATCH] Allow empty cmd in usersetup.py Using the same approach as in https://github.com/crops/poky-container/blob/master/poky-entry.py to allow running usersetup.py without `cmd`. --- usersetup.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/usersetup.py b/usersetup.py index 0261a28..758c520 100755 --- a/usersetup.py +++ b/usersetup.py @@ -56,10 +56,7 @@ def sanity_check_workdir(workdir): parser.add_argument("--workdir", default="/workdir", help="Directory to base the uid on") -parser.add_argument("cmd", help="command to exec after setting up the user") - -# All positional arguments are passed to args.cmd when it is ran -parser.add_argument("args", default="", nargs=argparse.REMAINDER) +parser.add_argument("cmd", nargs=argparse.REMAINDER, help="command to exec after setting up the user") args = parser.parse_args() @@ -94,5 +91,7 @@ def sanity_check_workdir(workdir): usercmd = [ args.cmd ] + args.args cmd = "sudo -E -H -u {} ".format(args.username) -cmd = cmd.split() + usercmd +cmd = cmd.split() +if args.cmd: + cmd.extend(args.cmd) os.execvp(cmd[0], cmd)