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