From 642ccb28a6a4a88442f00cb6e13a94c5f79e7921 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 7 Nov 2025 15:21:14 +0000 Subject: [PATCH] refactor: Create child containers during build as root, not at ai user login - Renamed init-containers.sh to user-continer.sh - Moved container creation from ai user first login to build.zsh - Removed initialization check from ai user .zshrc - Child containers (workspace, restore-img) now pre-created by root - ai user simply uses pre-existing containers --- build.zsh | 7 +++---- cfg/init-containers.sh | 46 ------------------------------------------ cfg/setup-user.sh | 14 +------------ cfg/user-continer.sh | 37 +++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 63 deletions(-) delete mode 100644 cfg/init-containers.sh create mode 100644 cfg/user-continer.sh diff --git a/build.zsh b/build.zsh index f98598c..365a4bc 100755 --- a/build.zsh +++ b/build.zsh @@ -101,15 +101,14 @@ echo "=== Finalizing ===" # Copy aios-ctl.zsh for host machine control cp -rf ./cfg/aios-ctl.zsh root.x86_64/var/lib/machines/aios/opt/aios-ctl.zsh -# Prepare directory for child containers (ai user will create them as needed) -echo "Preparing directory for child containers..." -mkdir -p root.x86_64/var/lib/machines/aios/var/lib/machines +# Create child containers (workspace, restore-img) +bash ./cfg/user-continer.sh # Copy install script cp -rf ./cfg/install.sh ./install.sh chmod +x ./install.sh -# Create tarball with aios (ready for child containers) +# Create tarball with aios (includes child containers) echo "Creating tarball..." tar -zcvf aios-bootstrap.tar.gz root.x86_64/ install.sh diff --git a/cfg/init-containers.sh b/cfg/init-containers.sh deleted file mode 100644 index 8a8dac8..0000000 --- a/cfg/init-containers.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -# Initialize child containers for ai user -# This script runs once on first login - -echo "=== Initializing workspace containers ===" -echo "This may take a few minutes..." - -# Create workspace directory -mkdir -p /tmp/workspace-init - -# Create base workspace -echo "Creating workspace container..." -sudo pacstrap -c /tmp/workspace-init base - -# Configure workspace -sudo arch-chroot /tmp/workspace-init /bin/sh -c 'pacman -Syu --noconfirm vim git zsh openssh nodejs npm sqlite' - -# Add securetty for pts login -sudo bash -c 'cat >> /tmp/workspace-init/etc/securetty <> $ROOTFS/home/ai/.zshrc <<'EOF' -# Initialize workspace containers on first login -if [ ! -f ~/.aios-initialized ]; then - echo "First login detected. Initializing workspace containers..." - if command -v sudo &>/dev/null && [ -x /usr/local/bin/init-containers.sh ]; then - /usr/local/bin/init-containers.sh && touch ~/.aios-initialized - fi -fi - # MCP auto-setup (run once after .claude.json is created) if [[ -f ~/.claude.json ]] && ! grep -q '"aigpt"' ~/.claude.json 2>/dev/null; then if command -v claude &>/dev/null && command -v aigpt &>/dev/null; then diff --git a/cfg/user-continer.sh b/cfg/user-continer.sh new file mode 100644 index 0000000..4ed44bb --- /dev/null +++ b/cfg/user-continer.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Create child containers inside aios for ai user +# This script runs during build.zsh as root + +ROOTFS="root.x86_64/var/lib/machines/aios" + +echo "=== Creating child containers ===" + +# Create workspace container +echo "Creating workspace container..." +mkdir -p /tmp/workspace-build +pacstrap -c /tmp/workspace-build base + +# Configure workspace +arch-chroot /tmp/workspace-build /bin/sh -c 'pacman -Syu --noconfirm vim git zsh openssh nodejs npm sqlite' + +# Add securetty for pts login +cat >> /tmp/workspace-build/etc/securetty <<'EOF' +pts/0 +pts/1 +pts/2 +pts/3 +pts/4 +pts/5 +EOF + +# Move to aios +mkdir -p $ROOTFS/var/lib/machines +mv /tmp/workspace-build $ROOTFS/var/lib/machines/workspace + +# Create restore-img as clean backup +echo "Creating restore-img (backup)..." +cp -a $ROOTFS/var/lib/machines/workspace $ROOTFS/var/lib/machines/restore-img + +echo "✓ Child containers created" +echo " - workspace" +echo " - restore-img"