#!/bin/sh
# an installation script for linux_base

case "$2" in
PRE-INSTALL)
	if [ -z "`kldstat -v | grep -E 'linux(aout|elf)'`" ]; then
		echo 'Linux mode is not enabled.'
		echo 'Loading linux kernel module now...'
		if ! kldload linux; then
			echo 'The linux kernel module could not be loaded.'
			echo 'Please enable linux mode manually and retry.'
			exit 1
		fi
	fi
	;;
POST-INSTALL)
	if [ -z "`grep ^linproc /etc/fstab`" ]; then
		echo ''
		echo '+++ Some programs may need linprocfs, please add it to /etc/fstab! +++'
	else
		if [ -z "`mount | grep -w ^linprocfs`" ]; then
			echo ''
			echo '+++ Please mount linprocfs manually! +++'
		fi
	fi
	if [ ! -f ${PKG_PREFIX}/etc/nsswitch.conf ]; then
		cp ${PKG_PREFIX}/etc/nsswitch.conf.dist \
			${PKG_PREFIX}/etc/nsswitch.conf
	fi
	if [ ! -f ${PKG_PREFIX}/etc/krb5.conf ]; then
		
		if [ -f /etc/krb5.conf ]; then
			ln -s /etc/krb5.conf ${PKG_PREFIX}/etc
		else
			cp ${PKG_PREFIX}/etc/krb5.conf.dist \
				${PKG_PREFIX}/etc/krb5.conf
		fi

	fi
	if [ ! -f ${PKG_PREFIX}/etc/yp.conf ]; then
		cp ${PKG_PREFIX}/etc/yp.conf.sample ${PKG_PREFIX}/etc/yp.conf
	fi
#
# This is needed when updating to ensure that already installed libraries
# are recorded in ${PKG_PREFIX}/etc/ld.so.cache
#
	echo ''
	echo 'Running linux ldconfig...'
	${PKG_PREFIX}/sbin/ldconfig -r ${PKG_PREFIX}
#
# Create linux mtree
#
	mkdir -p ${PKG_PREFIX}/var/yp
	mkdir -p ${PKG_PREFIX}/var/spool/repackage
	mkdir -p ${PKG_PREFIX}/var/spool/mail
	mkdir -p ${PKG_PREFIX}/var/spool/lpd
	mkdir -p ${PKG_PREFIX}/var/preserve
	mkdir -p ${PKG_PREFIX}/var/opt
	mkdir -p ${PKG_PREFIX}/var/nis
	mkdir -p ${PKG_PREFIX}/var/lock/subsys
	mkdir -p ${PKG_PREFIX}/var/local
	mkdir -p ${PKG_PREFIX}/var/lib/misc
	mkdir -p ${PKG_PREFIX}/var/lib/games
	mkdir -p ${PKG_PREFIX}/var/empty
	mkdir -p ${PKG_PREFIX}/var/db
	mkdir -p ${PKG_PREFIX}/var/cache
	mkdir -p ${PKG_PREFIX}/usr/src
	mkdir -p ${PKG_PREFIX}/usr/share/xsessions
	mkdir -p ${PKG_PREFIX}/usr/share/pixmaps
	mkdir -p ${PKG_PREFIX}/usr/share/misc
	mkdir -p ${PKG_PREFIX}/usr/share/man/mann
	mkdir -p ${PKG_PREFIX}/usr/share/man/man9
	mkdir -p ${PKG_PREFIX}/usr/share/man/man6
	mkdir -p ${PKG_PREFIX}/usr/share/man/man4
	mkdir -p ${PKG_PREFIX}/usr/share/man/man2
	mkdir -p ${PKG_PREFIX}/usr/share/locale/zh_CN.GB2312/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/yi/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/xh/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/vi/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/uz@Latn/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/uz/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/tl/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/tk/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/th/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/te/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/ta/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/sr@ije/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/sr@Latn/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/sq/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/pa/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/or/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/nso/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/nn/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/ne/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/mr/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/mn/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/ml/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/mk/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/mi/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/lv/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/lt/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/li/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/kn/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/ia/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/hy/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/hi/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/he/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/gu/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/fa/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/eu/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/es_ES/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/en_CA/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/en/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/cy/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/bs/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/br/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/bn/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/bg/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/az_IR/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/az/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/as/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/ar/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/locale/am/LC_MESSAGES
	mkdir -p ${PKG_PREFIX}/usr/share/games
	mkdir -p ${PKG_PREFIX}/usr/share/icons
	mkdir -p ${PKG_PREFIX}/usr/share/empty
	mkdir -p ${PKG_PREFIX}/usr/share/dict
	mkdir -p ${PKG_PREFIX}/usr/share/applications
	mkdir -p ${PKG_PREFIX}/usr/lib/gcc-lib
	mkdir -p ${PKG_PREFIX}/usr/lib/games
	mkdir -p ${PKG_PREFIX}/usr/games
	mkdir -p ${PKG_PREFIX}/usr/doc
	mkdir -p ${PKG_PREFIX}/usr/etc
	mkdir -p ${PKG_PREFIX}/usr/X11R6/share
	mkdir -p ${PKG_PREFIX}/usr/X11R6/man
	mkdir -p ${PKG_PREFIX}/usr/X11R6/lib/tls
	mkdir -p ${PKG_PREFIX}/usr/X11R6/include
	mkdir -p ${PKG_PREFIX}/usr/X11R6/bin
	mkdir -p ${PKG_PREFIX}/sys
	mkdir -p ${PKG_PREFIX}/srv
	mkdir -p ${PKG_PREFIX}/selinux
	mkdir -p ${PKG_PREFIX}/proc
	mkdir -p ${PKG_PREFIX}/opt
	mkdir -p ${PKG_PREFIX}/mnt
	mkdir -p ${PKG_PREFIX}/media
	mkdir -p ${PKG_PREFIX}/lib/modules
	mkdir -p ${PKG_PREFIX}/etc/xinetd.d
	mkdir -p ${PKG_PREFIX}/etc/rpm
	mkdir -p ${PKG_PREFIX}/etc/opt
	mkdir -p ${PKG_PREFIX}/etc/ld.so.conf.d
	mkdir -p ${PKG_PREFIX}/etc/X11/sysconfig
	mkdir -p ${PKG_PREFIX}/etc/X11/starthere
	mkdir -p ${PKG_PREFIX}/etc/X11/serverconfig
	mkdir -p ${PKG_PREFIX}/etc/X11/applnk
	;;
esac

exit 0
