feat: Add automatic workspace container initialization on first login
- Created init-containers.sh to create workspace and restore-img - Runs automatically on ai user's first login - Uses ~/.aios-initialized flag to run once - Updated sudoers to allow pacstrap, arch-chroot commands
This commit is contained in:
46
cfg/init-containers.sh
Normal file
46
cfg/init-containers.sh
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/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 ""
|
||||
@@ -46,9 +46,21 @@ cp -rf ./cfg/zshrc $ROOTFS/root/.zshrc
|
||||
# Copy .zshrc for user 'ai'
|
||||
cp -rf ./cfg/zshrc $ROOTFS/home/ai/.zshrc
|
||||
|
||||
# Add MCP auto-setup and claude auto-start for ai user (login shell only)
|
||||
# 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)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user