#!/bin/bash

##Super awesome arch builder script for lazy people like me. 
##I *did* all the work once, and now I've automated it, bitches
#
##Much love,
##/x1101

##Licensed GPLv3+

echo "Lets setup some mirrors"
cp /etc/pacman.d/mirrorlist{,.backup}
rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist

echo "What disk should we work on? [/dev/sdb]"
read ans
if [[ "${ans}" == "" ]];then
	DISK="/dev/sdb"
else
	DISK="${ans}"
fi

function partin
{
	#setup partitions
	##	/boot	200M bootable
	##	swap	4G
	##	/	remainder
	### Made this a LOT prettier thanks Hank!
	echo -e "/boot\t200M"
	echo -e "n\np\n\n\n+200M\nt\n83\nw\n\n"|fdisk ${DISK} > /dev/null 2>&1
	echo -e "swap\t4G"
	echo -e "n\np\n\n\n+4G\nt\n82\nw\n\n"|fdisk ${DISK} > /dev/null 2>&1
	echo -e "/\tRemainder"
	echo -e "n\np\n\n\n\nt\n83\nw\n\n"|fdisk ${DISK} > /dev/null 2>&1
	echo "Done making partitions, press [enter] to continue"
	read ans
}

function formattin
{
	mkfs.ext4 ${DISK}1 > /dev/null 2>&1
	mkfs.ext4 ${DISK}3 > /dev/null 2>&1
}

function mntn
{
	#Mountification
	echo "Mounting root ..."
	mount ${DISK}3 /mnt
	echo "Mounting boot"
	mount ${DISK}1 /mnt/boot
}

function strappin
{
	echo "pacstrapping..."
	pacstrap /mnt base
	genfstab -p /mnt >> /mnt/etc/fstab
	arch-chroot /mnt ln -sf /usr/share/zoneinfo/America/New_York/etc/localtime
}

function installin
{
	#Installing shit
	echo "Installing grub-bios"
	arch-chroot /mnt pacman -S grub-bios
	echo "Installing other packages"
	arch-chroot /mnt pacman -S xfce4 chromium slim xorg-server xorg-server-common xorg-server-utils vim networkmanager network-manager-applet xfce4-whiskermenu-plugin xfce4-mixer xfce4-power-manger net-tools htop
}

function chrootin
{
	#CHROOT
	echo "chroot'ing"
	arch-chroot /mnt modprobe dm-mod; grub-install --recheck ${DISK}; grub-mkconfig -o /boot/grub/grub.cfg
	arch-chroot /mnt systemctl set-default multi-user.target; systemctl enable slim.service
}

## ToDo List
# Fix TimeZones
partin
formattin
mntn
strappin
installin
chrootin
1