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:
@@ -65,7 +65,7 @@ cp -rf ./cfg/os-release root.x86_64/var/lib/machines/arch/etc/os-release
|
|||||||
|
|
||||||
# Configure sudoers for wheel group
|
# Configure sudoers for wheel group
|
||||||
echo "Configuring sudoers..."
|
echo "Configuring sudoers..."
|
||||||
arch-chroot root.x86_64/var/lib/machines/arch /bin/sh -c 'echo "%wheel ALL=(ALL:ALL) NOPASSWD: /usr/bin/pacman -Syu --noconfirm, /usr/bin/rm -rf /var/lib/pacman/db.lck, /usr/bin/poweroff, /usr/bin/reboot, /usr/bin/machinectl" >> /etc/sudoers'
|
arch-chroot root.x86_64/var/lib/machines/arch /bin/sh -c 'echo "%wheel ALL=(ALL:ALL) NOPASSWD: /usr/bin/pacman, /usr/bin/pacstrap, /usr/bin/arch-chroot, /usr/bin/rm, /usr/bin/mkdir, /usr/bin/mv, /usr/bin/cp, /usr/bin/poweroff, /usr/bin/reboot, /usr/bin/machinectl, /bin/bash" >> /etc/sudoers'
|
||||||
|
|
||||||
# Install aigpt (aios core package)
|
# Install aigpt (aios core package)
|
||||||
echo "Installing aigpt..."
|
echo "Installing aigpt..."
|
||||||
|
|||||||
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'
|
# Copy .zshrc for user 'ai'
|
||||||
cp -rf ./cfg/zshrc $ROOTFS/home/ai/.zshrc
|
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'
|
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)
|
# MCP auto-setup (run once after .claude.json is created)
|
||||||
if [[ -f ~/.claude.json ]] && ! grep -q '"aigpt"' ~/.claude.json 2>/dev/null; then
|
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
|
if command -v claude &>/dev/null && command -v aigpt &>/dev/null; then
|
||||||
|
|||||||
Reference in New Issue
Block a user