#!/bin/bash
# Miasma OS post-installation script
# This script runs after the alis installation is complete

set -eu

echo "Running Miasma OS post-installation setup..."

# Mount necessary filesystems for chroot
mount -t proc /proc /mnt/proc
mount -t sysfs /sys /mnt/sys
mount --rbind /dev /mnt/dev
mount --rbind /run /mnt/run

# Enable AppArmor
echo "Enabling AppArmor..."
chroot /mnt systemctl enable apparmor.service

# Enable firewall
echo "Enabling firewall..."
chroot /mnt systemctl enable nftables.service

# Set zsh as default shell for the user
echo "Setting zsh as default shell..."
chroot /mnt chsh -s /usr/bin/zsh $(cat /mnt/tmp/miasma-username)

# Create doas configuration
echo "Creating doas configuration..."
cat > /mnt/etc/doas.conf << 'EOF'
# Miasma OS doas configuration
# Allow wheel group members to run sudo-like commands
permit keepenv :wheel
permit persist keepenv root
EOF

# Set proper permissions for doas.conf
chmod 644 /mnt/etc/doas.conf

# Enable systemd-timesyncd for time synchronization
echo "Enabling time synchronization..."
chroot /mnt systemctl enable systemd-timesyncd.service

# Clean up temporary files
rm -f /mnt/tmp/miasma-username

echo "Miasma OS post-installation setup complete!"