From b18458449ce8de14bb8c06942168780fcef2ed0d Mon Sep 17 00:00:00 2001 From: Craig Comstock Date: Mon, 1 Nov 2021 12:01:53 -0500 Subject: [PATCH] Modified cfbs install behavior for easier use If an argument is provided, install will use that path If no argument and root is the user, default path of /var/cfengine/masterfiles is used If no argument and NOT root user, $HOME/.cfagent/inputs is used Ticket: CFE-3821 --- cfbs/commands.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cfbs/commands.py b/cfbs/commands.py index a23c0bfb..123fd973 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -938,16 +938,29 @@ def build_command() -> int: build_steps() -def install_command(destination=None) -> int: +def install_command(args) -> int: + if len(args) > 1: + user_error( + "Only one destination is allowed for command: cfbs install [destination]" + ) if not os.path.exists("out/masterfiles"): r = build_command() if r != 0: return r - if not destination: + if os.getuid() == 0: destination = "/var/cfengine/masterfiles" + if len(args) > 0: + destination = args[0] + elif os.getuid() == 0: + destination = "/var/cfengine/masterfiles" + else: + destination = os.path.join(os.environ["HOME"], ".cfagent/inputs") + if not destination.startswith("/") and not destination.startswith("./"): + destination = "./" + destination rm(destination, missing_ok=True) cp("out/masterfiles", destination) + print("Installed to %s" % destination) return 0