if [ "$1" = "" ]; then
	echo "Usage: $0 <stage>"
fi

user=slouken

if [ $1 = "0" ]; then
	fdisk /dev/sda
	mkfs -t ext4 /dev/sda1
	mount /dev/sda1 /mnt
	pacstrap /mnt base base-devel
	genfstab -p /mnt >>/mnt/etc/fstab
	arch-chroot /mnt

	pacman -S syslinux
	mkinitcpio -p linux
	touch /etc/udev/rules.d/80-net-name-slot.rules
	exit

	umount /mnt
	reboot
fi

if [ $1 = "1" ]; then
	echo "archlinux" >/etc/hostname
	cat /proc/version >/etc/arch-release
	ln -sf /usr/share/zoneinfo/PST8PDT /etc/localtime
	sed 's,^#en_US.UTF-8,en_US.UTF-8,' <etc/locale.gen >/etc/locale.gen.new
	mv -f /etc/locale.gen.new /etc/locale.gen
	locale-gen
	systemctl enable dhcpcd
	systemctl start dhcpcd
	pacman -Syu

	echo "Changing root password"
	passwd

	echo "Creating user account"
	useradd -m $user
	passwd $user
fi

if [ $1 = "2" ]; then
	pacman -S xorg-server xorg-xinit xorg-server-utils
	pacman -S open-vm-tools open-vm-tools-modules xf86-input-vmmouse xf86-video-vmware svga-dri
	cat <<__EOF__ >/etc/X11/xorg.conf.d/20-gpudriver.conf
Section "Device"
	Identifier "Card0"
	Driver "vmware"
EndSection
__EOF__
	touch /etc/modules-load.d/vmwgfx
	#systemctl enable vmtoolsd
	reboot
fi

if [ $1 = "3" ]; then
	#vmware-toolbox-cmd timesync enable
	pacman -S slim openssh chromium alsa-utils
	echo "Install your desktop package and add it to ~$user/.xinitrc"
	bash
	systemctl enable slim
	reboot
fi
