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

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

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

function setup_console_keymap() {
	if [ -f /etc/vconsole.conf ]; then
		cp -f /etc/vconsole.conf $INSTALL_PATH/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 $INSTALL_PATH/etc/mkinitcpio.conf
	fi
	mount --bind /proc $INSTALL_PATH/proc
	mount --bind /dev $INSTALL_PATH/dev
	mount --bind /sys $INSTALL_PATH/sys
	#~ local status=0; chroot $INSTALL_PATH mkinitcpio -g /boot/initramfs-${KERNEL#*-}.img -k /boot/$KERNEL || status=$INITRD_ERROR
	local status=0; chroot $INSTALL_PATH mkinitcpio -P -k /boot/$KERNEL || status=$INITRD_ERROR
	umount $INSTALL_PATH/sys
	umount $INSTALL_PATH/dev
	umount $INSTALL_PATH/proc
	return $status
}
