From 4c15e16a3adcb541c8315c2a3a78722c08a843e8 Mon Sep 17 00:00:00 2001 From: Andrew Hurley Date: Sun, 28 Jun 2026 17:59:09 +0800 Subject: [PATCH] minimal --- lxcd.completion | 4 ++-- lxcd.py | 34 ++++++++-------------------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/lxcd.completion b/lxcd.completion index d1a7c29..7c54884 100644 --- a/lxcd.completion +++ b/lxcd.completion @@ -26,7 +26,7 @@ _lxcd_completion() { case "${subcommand}" in create) if [[ "$cur" == -* ]]; then - COMPREPLY=($(compgen -W "--nested --sshd --git --certs --aptcache --ssh-client -i --image" -- "$cur")) + COMPREPLY=($(compgen -W "--nested --git --certs --aptcache --ssh-client -i --image -m --minimal" -- "$cur")) else COMPREPLY=($(compgen -W "ubuntu: ubuntu/24.04 ubuntu/22.04 debian/12 debian/11" -- "$cur")) fi @@ -52,7 +52,7 @@ _lxcd_completion() { if [ $cword -eq 2 ]; then COMPREPLY=($(compgen -W "${containers}" -- "$cur")) elif [[ "$cur" == -* ]]; then - COMPREPLY=($(compgen -W "--nested --sshd --git --certs --aptcache --ssh-client" -- "$cur")) + COMPREPLY=($(compgen -W "--nested --git --certs --aptcache --ssh-client" -- "$cur")) fi ;; diff --git a/lxcd.py b/lxcd.py index 59837e0..8de9d46 100755 --- a/lxcd.py +++ b/lxcd.py @@ -129,7 +129,7 @@ def handle_list(args): active_opts.append("nesting") # Check labels for other features - for feature in ("certs", "git", "sshd", "aptcache", "ssh-client"): + for feature in ("certs", "git", "aptcache", "ssh-client"): if get_config(f"user.lxcd.{feature}") == "true": active_opts.append(feature) @@ -158,6 +158,8 @@ def handle_clone(args): def handle_create(args): host_username, uid, gid, host_home = get_real_user_info() + if args.minimal: + args.image = "ubuntu-minimal:" host_timezone = detect_timezone() host_locale = detect_locale() @@ -173,12 +175,6 @@ def handle_create(args): print(f"Creating LXD container '{args.name}' from image '{args.image}'...") - # Determine SSH action based on --sshd flag - ssh_action = "systemctl disable --now ssh.service ssh.socket" - if args.sshd: - ssh_action = "systemctl enable --now ssh.service ssh.socket" - print("Security profiles adjusted: SSH daemon and socket explicitly requested.") - # Cloud-init configuration apt_proxy_cmd = ( f" - mkdir -p /etc/apt/apt.conf.d\n" @@ -215,7 +211,7 @@ runcmd: - cp -rpn /etc/skel/. /home/{host_username}/ - mkdir -p {container_coder_path} {ssh_client_cmd} - chown -R {host_username}:{host_username} /home/{host_username} - - {ssh_action} + - echo "SSH left at default image state" {apt_proxy_cmd}""" # Initialize container @@ -257,10 +253,6 @@ runcmd: lxc_run([ "config", "set", args.name, "security.syscalls.intercept.mknod", "true"]) set_label(args.name, "nested") - # Handle --sshd label (already handled in cloud-init config above) - if args.sshd: - set_label(args.name, "sshd") - # Handle --aptcache option if args.aptcache: print(f"APT cache/proxy will be configured to {args.aptcache} via cloud-init...") @@ -396,7 +388,7 @@ def handle_add(args): print(f"Error: Container '{args.name}' does not exist.", file=sys.stderr) sys.exit(1) - if not args.nested and not args.sshd and not args.git and not args.certs and not args.aptcache and not args.ssh_client: + if not args.nested and not args.git and not args.certs and not args.aptcache and not args.ssh_client: print("Error: Specify at least one option to add.\n" "Example: lxcd add --git --nested", file=sys.stderr) sys.exit(1) @@ -417,17 +409,8 @@ def handle_add(args): lxc_run([ "config", "set", args.name, "security.syscalls.intercept.mknod", "true"]) set_label(args.name, "nested") - if args.sshd: - print(f"Activating SSH daemon and socket inside '{args.name}'...") - lxc_run([ "exec", args.name, "--", "systemctl", "enable", "--now", "ssh.service", "ssh.socket"]) - set_label(args.name, "sshd") - if args.git: was_running = not was_stopped - print(f"Installing git inside '{args.name}'...") - lxc_run([ "exec", args.name, "--", "env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "update", "-y"]) - lxc_run([ "exec", args.name, "--", "env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "install", "-y", "git"]) - host_gitconfig = host_home / ".gitconfig" if host_gitconfig.exists(): print(f"Mapping host .gitconfig into '{args.name}' as a device mount...") @@ -443,7 +426,7 @@ def handle_add(args): lxc_run([ "start", args.name]) lxc_run([ "exec", args.name, "--", "cloud-init", "status", "--wait"], check=False) else: - print(f"Warning: Host ~/.gitconfig not found. Git was installed, but file copy skipped.") + print(f"Warning: Host ~/.gitconfig not found. Skipping git config mapping.") if args.certs: host_certs = Path("/etc/ssl/certs/ca-certificates.crt") @@ -515,8 +498,8 @@ def main(): parser_create = subparsers.add_parser("create", help="Create a new LXD container") parser_create.add_argument("name", help="Name of the container") parser_create.add_argument("-i", "--image", default="ubuntu:", help="LXD image to use (defaults to 'ubuntu:')") + parser_create.add_argument("-m", "--minimal", action="store_true", help="Use ubuntu-minimal: image instead") parser_create.add_argument("--nested", action="store_true", help="Enable nesting") - parser_create.add_argument("--sshd", action="store_true", help="Enable SSH daemon") parser_create.add_argument("--git", action="store_true", help="Map host ~/.gitconfig into the container") parser_create.add_argument("--certs", action="store_true", help="Mount host CA certificates bundle") parser_create.add_argument("--aptcache", help="URL for an APT cache/proxy (e.g. http://10.0.0.1:3142)") @@ -560,8 +543,7 @@ def main(): parser_add = subparsers.add_parser("add", help="Add features to an existing container") parser_add.add_argument("name", help="Name of the container") parser_add.add_argument("--nested", action="store_true", help="Enable nesting") - parser_add.add_argument("--sshd", action="store_true", help="Enable SSH daemon") - parser_add.add_argument("--git", action="store_true", help="Install git and copy ~/.gitconfig") + parser_add.add_argument("--git", action="store_true", help="Map host ~/.gitconfig into the container") parser_add.add_argument("--certs", action="store_true", help="Mount host CA certificates bundle") parser_add.add_argument("--aptcache", help="URL for an APT cache/proxy (e.g. http://10.0.0.1:3142)") parser_add.add_argument("--ssh-client", action="store_true",