#!/bin/sh # # ELWIX build script for rootfs firmware # # (C) AITNET ltd - Sofia/Bulgaria # by Michael Pounov # # $Id: build_rootfs.sh,v 1.2 2011/10/18 09:02:05 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 - RootFS must build under root !?!" echo exit 1 fi NEWKERN="${REL}/kernel" clean_elwix() { echo "+++ Clean csh from ELWIX World ..." rm -rf ${BSDOBJ}/usr/src/bin/csh/* echo "+++ Clean ELWIX RootFS firmware ..." rm -rf $MKDIR mkdir $MKDIR echo "+++ Clean RootFS directory ..." rm -rf $ROOTFS mkdir $ROOTFS echo "+++ Clean Release directory ..." rm -rf $REL/$ROOTFS_IMG ${NEWKERN}* } prepare_elwix() { echo "+++ Prepair ELWIX RootFS firmware ..." cd $MKDIR cat >$MKH <<_EOF # Auto-generated Makefile include for crungegen # !!! Dont edit by hand !!! # #BUILDOPTS += TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ} CRUNCH_SUPPRESS_LINK_-sh= 1 CRUNCH_SUPPRESS_LINK_-csh= 1 CRUNCH_SUPPRESS_LINK_-tcsh= 1 LIBS += -L${WORLD}/lib -L${WORLD}/usr/lib _EOF cat >$ROOTFS_CONF <<_EOF srcdirs ${BSDSRC}/bin ${BSDSRC}/sbin ${BSDSRC}/libexec ${BSDSRC}/cddl/sbin ${BSDSRC}/sbin/ggate #buildopts -DRESCUE CRUNCH_CFLAGS=-DRESCUE TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ} buildopts TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ} _EOF cat $CFGDIR/$ROOTFS_CONF >>$ROOTFS_CONF crunchgen -f -p $BSDOBJ -h $MKDIR/$MKH -m $MKF -c elwix.c -e elwix $ROOTFS_CONF cd - } build_elwix() { echo "+++ Build ELWIX RootFS firmware ..." cd $MKDIR make -f $MKF clean make -f $MKF cd - } build_rootdir() { echo "+++ Build RootFS directory ..." cd $ROOTFS install -d bin; install -d dev; install -d elwix; install -d elwix/etc; install -d mnt; install -d -m 0555 proc; install -d sbin; install -d system; install -d -m 1777 tmp; install -d usr; install -d var; ln -fs /usr/lib lib; ln -fs /usr/libexec libexec; ln -fs /elwix/etc etc; ln -fs /elwix/exports exports; ln -fs /elwix/home home; ln -fs /elwix/root root; ln -fs /elwix/tftpboot tftpboot; cd - } install_rootfs() { PRG="/sbin/elwix" BIN="${ROOTFS}/bin" SBIN="${ROOTFS}/sbin" ETC="${ROOTFS}/elwix/etc" echo "+++ Install ELWIX into RootFS directory ..." install $MKDIR/elwix $SBIN InstallList ${ELWIX_ROOTFS} ${WORLD} ${ROOTFS} InstallDir ${ROOTFS_ETC} $ETC ln -s /usr/sbin/nologin $SBIN ln -s $PRG $BIN/test ln -s $PRG $BIN/\[ ln -s $PRG $BIN/cat ln -s $PRG $BIN/chflags ln -s $PRG $BIN/chio ln -s $PRG $BIN/chmod ln -s $PRG $BIN/cp # ln -s $PRG $BIN/csh # ln -s $PRG $BIN/tcsh ln -s /bin/tcsh $BIN/-tcsh ln -s /bin/csh $BIN/-csh ln -s $PRG $BIN/date ln -s $PRG $BIN/dd ln -s $PRG $BIN/df ln -s $PRG $BIN/domainname ln -s $PRG $BIN/echo ln -s $PRG $BIN/expr ln -s $PRG $BIN/getfacl ln -s $PRG $BIN/hostname ln -s $PRG $BIN/kenv ln -s $PRG $BIN/kill ln -s $PRG $BIN/ln ln -s $PRG $BIN/link ln -s $PRG $BIN/ls ln -s $PRG $BIN/mkdir ln -s $PRG $BIN/mv ln -s $PRG $BIN/pax ln -s $PRG $BIN/pkill ln -s $PRG $BIN/pgrep ln -s $PRG $BIN/sh ln -s $PRG $BIN/-sh ln -s $PRG $BIN/ps ln -s $PRG $BIN/pwait ln -s $PRG $BIN/pwd ln -s $PRG $BIN/realpath ln -s $PRG $BIN/rm ln -s $PRG $BIN/unlink ln -s $PRG $BIN/rmdir ln -s $PRG $BIN/setfacl ln -s $PRG $BIN/sleep ln -s $PRG $BIN/stty ln -s $PRG $BIN/sync ln -s $PRG $BIN/uuidgen ln -s $PRG $SBIN/adjkerntz ln -s $PRG $SBIN/atacontrol ln -s $PRG $SBIN/badsect ln -s $PRG $SBIN/bsdlabel ln -s $PRG $SBIN/disklabel ln -s $PRG $SBIN/camcontrol ln -s $PRG $SBIN/ccdconfig ln -s $PRG $SBIN/comcontrol ln -s $PRG $SBIN/conscontrol ln -s $PRG $SBIN/devfs ln -s $PRG $SBIN/dhclient ln -s $PRG $SBIN/dmesg ln -s $PRG $SBIN/dump ln -s $PRG $SBIN/rdump ln -s $PRG $SBIN/dumpfs ln -s $PRG $SBIN/dumpon ln -s $PRG $SBIN/fdisk ln -s $PRG $SBIN/ffsinfo ln -s $PRG $SBIN/fsck ln -s $PRG $SBIN/fsck_ffs ln -s $PRG $SBIN/fsck_ufs ln -s $PRG $SBIN/fsck_4.2bsd ln -s $PRG $SBIN/fsck_msdosfs ln -s $PRG $SBIN/gbde ln -s $PRG $SBIN/ggatec ln -s $PRG $SBIN/ggated ln -s $PRG $SBIN/ggatel ln -s $PRG $SBIN/-geom ln -s $PRG $SBIN/glabel ln -s $PRG $SBIN/gpart ln -s $PRG $SBIN/growfs ln -s $PRG $SBIN/hastctl ln -s $PRG $SBIN/hastd ln -s $PRG $SBIN/ifconfig ln -s $PRG $SBIN/init ln -s $PRG $SBIN/ipfw ln -s $PRG $SBIN/iscontrol ln -s $PRG $SBIN/kldconfig ln -s $PRG $SBIN/kldload ln -s $PRG $SBIN/kldstat ln -s $PRG $SBIN/kldunload ln -s $PRG $SBIN/ldconfig ln -s $PRG $SBIN/md5 ln -s $PRG $SBIN/sha1 ln -s $PRG $SBIN/sha256 ln -s $PRG $SBIN/rmd160 ln -s $PRG $SBIN/mdconfig ln -s $PRG $SBIN/mdmfs ln -s $PRG $SBIN/mount_mfs ln -s $PRG $SBIN/mknod ln -s $PRG $SBIN/mksnap_ffs ln -s $PRG $SBIN/mount ln -s $PRG $SBIN/mount_cd9660 ln -s $PRG $SBIN/mount_msdosfs ln -s $PRG $SBIN/mount_nfs ln -s $PRG $SBIN/mount_ntfs ln -s $PRG $SBIN/mount_nullfs ln -s $PRG $SBIN/mount_udf ln -s $PRG $SBIN/mount_unionfs ln -s $PRG $SBIN/natd ln -s $PRG $SBIN/newfs ln -s $PRG $SBIN/newfs_msdos ln -s $PRG $SBIN/nfsiod ln -s $PRG $SBIN/nos-tun ln -s $PRG $SBIN/pfctl ln -s $PRG $SBIN/pflogd ln -s $PRG $SBIN/ping ln -s $PRG $SBIN/ping6 ln -s $PRG $SBIN/quotacheck ln -s $PRG $SBIN/reboot ln -s $PRG $SBIN/halt ln -s $PRG $SBIN/fastboot ln -s $PRG $SBIN/fasthalt ln -s $PRG $SBIN/recoverdisk ln -s $PRG $SBIN/restore ln -s $PRG $SBIN/rrestore ln -s $PRG $SBIN/route ln -s $PRG $SBIN/rtsol ln -s $PRG $SBIN/savecore ln -s $PRG $SBIN/setkey ln -s $PRG $SBIN/shutdown ln -s $PRG $SBIN/spppcontrol ln -s $PRG $SBIN/swapon ln -s $PRG $SBIN/swapoff ln -s $PRG $SBIN/swapctl ln -s $PRG $SBIN/sysctl ln -s $PRG $SBIN/tunefs ln -s $PRG $SBIN/umount ln -s $PRG $SBIN/zfs ln -s $PRG $SBIN/zpool chown -hR root:wheel $ROOTFS } build_image() { echo "+++ Build ELWIX RootFS image ..." makefs -s ${ROOTFS_SIZE} -o minfree=0 $REL/$ROOTFS_IMG $ROOTFS } install_image() { echo "+++ Install ELWIX RootFS Image into kernel ..." START=`strings -td $KERNEL | grep "MFS Filesystem" | cut -d ' ' -f 1 | head -1` STOP=`strings -td $KERNEL | grep "MFS Filesystem" | cut -d ' ' -f 1 | tail -1` STOP=$(($STOP + 1)) head -c $START $KERNEL >$NEWKERN cat $REL/$ROOTFS_IMG >>$NEWKERN tail -c +$STOP $KERNEL >>$NEWKERN cd $REL gzip -9 kernel cd - } ### main() if SnitVer ${WORLD}/elwix.ver; then clean_elwix prepare_elwix build_elwix build_rootdir install_rootfs build_image install_image else echo "Skipped ELWIX RootFS build ..." fi echo "+++ Complete build ELWIX RootFS"