#!/bin/sh
#
# Boot startup script for elwix :)
#
# $Id: rc.init,v 1.7 2021/03/11 13:59:50 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
CFDIR="/elwix/cf"
SYSPKGDIR="/var/frm"
BOOTLOG="/var/run/elwix.boot"
MGMT_VLAN="4093"
MGMT_NAME="mgmt"
MGMT_ADDR="10.254.254.254/30"
umask 022
boot()
{
echo "Loading ELWIX configz ..."
cd /elwix/altroot
pax -rw -pe var /
chmod 1777 /var/tmp
mount -ttmpfs tmpfs /var/db/pkg
cd /
}
restore_uboot()
{
echo "Restore configz from NAND ..."
/etc/rc.cfg load /etc
}
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 inet 127.0.0.1 netmask 255.0.0.0 | tee -a $BOOTLOG 1>/dev/null 2>&1
hostname `cat /etc/myname`
}
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 $VDEV up
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 ${CFDIR}/*-pkg.frm; 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 ${CFDIR}/*-pkg.frz; 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
restore_uboot
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>