Annotation of elwix/build_rootfs.sh, revision 1.2

1.1       misho       1: #!/bin/sh
                      2: #
                      3: # ELWIX build script for rootfs firmware
                      4: #
                      5: # (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
                      6: #    by Michael Pounov <misho@elwix.org>
                      7: #
1.2     ! misho       8: # $Id: build_rootfs.sh,v 1.1.1.1.2.3 2011/09/25 19:18:07 misho Exp $
1.1       misho       9: #
                     10: 
                     11: [ -r ./config/rc.elwix ] && . ./config/rc.elwix
                     12: if [ X"${ELWIX_IS_CONFIGURED}" != X"YES" ]; then
                     13:        echo
                     14:        echo "ELWIX project is not configured !?!"
                     15:        echo
                     16:        exit 1
                     17: fi
                     18: 
                     19: if [ ! -d ${BSDSRC} ]; then
                     20:        echo
                     21:        echo "ELWIX project is not configured - missing BSD sources !?!"
                     22:        echo
                     23:        exit 1
                     24: fi
                     25: 
                     26: if [ "${USER}" != "root" ]; then
                     27:        echo
                     28:        echo "ELWIX project is not configured - RootFS must build under root !?!"
                     29:        echo
                     30:        exit 1
                     31: fi
                     32: 
                     33: NEWKERN="${REL}/kernel"
                     34: 
                     35: clean_elwix()
                     36: {
                     37:        echo "+++ Clean csh from ELWIX World ..."
                     38:        rm -rf ${BSDOBJ}/usr/src/bin/csh/*
                     39: 
                     40:        echo "+++ Clean ELWIX RootFS firmware ..."
                     41:        rm -rf $MKDIR
                     42:        mkdir $MKDIR
                     43: 
                     44:        echo "+++ Clean RootFS directory ..."
                     45:        rm -rf $ROOTFS
                     46:        mkdir $ROOTFS
                     47: 
                     48:        echo "+++ Clean Release directory ..."
                     49:        rm -rf $REL/$ROOTFS_IMG ${NEWKERN}*
                     50: }
                     51: 
                     52: prepare_elwix()
                     53: {
                     54:        echo "+++ Prepair ELWIX RootFS firmware ..."
                     55:        cd $MKDIR
                     56:        cat >$MKH <<_EOF
                     57: # Auto-generated Makefile include for crungegen
                     58: # !!! Dont edit by hand !!!
                     59: #
                     60: #BUILDOPTS += TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ}
                     61: CRUNCH_SUPPRESS_LINK_-sh= 1
                     62: CRUNCH_SUPPRESS_LINK_-csh= 1
                     63: CRUNCH_SUPPRESS_LINK_-tcsh= 1
                     64: LIBS += -L${WORLD}/lib -L${WORLD}/usr/lib
                     65: _EOF
                     66:        cat >$ROOTFS_CONF <<_EOF
                     67: srcdirs ${BSDSRC}/bin ${BSDSRC}/sbin ${BSDSRC}/libexec ${BSDSRC}/cddl/sbin ${BSDSRC}/sbin/ggate
                     68: #buildopts -DRESCUE CRUNCH_CFLAGS=-DRESCUE TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ}
                     69: buildopts TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} MAKEOBJDIRPREFIX=${BSDOBJ}
                     70: _EOF
                     71:        cat $CFGDIR/$ROOTFS_CONF >>$ROOTFS_CONF
                     72: 
                     73:        crunchgen -f -p $BSDOBJ -h $MKDIR/$MKH -m $MKF -c elwix.c -e elwix $ROOTFS_CONF
                     74:        cd -
                     75: }
                     76: 
                     77: build_elwix()
                     78: {
                     79:        echo "+++ Build ELWIX RootFS firmware ..."
                     80:        cd $MKDIR
                     81:        make -f $MKF clean
                     82:        make -f $MKF
                     83:        cd -
                     84: }
                     85: 
                     86: build_rootdir()
                     87: {
                     88:        echo "+++ Build RootFS directory ..."
                     89:        cd $ROOTFS
                     90: 
                     91:        install -d bin;
                     92:        install -d dev;
                     93:        install -d elwix;
                     94:        install -d elwix/etc;
                     95:        install -d mnt;
                     96:        install -d -m 0555 proc;
                     97:        install -d sbin;
                     98:        install -d system;
                     99:        install -d -m 1777 tmp;
                    100:        install -d usr;
                    101:        install -d var;
                    102: 
                    103:        ln -fs /usr/lib lib;
                    104:        ln -fs /usr/libexec libexec;
                    105: 
                    106:        ln -fs /elwix/etc etc;
                    107:        ln -fs /elwix/exports exports;
                    108:        ln -fs /elwix/home home;
                    109:        ln -fs /elwix/root root;
                    110:        ln -fs /elwix/tftpboot tftpboot;
                    111: 
                    112:        cd -
                    113: }
                    114: 
                    115: install_rootfs()
                    116: {
                    117:        PRG="/sbin/elwix"
                    118:        BIN="${ROOTFS}/bin"
                    119:        SBIN="${ROOTFS}/sbin"
                    120:        ETC="${ROOTFS}/elwix/etc"
                    121: 
                    122:        echo "+++ Install ELWIX into RootFS directory ..."
                    123:        install $MKDIR/elwix $SBIN
                    124: 
                    125:        InstallList ${ELWIX_ROOTFS} ${WORLD} ${ROOTFS}
                    126: 
1.2     ! misho     127:        InstallDir ${ROOTFS_ETC} $ETC
1.1       misho     128: 
                    129:        ln -s /usr/sbin/nologin $SBIN
                    130: 
                    131:        ln -s $PRG $BIN/test
                    132:        ln -s $PRG $BIN/\[
                    133:        ln -s $PRG $BIN/cat
                    134:        ln -s $PRG $BIN/chflags
                    135:        ln -s $PRG $BIN/chio
                    136:        ln -s $PRG $BIN/chmod
                    137:        ln -s $PRG $BIN/cp
1.2     ! misho     138: #      ln -s $PRG $BIN/csh
        !           139: #      ln -s $PRG $BIN/tcsh
        !           140:        ln -s /bin/tcsh $BIN/-tcsh
        !           141:        ln -s /bin/csh $BIN/-csh
1.1       misho     142:        ln -s $PRG $BIN/date
                    143:        ln -s $PRG $BIN/dd
                    144:        ln -s $PRG $BIN/df
                    145:        ln -s $PRG $BIN/domainname
                    146:        ln -s $PRG $BIN/echo
                    147:        ln -s $PRG $BIN/expr
                    148:        ln -s $PRG $BIN/getfacl
                    149:        ln -s $PRG $BIN/hostname
                    150:        ln -s $PRG $BIN/kenv
                    151:        ln -s $PRG $BIN/kill
                    152:        ln -s $PRG $BIN/ln
                    153:        ln -s $PRG $BIN/link
                    154:        ln -s $PRG $BIN/ls
                    155:        ln -s $PRG $BIN/mkdir
                    156:        ln -s $PRG $BIN/mv
                    157:        ln -s $PRG $BIN/pax
                    158:        ln -s $PRG $BIN/pkill
                    159:        ln -s $PRG $BIN/pgrep
                    160:        ln -s $PRG $BIN/sh
                    161:        ln -s $PRG $BIN/-sh
                    162:        ln -s $PRG $BIN/ps
                    163:        ln -s $PRG $BIN/pwait
                    164:        ln -s $PRG $BIN/pwd
                    165:        ln -s $PRG $BIN/realpath
                    166:        ln -s $PRG $BIN/rm
                    167:        ln -s $PRG $BIN/unlink
                    168:        ln -s $PRG $BIN/rmdir
                    169:        ln -s $PRG $BIN/setfacl
                    170:        ln -s $PRG $BIN/sleep
                    171:        ln -s $PRG $BIN/stty
                    172:        ln -s $PRG $BIN/sync
                    173:        ln -s $PRG $BIN/uuidgen
                    174: 
                    175:        ln -s $PRG $SBIN/adjkerntz
                    176:        ln -s $PRG $SBIN/atacontrol
                    177:        ln -s $PRG $SBIN/badsect
                    178:        ln -s $PRG $SBIN/bsdlabel
                    179:        ln -s $PRG $SBIN/disklabel
                    180:        ln -s $PRG $SBIN/camcontrol
                    181:        ln -s $PRG $SBIN/ccdconfig
                    182:        ln -s $PRG $SBIN/comcontrol
                    183:        ln -s $PRG $SBIN/conscontrol
                    184:        ln -s $PRG $SBIN/devfs
                    185:        ln -s $PRG $SBIN/dhclient
                    186:        ln -s $PRG $SBIN/dmesg
                    187:        ln -s $PRG $SBIN/dump
                    188:        ln -s $PRG $SBIN/rdump
                    189:        ln -s $PRG $SBIN/dumpfs
                    190:        ln -s $PRG $SBIN/dumpon
                    191:        ln -s $PRG $SBIN/fdisk
                    192:        ln -s $PRG $SBIN/ffsinfo
                    193:        ln -s $PRG $SBIN/fsck
                    194:        ln -s $PRG $SBIN/fsck_ffs
                    195:        ln -s $PRG $SBIN/fsck_ufs
                    196:        ln -s $PRG $SBIN/fsck_4.2bsd
                    197:        ln -s $PRG $SBIN/fsck_msdosfs
                    198:        ln -s $PRG $SBIN/gbde
                    199:        ln -s $PRG $SBIN/ggatec
                    200:        ln -s $PRG $SBIN/ggated
                    201:        ln -s $PRG $SBIN/ggatel
                    202:        ln -s $PRG $SBIN/-geom
                    203:        ln -s $PRG $SBIN/glabel
                    204:        ln -s $PRG $SBIN/gpart
                    205:        ln -s $PRG $SBIN/growfs
                    206:        ln -s $PRG $SBIN/hastctl
                    207:        ln -s $PRG $SBIN/hastd
                    208:        ln -s $PRG $SBIN/ifconfig
                    209:        ln -s $PRG $SBIN/init
                    210:        ln -s $PRG $SBIN/ipfw
                    211:        ln -s $PRG $SBIN/iscontrol
                    212:        ln -s $PRG $SBIN/kldconfig
                    213:        ln -s $PRG $SBIN/kldload
                    214:        ln -s $PRG $SBIN/kldstat
                    215:        ln -s $PRG $SBIN/kldunload
                    216:        ln -s $PRG $SBIN/ldconfig
                    217:        ln -s $PRG $SBIN/md5
                    218:        ln -s $PRG $SBIN/sha1
                    219:        ln -s $PRG $SBIN/sha256
                    220:        ln -s $PRG $SBIN/rmd160
                    221:        ln -s $PRG $SBIN/mdconfig
                    222:        ln -s $PRG $SBIN/mdmfs
                    223:        ln -s $PRG $SBIN/mount_mfs
                    224:        ln -s $PRG $SBIN/mknod
                    225:        ln -s $PRG $SBIN/mksnap_ffs
                    226:        ln -s $PRG $SBIN/mount
                    227:        ln -s $PRG $SBIN/mount_cd9660
                    228:        ln -s $PRG $SBIN/mount_msdosfs
                    229:        ln -s $PRG $SBIN/mount_nfs
                    230:        ln -s $PRG $SBIN/mount_ntfs
                    231:        ln -s $PRG $SBIN/mount_nullfs
                    232:        ln -s $PRG $SBIN/mount_udf
                    233:        ln -s $PRG $SBIN/mount_unionfs
                    234:        ln -s $PRG $SBIN/natd
                    235:        ln -s $PRG $SBIN/newfs
                    236:        ln -s $PRG $SBIN/newfs_msdos
                    237:        ln -s $PRG $SBIN/nfsiod
                    238:        ln -s $PRG $SBIN/nos-tun
                    239:        ln -s $PRG $SBIN/pfctl
                    240:        ln -s $PRG $SBIN/pflogd
                    241:        ln -s $PRG $SBIN/ping
                    242:        ln -s $PRG $SBIN/ping6
                    243:        ln -s $PRG $SBIN/quotacheck
                    244:        ln -s $PRG $SBIN/reboot
                    245:        ln -s $PRG $SBIN/halt
                    246:        ln -s $PRG $SBIN/fastboot
                    247:        ln -s $PRG $SBIN/fasthalt
                    248:        ln -s $PRG $SBIN/recoverdisk
                    249:        ln -s $PRG $SBIN/restore
                    250:        ln -s $PRG $SBIN/rrestore
                    251:        ln -s $PRG $SBIN/route
                    252:        ln -s $PRG $SBIN/rtsol
                    253:        ln -s $PRG $SBIN/savecore
                    254:        ln -s $PRG $SBIN/setkey
                    255:        ln -s $PRG $SBIN/shutdown
                    256:        ln -s $PRG $SBIN/spppcontrol
                    257:        ln -s $PRG $SBIN/swapon
                    258:        ln -s $PRG $SBIN/swapoff
                    259:        ln -s $PRG $SBIN/swapctl
                    260:        ln -s $PRG $SBIN/sysctl
                    261:        ln -s $PRG $SBIN/tunefs
                    262:        ln -s $PRG $SBIN/umount
                    263:        ln -s $PRG $SBIN/zfs
                    264:        ln -s $PRG $SBIN/zpool
                    265: 
                    266:        chown -hR root:wheel $ROOTFS
                    267: }
                    268: 
                    269: build_image()
                    270: {
                    271:        echo "+++ Build ELWIX RootFS image ..."
                    272:        makefs -s ${ROOTFS_SIZE} -o minfree=0 $REL/$ROOTFS_IMG $ROOTFS
                    273: }
                    274: 
                    275: install_image()
                    276: {
                    277:        echo "+++ Install ELWIX RootFS Image into kernel ..."
                    278:        START=`strings -td $KERNEL | grep "MFS Filesystem" | cut -d ' ' -f 1 | head -1`
                    279:        STOP=`strings -td $KERNEL | grep "MFS Filesystem" | cut -d ' ' -f 1 | tail -1`
                    280:        STOP=$(($STOP + 1))
                    281: 
                    282:        head -c $START $KERNEL >$NEWKERN
                    283:        cat $REL/$ROOTFS_IMG >>$NEWKERN
                    284:        tail -c +$STOP $KERNEL >>$NEWKERN
                    285: 
                    286:        cd $REL
                    287:        gzip -9 kernel
                    288:        cd -
                    289: }
                    290: 
                    291: ### main()
                    292: if SnitVer ${WORLD}/elwix.ver; then
                    293:        clean_elwix
                    294:        prepare_elwix
                    295:        build_elwix
                    296: 
                    297:        build_rootdir
                    298:        install_rootfs
                    299: 
                    300:        build_image
                    301:        install_image
                    302: else
                    303:        echo "Skipped ELWIX RootFS build ..."
                    304: fi
                    305: 
                    306: echo "+++ Complete build ELWIX RootFS"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>