#!/bin/sh
#
# ELWIX install script for image
#
# (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
# by Michael Pounov <misho@elwix.org>
#
# $Id: install2img.sh,v 1.3 2012/10/12 08:22:43 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 [ "${USER}" != "root" ]; then
echo
echo "ELWIX project is not configured - install must build under root !?!"
echo
exit 1
fi
MNT="/mnt"
DEV=""
mkdevice()
{
echo "+++ Make prepare file image ... "
rm -f $1
dd if=/dev/zero of=$1 bs=1024 count=$2
echo -n "+++ Assign memory device to image $1 ... "
DEV=`mdconfig -a -tvnode -f $1`
echo $DEV
if [ -z "$DEV" ]; then
rm -f $1
exit 3
fi
}
initdev()
{
echo -n "+++ Init device label ... "
if disklabel -w $1; then
echo "OK"
else
echo "Failed!"
exit 3
fi
if newfs -b8192 -f1024 -m0 -Lelwix ${1}a; then
echo "+++ Formatting ... OK"
else
echo "+++ Formatting ... Failed!"
exit 3
fi
}
mountdev()
{
echo -n "+++ Mount device $1 to $MNT ... "
if mount /dev/${1}a $MNT; then
echo "OK"
else
echo "Failed!"
exit 4
fi
}
umountdev()
{
echo -n "+++ Unmount $MNT ... "
if umount $MNT; then
echo "OK"
else
echo "Failed!"
exit 4
fi
}
enablejfs()
{
if tunefs -n enable -j enable ${1}a; then
echo "Start FS Journaling ... OK"
else
echo "Start FS Journaling ... Failed!"
exit 6
fi
}
boot2dev()
{
echo -n "+++ Installboot to device $1 ... "
if disklabel -B -b ${WORLD}/boot/boot -m ${TARGET} $1; then
echo "OK"
else
echo "Failed!"
exit 7
fi
}
install2()
{
echo -n "+++ Install ELWIX OS from $1 into $MNT ... "
if tar -xzvpf $1 -C $MNT; then
echo "OK"
else
echo "Failed!"
exit 5
fi
}
cleandev()
{
mdconfig -d -u $1
}
gencksum()
{
echo -n "+++ Generate check sums ... "
md5 $1 >$2
sha1 $1 >$3
echo "OK"
}
### main()
if [ ! -r ${REL}/${OS} -a -r ${REL}/${OS_LITE} ]; then
echo
echo "Error:: ELWIX OS file not found!"
echo
exit 2
fi
mkdevice $IMG ${1:-"${IMG_SIZE}"}
initdev $DEV
mountdev $DEV
install2 ${REL}/${OS}
umountdev
#enablejfs $DEV
boot2dev $DEV
cleandev $DEV
gencksum $IMG $MD5CHK $SHA1CHK
mkdevice $IMG_LITE ${1:-"${IMG_SIZE}"}
initdev $DEV
mountdev $DEV
install2 ${REL}/${OS_LITE}
umountdev
#enablejfs $DEV
boot2dev $DEV
cleandev $DEV
gencksum $IMG_LITE $MD5CHK_LITE $SHA1CHK_LITE
echo "ELWIX OS image complete."
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>