Annotation of elwix/config/etc/uboot/rc.init, revision 1.1.2.2

1.1.2.1   misho       1: #!/bin/sh
                      2: #
                      3: # Boot startup script for elwix :)
                      4: #
1.1.2.2 ! misho       5: # $Id: rc.init,v 1.1.2.1 2014/01/21 09:19:06 misho Exp $
1.1.2.1   misho       6: 
                      7: stty status '^T'
                      8: 
                      9: trap : 2
                     10: trap : 3
                     11: trap : 18
                     12: 
                     13: HOME=/root
                     14: PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin
                     15: TERM=xterm
                     16: BLOCKSIZE=1k
                     17: EDITOR=vi
                     18: PAGER=less
                     19: export HOME PATH TERM BLOCKSIZE EDITOR PAGER
                     20: 
                     21: SYSPKGDIR="/var/frm"
                     22: BOOTLOG="/var/run/elwix.boot"
                     23: 
                     24: MGMT_VLAN="4093"
                     25: MGMT_NAME="mgmt"
                     26: MGMT_ADDR="10.254.254.254/30"
                     27: 
                     28: umask 022
                     29: 
                     30: boot()
                     31: {
                     32:        echo "Check and mount filesystems ..."
                     33:        fsck -y 1>/dev/null 2>&1 && mount -a || fsck -f -y
                     34: 
                     35:        echo "Loading elwix firmware variables ..."
                     36:        cd /elwix/altroot
                     37:        pax -rw -pe var /
                     38:        chmod 1777 /var/tmp
                     39:        cd /
                     40: }
                     41: 
                     42: options()
                     43: {
                     44:        echo "Set firmware options ..." | tee -a $BOOTLOG
                     45:        [ -x /etc/sysctl.conf ] && /etc/sysctl.conf | tee -a $BOOTLOG
                     46: }
                     47: 
                     48: passwd()
                     49: {
                     50:        echo "Syncing password database ..." | tee -a $BOOTLOG
                     51:        pwd_mkdb /etc/master.passwd | tee -a $BOOTLOG 1>/dev/null 2>&1
                     52:        rm -f /etc/nologin
                     53: }
                     54: 
                     55: local()
                     56: {
                     57:        echo "Configurate localhost ..." | tee -a $BOOTLOG
                     58:        ifconfig lo0 127.0.0.1 | tee -a $BOOTLOG 1>/dev/null 2>&1
                     59:        hostname `cat /etc/myname`
                     60: }
                     61: 
                     62: geteth()
                     63: {
                     64:        ifconfig -a -u | awk '
                     65:                (match($0, "[:alpha:]*\: ") && match($2, "flags=")) { eth = substr($1, 1, index($1, ":") - 1); next; }; 
                     66:                (match($0, "media:\ Ethernet")) { printf("%s\n", eth); };
                     67:        ' | head -1
                     68: }
                     69: 
                     70: mgmt()
                     71: {
                     72:        [ -r /etc/mylan ] && VDEV=`cat /etc/mylan`
                     73:        if [ -x /usr/bin/get1steth ]; then
                     74:                VDEV=${VDEV:-`get1steth -g`}
                     75: 
                     76:                get1steth -v $VDEV | tee -a $BOOTLOG 1>/dev/null 2>&1
                     77:        else
                     78:                VDEV=${VDEV:-`geteth`}
                     79:                ifconfig $VDEV up
                     80:                ifconfig vlan$MGMT_VLAN create vlan $MGMT_VLAN vlandev $VDEV
                     81:                ifconfig vlan$MGMT_VLAN name $MGMT_NAME
                     82:                ifconfig $MGMT_NAME inet $MGMT_ADDR
                     83:        fi
                     84: 
                     85:        echo "Configurete management interface to ($VDEV) ..." | tee -a $BOOTLOG
                     86: }
                     87: 
                     88: syspkg()
                     89: {
                     90:        echo "Setup elwix dynamic link libraries ..."
                     91:        ldconfig /etc/ld.so.conf
                     92: 
                     93:        echo "Mounting firmware system packages:" | tee -a $BOOTLOG
                     94: # Raw images
                     95:        for i in /elwix/cf/*-pkg.frm; do
                     96:                if [ -r $i ]; then
                     97:                        MDDEV=$(mdconfig -a -t vnode -f $i);
                     98:                        install -d $SYSPKGDIR/$MDDEV;
                     99:                        mount -r /dev/$MDDEV $SYSPKGDIR/$MDDEV | tee -a $BOOTLOG 1>/dev/null 2>&1;
                    100:                        if [ $? -ne 0 ]; then
                    101:                                mdconfig -d -u $MDDEV;
                    102:                                echo "Failed mount system package $i ... Corrupted!" | tee -a $BOOTLOG;
                    103:                                continue
                    104:                        else
                    105:                                echo "Added firmware system package ... $i($?)" | tee -a $BOOTLOG;
                    106:                                PATH=$PATH:$SYSPKGDIR/$MDDEV/bin:$SYSPKGDIR/$MDDEV/sbin
                    107:                                export PATH
                    108: 
                    109:                                [ -d $SYSPKGDIR/$MDDEV/lib ] && ldconfig -v -m $SYSPKGDIR/$MDDEV/lib | \
                    110:                                                                        tee -a $BOOTLOG 1>/dev/null 2>&1;
                    111: 
                    112:                                [ -x $SYSPKGDIR/$MDDEV/.pkg2sys ] && $SYSPKGDIR/$MDDEV/.pkg2sys;
                    113:                        fi
                    114:                fi
                    115:        done
                    116: # UZIP images
                    117:        for i in /elwix/cf/*-pkg.frz; do
                    118:                if [ -r $i ]; then
                    119:                        MDDEV=$(mdconfig -a -t vnode -f $i);
                    120:                        install -d $SYSPKGDIR/$MDDEV;
                    121:                        mount -r /dev/$MDDEV.uzip $SYSPKGDIR/$MDDEV | tee -a $BOOTLOG 1>/dev/null 2>&1;
                    122:                        if [ $? -ne 0 ]; then
                    123:                                mdconfig -d -u $MDDEV;
                    124:                                echo "Failed mount system package $i ... Corrupted!" | tee -a $BOOTLOG;
                    125:                                continue
                    126:                        else
                    127:                                echo "Added firmware system package ... $i($?)" | tee -a $BOOTLOG;
                    128:                                PATH=$PATH:$SYSPKGDIR/$MDDEV/bin:$SYSPKGDIR/$MDDEV/sbin
                    129:                                export PATH
                    130: 
                    131:                                [ -d $SYSPKGDIR/$MDDEV/lib ] && ldconfig -v -m $SYSPKGDIR/$MDDEV/lib | \
                    132:                                                                        tee -a $BOOTLOG 1>/dev/null 2>&1;
                    133: 
                    134:                                [ -x $SYSPKGDIR/$MDDEV/.pkg2sys ] && $SYSPKGDIR/$MDDEV/.pkg2sys;
                    135:                        fi
                    136:                fi
                    137:        done
                    138: }
                    139: 
                    140: service()
                    141: {
                    142:        echo "Starting distribution static services:" | tee -a $BOOTLOG
                    143:        for i in /etc/rc.d/*.run; do
                    144:                if [ -x $i ]; then
                    145:                        $i
                    146:                fi
                    147:        done
                    148: 
                    149:        if [ -d /etc/rc.S ]; then
                    150:                echo "Select boot service directory ..." `readlink /etc/rc.S` | tee -a $BOOTLOG
                    151: 
                    152:                echo "Starting distribution services:" | tee -a $BOOTLOG
                    153:                for i in /etc/rc.S/*.run; do
                    154:                        if [ -x $i ]; then
                    155:                                $i
                    156:                        fi
                    157:                done
                    158:        fi
                    159: }
                    160: 
                    161: #
                    162: ## main()
                    163: #
                    164: 
                    165: boot
                    166: echo "elwix>>> Start system boot stage at `date`" | tee $BOOTLOG
                    167: options
                    168: passwd
                    169: local
                    170: mgmt
                    171: syspkg
                    172: service
                    173: echo "elwix>>> Start local services:" | tee -a $BOOTLOG
                    174: [ -r /etc/rc.local ] && . /etc/rc.local
                    175: echo "elwix>>> Done." | tee -a $BOOTLOG

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