# configure KDM for autologin
#
if [ -e $MOUNTDIR/opt/kde/share/config/kdm/kdmrc ]; then
   sed -i 's|[#]*AutoLoginEnable=.*|AutoLoginEnable=true|' \
      $MOUNTDIR/opt/kde/share/config/kdm/kdmrc
   sed -i 's|[#]*AutoReLogin=.*|AutoReLogin=true|' \
      $MOUNTDIR/opt/kde/share/config/kdm/kdmrc
   sed -i 's|[#]*AutoLoginUser=.*|AutoLoginUser=liveuser|' \
      $MOUNTDIR/opt/kde/share/config/kdm/kdmrc
fi

# FIXME: ensure alternatives are correclty set
chroot $MOUNTDIR update-alternatives-set-dri

# set timezone according to LANGUAGE (default is UTC)
#
if [ ! "$MULTILANGUAGE" ]; then
   case $LANGUAGE in
      it) timezone=Europe/Rome ;;
      es) timezone=Europe/Madrid ;;
      fr) timezone=Europe/Paris ;;
      de) timezone=Europe/Berlin ;;
      en) timezone=Europe/London ;;
      *)  timezone=UTC ;;
   esac
   ln -s ../usr/share/zoneinfo/$timezone $MOUNTDIR/etc/localtime
fi

# configure favorites in kde menu
for f in /usr/share/applications/chromium-devel.desktop /opt/kde/share/applications/amarok.desktop; do
   chroot $MOUNTDIR /opt/kde/bin/kickoffcfg --add-favorite $f
done

# clean rpm database before doing other operations with internal rpm
# to fix cross x86/x86_64 installation error: 
# error: db4 error(-30986) from dbcursor->get: DB_PAGE_NOTFOUND: Requested page not found
clean_rpm_database

virtualbox_ver=`ls -d $MOUNTDIR/usr/src/vboxvideo-* | sed "s|.*-||"`
for K in $KERNEL_EXTRAVER $KERNEL_MORE_EXTRAVER; do
   # pre-create video drivers for VirtualBox
   chroot $MOUNTDIR dkms install -q -m vboxguest -v ${virtualbox_ver} -k ${KERNEL_MAJVER}$K --force
   chroot $MOUNTDIR dkms install -q -m vboxvideo -v ${virtualbox_ver} -k ${KERNEL_MAJVER}$K --force
   # remove unused initramfs generated by kernel
   rm -f $MOUNTDIR/boot/initramfs-${KERNEL_MAJVER}${K}.img*
#   # remove failsafe image to save space for livecd
#   rm -f $MOUNTDIR/boot/initramfs-${KERNEL_MAJVER}${KERNEL_EXTRAVER}-failsafe.img*
done

prelink