#!/bin/sh

install_syslinux() {
	pacman -S gptfdisk syslinux
	read -p "Please change start disk options in the following file."
	vim /boot/syslinux/syslinux.cfg
	echo "Installing syslinux bootloader"
	syslinux-install_update -iam
}

install_mykeys() {
	echo "Install my keys to your system! muhaha"
	mkdir ~/.ssh
	curl http://share.julianjacobi.net/keys/misc.pub >> ~/.ssh/authorized_keys
	curl http://share.julianjacobi.net/keys/misc_work.pub >> ~/.ssh/authorized_keys
	echo "my keys are now installed on your system if this what not your wish please clear ~/.ssh/authorized_keys file"
}


pacman -S vim git

clear
echo "Welcome to my personal ArchLinux install script!"
read -p "First let me know your favorite Hostname: " hostname
echo $hostname > /etc/hostname

echo ""
echo "Lets change the root users password."
passwd

echo ""
echo "Lets create an additional user which is in sudoers"
read -p "Username: " new_user
useradd -m -G users,wheel $new_user
passwd $new_user

echo ""
echo "Please uncomment the right sudoers rule in the now opened sudoers file."
vim /etc/sudoers

echo ""
echo ""
echo "Please give me now some aditional Informations!"
echo "If you are located in Germany the default values should be ok for you."
read -p "LANG= [de_DE.UTF-8]: " lang
read -p "LC_COLLATE= [C]: " collate
read -p "LANGUAGE= [de_DE]: " language
read -p "KEYMAP= [de-latin1]: " keymap
read -p "Timezone [Europe/Berlin]: " timezone

if [ "$lang" = "" ]
then
	lang="de_DE.UTF-8"
fi
if [ "$collate" = "" ]
then
	collate="C"
fi
if [ "$language" = "" ]
then
	language="de_DE"
fi
if [ "$keymap" = "" ]
then
	keymap="de-latin1"
fi
if [ "$timezone" = "" ]
then
	timezone="Europe/Berlin"
fi

echo LANG=$lang > /etc/locale.conf
echo LC_COLLATE=$collate >> /etc/locale.conf
echo LANGUAGE=$language >> /etc/locale.conf

echo KEYMAP=$keymap > /etc/vconsole.conf

ln -s /usr/share/zoneinfo/$timezone /etc/localtime

echo ""
echo "Now i will install vim and git"

echo ""
read -p "Please uncomment the right entrys in the following file"

vim /etc/locale.gen
locale-gen

echo ""
read -p "Do you want to install and enable sshd? [Y/n]" sshd
case $sshd in
	[Yy]* ) pacman -S openssh; systemctl enable ssshd;;
	[Nn]* ) ;;
	*) pacman -S openssh; systemctl enable sshd;;
esac

echo ""
read -p "Do you wish to install syslinux bootloader? [Y/n]" syslinux
case $syslinux in
	[Yy]* ) install_syslinux;;
	[Nn]* ) ;;
	* ) install_syslinux;;
esac

echo ""
read -p "Do you wish to install ssh keys from Julian Jacobi in authorized key file? [y/N]" mykeys
case $mykeys in
	[Yy]* ) install_mykeys;;
esac

echo ""
echo "Install yaourt"

echo "[archlinuxfr]" >> /etc/pacman.conf
echo "SigLevel = Never" >> /etc/pacman.conf
echo "Server = http://repo.archlinux.fr/\$arch" >> /etc/pacman.conf

pacman -Sy
pacman -S package-query yaourt


echo "Congratulation you have successfully installed ArchLinux please exit changeroot and reboot the system!"
