diff --git a/otherworld b/otherworld index db4f028..db84766 100755 --- a/otherworld +++ b/otherworld @@ -217,6 +217,11 @@ def load_config_files (namespace, config_files): exec(config_code.read(), {}, namespace) return dict([item for item in namespace.items() if item[0] in config_keys]) +def init_command_as_list (command): + if isinstance(command, str): + command = ["sh", "-c", command] + return command + # parse options and command from command line (command_line_options, command) = parse_command_line(sys.argv[1:]) actions = command_line_options['actions'] @@ -246,6 +251,7 @@ config = { "cwd": os.getcwd(), "tty": sys.stdout.isatty(), "log": log, + "root_init_command": [], "user_init_command": [], "docker_create_options": [] } @@ -338,11 +344,11 @@ except Exception: log("Creating container user: {}", user) docker_create_user(container_name, user, uid) + if config['root_init_command']: + docker_exec(container_name, init_command_as_list(config['root_init_command']), "root", command_env, tty, "/home/{}".format(command_user)) + if config['user_init_command']: - user_init_command = config['user_init_command'] - if isinstance(user_init_command, str): - user_init_command = ["sh", "-c", user_init_command] - docker_exec(container_name, user_init_command, command_user, command_env, tty, "/home/{}".format(command_user)) + docker_exec(container_name, init_command_as_list(config['user_init_command']), command_user, command_env, tty, "/home/{}".format(command_user)) log("Welcome to {} (IP {})", container_name, container['NetworkSettings']['IPAddress']) docker_exec(container_name, command, command_user, command_env, tty, command_workdir)