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

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

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