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