#!/bin/bash
readonly KERNEL="vmlinuz-linux"
readonly RIGHT_GROUPS="optical,wheel,disk"

function setup_locale() {
	if [ -f /etc/locale.conf ]; then
		cp -f /etc/locale.conf $INSTALLPATH/etc/
	fi
}

function setup_time() {
	if [ -h /etc/localtime ]; then
		cp -fd /etc/localtime $INSTALLPATH/etc/
	fi
	if [ -f /etc/adjtime ]; then
		cp -f /etc/adjtime $INSTALLPATH/etc/
	fi
}

function setup_console_keymap() {
	if [ -f /etc/vconsole.conf ]; then
		cp -f /etc/vconsole.conf $INSTALLPATH/etc/
	fi
}

function setup_initrd() {
	systempart=$1
	
	if [ $(echo $systempart | cut -c1-7) == "/dev/vd" ]; then
		sed 's/^MODULES=()/MODULES=(virtio_pci virtio_blk)/' -i $INSTALLPATH/etc/mkinitcpio.conf
	fi
	mount --bind /proc $INSTALLPATH/proc
	mount --bind /dev $INSTALLPATH/dev
	mount --bind /sys $INSTALLPATH/sys
	#~ local status=0; chroot $INSTALLPATH mkinitcpio -g /boot/initramfs-${KERNEL#*-}.img -k /boot/$KERNEL || status=$INITRD_ERROR
	local status=0; chroot $INSTALLPATH mkinitcpio -P -k /boot/$KERNEL || status=$INITRD_ERROR
	umount $INSTALLPATH/sys
	umount $INSTALLPATH/dev
	umount $INSTALLPATH/proc
	return $status
}
