#!/bin/sh
#
# ELWIX Build script for ELWIX CompactFlash image
#
# (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
# by Michael Pounov <misho@elwix.org>
#
# $Id: build_fs.sh,v 1.12 2021/03/11 13:59:50 misho Exp $
#
[ -r ./config/rc.elwix ] && . ./config/rc.elwix
if [ X"${ELWIX_IS_CONFIGURED}" != X"YES" ]; then
echo
echo "ELWIX project is not configured !?!"
echo
exit 1
fi
if [ ! -d ${BSDSRC} ]; then
echo
echo "ELWIX project is not configured - missing BSD sources !?!"
echo
exit 1
fi
if [ "${USER}" != "root" ]; then
echo
echo "ELWIX project is not configured - FS must build under root !?!"
echo
exit 1
fi
clean_fsdir()
{
echo "+++ Clean ELWIX FS ... $1"
chflags -Rf nosunlink $1
rm -rf $1 $2
}
build_fsdir()
{
#
# Structure of ELWIX CF Drive mount on /elwix
#
echo "+++ Build ELWIX FS directory ... $1"
mkdir -p $1
cd $1
# boot
install -d boot;
# cf
install -d cf;
# etc
install -d etc;
# exports
install -d exports;
# home
install -d home;
# local
install -d local;
install -d local/lib;
# root
install -d -m 0750 root;
# pkg
install -d pkg;
# tftpboot
install -d tftpboot;
chown -hR root:wheel .
cd -
}
create_etc_fstab()
{
cat >$1/etc/fstab <<_EOF
# Automatic generated fstab for ELWIX $2 at ${BUILD_DATE}
#
_EOF
}
update_etc_cfexec()
{
echo "mount = \"/elwix\"" >> $1/etc/cfexec.conf
}
install_fsdir()
{
echo "+++ Install ELWIX RootFS $1 in bundle OS install file ..."
OSZ=""
install -v ${REL}/${ROOTFS_KERN} $1/boot/kernel/kernel.gz
case "$2" in
[Ee][Xx][Tt])
install -d $1/usr
cd $1/usr
pax -r -z -pe -f ${REL}/${ROMFS_IMG}
cd -
install -d $1/pkg
cd $1/pkg
pax -r -z -pe -f ${REL}/${ROMFS_IMG2}
cd -
OSZ=${REL}/${OS_EXT}
;;
*)
install -v ${REL}/${ROMFS_IMG} \
$1/altroot/elwix-firmware-${VERSION}_${TARGET_ARCH}
ln $1/altroot/elwix-firmware-${VERSION}_${TARGET_ARCH} \
$1/altroot/${ROMFS_IMG}
ln -s /elwix/altroot/elwix-firmware-${VERSION}_${TARGET_ARCH} \
$1/${ROMFS_IMG}
install -v ${REL}/${ROMFS_IMG2} \
$1/altroot/elwix-firmware2-${VERSION}_${TARGET_ARCH}
ln $1/altroot/elwix-firmware2-${VERSION}_${TARGET_ARCH} \
$1/altroot/${ROMFS_IMG2}
ln -s /elwix/altroot/elwix-firmware2-${VERSION}_${TARGET_ARCH} \
$1/${ROMFS_IMG2}
OSZ=${REL}/${OS}
;;
esac
cd $1
tar -czvf $OSZ .
echo "+++ Completed ELWIX RootFS $1 --> $OSZ"
}
### main()
if [ ! -r ${REL}/${ROOTFS_KERN} -o ! -r ${REL}/${ROMFS_IMG} ]; then
echo
echo "Error:: not found kernel or firmware elwix files ..."
echo
echo " For fix this issue, please re-run build_rootfs.sh or build_romfs.sh"
echo
exit 1
fi
clean_fsdir ${FS} ${REL}/${OS} || exit 1
clean_fsdir ${FS_EXT} ${REL}/${OS_EXT} || exit 1
build_fsdir ${FS} || exit 1
build_fsdir ${FS_EXT} || exit 1
MakeFS_home ${FS} || exit 1
MakeFS_home ${FS_EXT} || exit 1
MakeFS_var ${FS} ${FS_ETC} || exit 1
MakeFS_var ${FS_EXT} ${FS_EXT_ETC} || exit 1
MakeFS_etc ${FS} ${FS_ETC} rootfs || exit 1
MakeFS_etc ${FS_EXT} ${FS_EXT_ETC} rootfsext || exit 1
create_etc_fstab ${FS} || exit 1
create_etc_fstab ${FS_EXT} ext || exit 1
update_etc_cfexec ${FS} || exit 1
update_etc_cfexec ${FS_EXT} ext || exit 1
MakeFS_boot ${FS} || exit 1
MakeFS_boot ${FS_EXT} || exit 1
install_fsdir ${FS} || exit 1
install_fsdir ${FS_EXT} ext || exit 1
echo "+++ Complete build ELWIX RootFS system"
echo "ELWIX RootFS finish version ${VERSION}, Good luck!"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>