- Increase sleep time to 2 seconds - Add SIGKILL as last resort - Continue with warning if removal fails
137 lines
3.1 KiB
Bash
137 lines
3.1 KiB
Bash
#!/bin/bash
|
|
# aios installation script
|
|
|
|
set -e
|
|
|
|
NAME="aios"
|
|
BACKUP="${NAME}back"
|
|
TARBALL="aios-bootstrap.tar.gz"
|
|
|
|
echo "=== aios installation ==="
|
|
echo ""
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Error: This script must be run as root"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if tarball exists
|
|
if [ ! -f "$TARBALL" ]; then
|
|
echo "Error: $TARBALL not found"
|
|
echo "Please download aios-bootstrap.tar.gz first"
|
|
exit 1
|
|
fi
|
|
|
|
# Extract tarball
|
|
echo "1. Extracting $TARBALL..."
|
|
tar xf "$TARBALL"
|
|
|
|
# Move to /var/lib/machines/
|
|
echo "2. Installing to /var/lib/machines/$NAME..."
|
|
rm -rf /var/lib/machines/$NAME
|
|
mkdir -p /var/lib/machines
|
|
mv root.x86_64/var/lib/machines/arch /var/lib/machines/$NAME
|
|
|
|
# Copy nspawn configuration
|
|
echo "3. Installing systemd-nspawn configuration..."
|
|
mkdir -p /etc/systemd/nspawn
|
|
|
|
# Create aios.nspawn
|
|
cat > /etc/systemd/nspawn/$NAME.nspawn <<'EOF'
|
|
[Exec]
|
|
Boot=yes
|
|
PrivateUsers=pick
|
|
ResolvConf=copy-host
|
|
|
|
[Files]
|
|
Bind=/root/.config/syui/ai:/root/.config/syui/ai
|
|
|
|
[Network]
|
|
VirtualEthernet=no
|
|
EOF
|
|
|
|
# Create aiosback.nspawn
|
|
cat > /etc/systemd/nspawn/$BACKUP.nspawn <<'EOF'
|
|
[Exec]
|
|
Boot=yes
|
|
PrivateUsers=pick
|
|
ResolvConf=copy-host
|
|
|
|
[Files]
|
|
Bind=/root/.config/syui/ai:/root/.config/syui/ai
|
|
|
|
[Network]
|
|
VirtualEthernet=no
|
|
EOF
|
|
|
|
# Create workspace.nspawn
|
|
cat > /etc/systemd/nspawn/workspace.nspawn <<'EOF'
|
|
[Exec]
|
|
Boot=yes
|
|
PrivateUsers=pick
|
|
ResolvConf=copy-host
|
|
|
|
[Files]
|
|
Bind=/root/.config/syui/ai:/root/.config/syui/ai
|
|
|
|
[Network]
|
|
VirtualEthernet=no
|
|
EOF
|
|
|
|
# Create bind mount directory
|
|
mkdir -p /root/.config/syui/ai
|
|
|
|
# Enable systemd-machined
|
|
echo "4. Enabling systemd-machined..."
|
|
systemctl enable --now systemd-machined
|
|
|
|
# Remove existing images if they exist
|
|
echo "5. Checking for existing images..."
|
|
for img in $BACKUP workspace; do
|
|
if machinectl list-images | grep -q "^$img"; then
|
|
echo " Removing existing image: $img"
|
|
machinectl poweroff $img 2>/dev/null || true
|
|
sleep 2
|
|
machinectl terminate $img 2>/dev/null || true
|
|
sleep 2
|
|
# Force kill if still running
|
|
if machinectl status $img &>/dev/null; then
|
|
machinectl kill $img --signal=SIGKILL 2>/dev/null || true
|
|
sleep 2
|
|
fi
|
|
machinectl remove $img 2>/dev/null || echo " Warning: Could not remove $img (will skip)"
|
|
fi
|
|
done
|
|
|
|
# Create initial backup
|
|
echo "6. Creating initial backup image..."
|
|
machinectl clone $NAME $BACKUP
|
|
|
|
# Create workspace container for AI operations
|
|
echo "7. Creating workspace container..."
|
|
machinectl clone $NAME workspace
|
|
|
|
echo ""
|
|
echo "=== Installation complete ==="
|
|
echo ""
|
|
echo "Next steps for each user:"
|
|
echo " 1. Copy control script to your home:"
|
|
echo " cp /var/lib/machines/$NAME/opt/aios-ctl.zsh ~/.aios-ctl.zsh"
|
|
echo ""
|
|
echo " 2. Add to your .zshrc:"
|
|
echo " echo 'source ~/.aios-ctl.zsh' >> ~/.zshrc"
|
|
echo " source ~/.zshrc"
|
|
echo ""
|
|
echo " 3. Start aios:"
|
|
echo " aios-start"
|
|
echo ""
|
|
echo " 4. Login to aios:"
|
|
echo " aios-login"
|
|
echo ""
|
|
echo "Available commands:"
|
|
echo " aios-start, aios-stop, aios-shell, aios-login"
|
|
echo " aios-backup, aios-reset, aios-update"
|
|
echo " aios-help for full list"
|
|
echo ""
|