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
This commit is contained in:
Claude
2025-11-07 15:21:14 +00:00
parent e2b0d7a51d
commit 642ccb28a6
4 changed files with 41 additions and 63 deletions

View File

@@ -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

View File

@@ -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 <<EOF
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
EOF'
# Move to /var/lib/machines
sudo mkdir -p /var/lib/machines
sudo mv /tmp/workspace-init /var/lib/machines/workspace
# Create restore-img as clean backup
echo "Creating restore-img (backup)..."
sudo cp -a /var/lib/machines/workspace /var/lib/machines/restore-img
echo ""
echo "✓ Initialization complete!"
echo ""
echo "Available containers:"
echo " workspace - Working environment"
echo " restore-img - Clean backup"
echo ""
echo "Usage:"
echo " sudo machinectl start workspace"
echo " sudo machinectl shell workspace"
echo ""

View File

@@ -46,21 +46,9 @@ cp -rf ./cfg/zshrc $ROOTFS/root/.zshrc
# Copy .zshrc for user 'ai'
cp -rf ./cfg/zshrc $ROOTFS/home/ai/.zshrc
# Copy container initialization script
cp -rf ./cfg/init-containers.sh $ROOTFS/usr/local/bin/init-containers.sh
arch-chroot $ROOTFS /bin/sh -c 'chmod +x /usr/local/bin/init-containers.sh'
# Add initialization, MCP auto-setup and claude auto-start for ai user (login shell only)
# Add MCP auto-setup and claude auto-start for ai user (login shell only)
cat >> $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

37
cfg/user-continer.sh Normal file
View File

@@ -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"