#!/usr/bin/env bash
# Runs INSIDE arch-chroot. Locale, time, hostname, user, network.
set -euo pipefail
source /root/arch-system-hyprland/system.conf

# time + locale
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
hwclock --systohc
sed -i "s/^#\s*\($LOCALE\)/\1/" /etc/locale.gen
locale-gen
echo "LANG=$LOCALE" > /etc/locale.conf
echo "KEYMAP=$KEYMAP" > /etc/vconsole.conf

# hostname
echo "$HOSTNAME" > /etc/hostname

# user + sudo (wheel)
useradd -m -G wheel -s /bin/bash "$USERNAME" 2>/dev/null || true
echo "%wheel ALL=(ALL:ALL) ALL" > /etc/sudoers.d/10-wheel
chmod 440 /etc/sudoers.d/10-wheel
echo "Set passwords for root and $USERNAME:"
passwd root
passwd "$USERNAME"

# move the repo into the user's home so provisioning runs as them after reboot
cp -a /root/arch-system-hyprland "/home/$USERNAME/arch-system-hyprland"
chown -R "$USERNAME:$USERNAME" "/home/$USERNAME/arch-system-hyprland"

# network up on first boot
systemctl enable NetworkManager.service
