#!/bin/sh
#
# Boot startup script for elwix :)
#
# $Id: rc.init,v 1.1.1.1.6.4 2012/10/10 14:29:11 misho Exp $
stty status '^T'
trap : 2
trap : 3
trap : 18
HOME=/root
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/local/bin:/usr/local/sbin
TERM=xterm
BLOCKSIZE=1k
EDITOR=vi
PAGER=less
export HOME PATH TERM BLOCKSIZE EDITOR PAGER
SYSPKGDIR="/var/sys"
BOOTLOG="/var/run/elwix.boot"
XML="/etc/config.xml"
MGMT_VLAN="4093"
MGMT_NAME="mgmt"
MGMT_ADDR="10.254.254.254/30"
umask 022
boot()
{
echo "Check and mount filesystems ..."
fsck -y 1>/dev/null 2>&1 && mount -a || fsck -f -y
echo "Loading elwix firmware variables ..."
cd /elwix/altroot
pax -rw -pe var /
chmod 1777 /var/tmp
cd /
}
options()
{
echo "Set firmware options ..." | tee -a $BOOTLOG
[ -x /etc/sysctl.conf ] && /etc/sysctl.conf | tee -a $BOOTLOG
}
passwd()
{
echo "Syncing password database ..." | tee -a $BOOTLOG
pwd_mkdb /etc/master.passwd | tee -a $BOOTLOG 1>/dev/null 2>&1
rm -f /etc/nologin
}
local()
{
echo "Configurate localhost ..." | tee -a $BOOTLOG
ifconfig lo0 127.0.0.1 | tee -a $BOOTLOG 1>/dev/null 2>&1
hostname `cat /etc/myname`
if [ -x /usr/bin/xmler ]; then
hostname `xmler -g /elwix/system/hostname $XML`
domainname `xmler -g /elwix/system/domain $XML`
fi
}
geteth()
{
ifconfig -a -u | awk '
(match($0, "[:alpha:]*\: ") && match($2, "flags=")) { eth = substr($1, 1, index($1, ":") - 1); next; };
(match($0, "media:\ Ethernet")) { printf("%s\n", eth); };
' | head -1
}
mgmt()
{
[ -r /etc/mylan ] && VDEV=`cat /etc/mylan`
if [ -x /usr/bin/get1steth ]; then
VDEV=${VDEV:-`get1steth -g`}
get1steth -v $VDEV | tee -a $BOOTLOG 1>/dev/null 2>&1
else
VDEV=${VDEV:-`geteth`}
ifconfig vlan$MGMT_VLAN create vlan $MGMT_VLAN vlandev $VDEV
ifconfig vlan$MGMT_VLAN name $MGMT_NAME
ifconfig $MGMT_NAME inet $MGMT_ADDR
fi
echo "Configurete management interface to ($VDEV) ..." | tee -a $BOOTLOG
}
syspkg()
{
echo "Setup elwix dynamic link libraries ..."
ldconfig /etc/ld.so.conf
echo "Mounting firmware system packages:" | tee -a $BOOTLOG
# Raw images
for i in /elwix/cf/*-pkg.fw; do
if [ -r $i ]; then
MDDEV=$(mdconfig -a -t vnode -f $i);
install -d $SYSPKGDIR/$MDDEV;
mount -r /dev/$MDDEV $SYSPKGDIR/$MDDEV | tee -a $BOOTLOG 1>/dev/null 2>&1;
if [ $? -ne 0 ]; then
mdconfig -d -u $MDDEV;
echo "Failed mount system package $i ... Corrupted!" | tee -a $BOOTLOG;
continue
else
echo "Added firmware system package ... $i($?)" | tee -a $BOOTLOG;
PATH=$PATH:$SYSPKGDIR/$MDDEV/bin:$SYSPKGDIR/$MDDEV/sbin
export PATH
[ -d $SYSPKGDIR/$MDDEV/lib ] && ldconfig -v -m $SYSPKGDIR/$MDDEV/lib | \
tee -a $BOOTLOG 1>/dev/null 2>&1;
[ -x $SYSPKGDIR/$MDDEV/.pkg2sys ] && $SYSPKGDIR/$MDDEV/.pkg2sys;
fi
fi
done
# UZIP images
for i in /elwix/cf/*-pkg.fwz; do
if [ -r $i ]; then
MDDEV=$(mdconfig -a -t vnode -f $i);
install -d $SYSPKGDIR/$MDDEV;
mount -r /dev/$MDDEV.uzip $SYSPKGDIR/$MDDEV | tee -a $BOOTLOG 1>/dev/null 2>&1;
if [ $? -ne 0 ]; then
mdconfig -d -u $MDDEV;
echo "Failed mount system package $i ... Corrupted!" | tee -a $BOOTLOG;
continue
else
echo "Added firmware system package ... $i($?)" | tee -a $BOOTLOG;
PATH=$PATH:$SYSPKGDIR/$MDDEV/bin:$SYSPKGDIR/$MDDEV/sbin
export PATH
[ -d $SYSPKGDIR/$MDDEV/lib ] && ldconfig -v -m $SYSPKGDIR/$MDDEV/lib | \
tee -a $BOOTLOG 1>/dev/null 2>&1;
[ -x $SYSPKGDIR/$MDDEV/.pkg2sys ] && $SYSPKGDIR/$MDDEV/.pkg2sys;
fi
fi
done
}
service()
{
echo "Starting distribution static services:" | tee -a $BOOTLOG
for i in /etc/rc.d/*.run; do
if [ -x $i ]; then
$i
fi
done
if [ -d /etc/rc.S ]; then
echo "Select boot service directory ..." `readlink /etc/rc.S` | tee -a $BOOTLOG
echo "Starting distribution services:" | tee -a $BOOTLOG
for i in /etc/rc.S/*.run; do
if [ -x $i ]; then
$i
fi
done
fi
}
#
## main()
#
boot
echo "elwix>>> Start system boot stage at `date`" | tee $BOOTLOG
options
passwd
local
mgmt
syspkg
service
echo "elwix>>> Start local services:" | tee -a $BOOTLOG
[ -r /etc/rc.local ] && . /etc/rc.local
echo "elwix>>> Done." | tee -a $BOOTLOG
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>