197 lines
5.4 KiB
Bash
Executable File
197 lines
5.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# Start basic services
|
|
|
|
set -u
|
|
|
|
NVDIFF='/nvram/bewan/router.diff'
|
|
NVMAGIC='/nvram/bewan/router.magic'
|
|
DEFFILE='/etc/bewan/config.default/router.conf'
|
|
|
|
# Set date to 1st january 2010
|
|
# This initial date is updated later by base_time package (S000-init-time)
|
|
date 010100002010
|
|
|
|
# Mount file systems if not already mounted by BSP startup
|
|
test -z "$(mount -t proc)" && mount -t proc proc /proc
|
|
test -z "$(mount -t sysfs)" && mount -t sysfs sysfs /sys
|
|
test -z "$(mount -t tmpfs | grep /var)" && mount -t tmpfs -o size=8M shm /var
|
|
mkdir -p /var/bewan
|
|
|
|
# Create /dev in ram
|
|
test -z "$(mount -t tmpfs | grep /dev)" && mount -t tmpfs -o size=128k shm /dev
|
|
|
|
# Start mdev if not already done by BSP startup
|
|
if test -z $(cat /proc/sys/kernel/hotplug | grep mdev); then
|
|
cat /etc/bewan/mdev/* > /var/bewan/mdev.conf
|
|
echo "/sbin/mdev" > /proc/sys/kernel/hotplug
|
|
mdev -s
|
|
fi
|
|
|
|
mkdir -p /dev/pts
|
|
test -z "$(mount -t devpts)" && mount -t devpts -o mode=620,gid=5 devpts /dev/pts
|
|
|
|
# Create /var directories
|
|
mkdir -p /var/tmp
|
|
mkdir -p /var/mnt
|
|
mkdir -p /var/run
|
|
mkdir -p /var/log
|
|
mkdir -p /var/bewan
|
|
mkdir -p /var/bewan/lib
|
|
mkdir -p /var/bewan/log
|
|
mkdir -p /var/bewan/tmp
|
|
mkdir -p /var/bewan/lock
|
|
mkdir -p /var/bewan/inittab.d
|
|
mkdir -p /var/bewan/lib/hotplug/storage
|
|
|
|
# Ram symbolic links to /etc
|
|
touch /var/bewan/passwd
|
|
touch /var/bewan/fstab
|
|
touch /var/bewan/inittab
|
|
|
|
touch /var/run/rcrunning
|
|
|
|
cat /etc/bewan/motd >/dev/console
|
|
|
|
ifconfig lo 127.0.0.1
|
|
route add -net 127.0.0.0 netmask 255.0.0.0 lo
|
|
|
|
# Mount config filesystem on nvram directory
|
|
. /etc/bewan/lib/config
|
|
config_mtd_mount
|
|
|
|
# Mount other partition
|
|
# If config partition is called Nvlog, mount it as a JFFS2 filesystem
|
|
cat /proc/mtd | grep Nvlog >/dev/null
|
|
if [ $? = 0 ]; then
|
|
device=$(cat /proc/mtd | grep Nvlog | cut -d ':' -f 1 | sed -e "s/mtd//")
|
|
mount -t jffs2 -o rw /dev/mtdblock$device /nvlog
|
|
if [ $? != 0 ]; then
|
|
# If mount failed, try format it, then remount
|
|
flash_erase /dev/mtd$device 0 0
|
|
mount -t jffs2 -o rw /dev/mtdblock$device /nvlog
|
|
fi
|
|
fi
|
|
|
|
RESET=0
|
|
# Check factory reset button
|
|
grep bewan_reset_fdp /proc/cmdline >/dev/null
|
|
[ $? = 0 ] && RESET=1
|
|
|
|
# Sanity check on router.diff in flash
|
|
if [ ! -f $NVDIFF ]; then
|
|
RESET=1
|
|
fi
|
|
|
|
# Restore factory configuration
|
|
if [ $RESET = 1 ]; then
|
|
echo "Restoring default configuration" >/dev/console
|
|
config_mtd_write
|
|
rm -f $NVDIFF $NVMAGIC
|
|
config_mtd_erase
|
|
fi
|
|
|
|
# --------------------------------------------------
|
|
# Configuration system version 2 with configd daemon
|
|
# --------------------------------------------------
|
|
if which configd >/dev/null; then
|
|
# We just need to start configd through inittab
|
|
echo '/dev/null::respawn:/sbin/configd' >> /etc/inittab
|
|
kill -HUP 1
|
|
# Wait until daemon is initialized
|
|
while [ ! -f '/var/run/configd.pid' ]; do usleep 500000; done
|
|
|
|
# ---------------------------------------------
|
|
# Configuration system version 1 with configlib
|
|
# ---------------------------------------------
|
|
else
|
|
# Files used by configuration system version 1
|
|
FACTORY='/var/bewan/factory.conf'
|
|
CNFFILE='/var/bewan/router.conf'
|
|
WRKFILE='/var/bewan/working.conf'
|
|
|
|
# Factory default parameters
|
|
. $DEFFILE
|
|
|
|
# Build an expanded version of the factory profile in ramdisk
|
|
cp $DEFFILE $CNFFILE
|
|
echo fbuild | cli -q
|
|
mv $WRKFILE $FACTORY
|
|
|
|
# Rebuild the full current config file
|
|
if [ -f $NVDIFF ]; then
|
|
# Rebuild config profile from /nvram/bewan/router.diff
|
|
echo 'Build router.conf from nvram router.diff' >/dev/console
|
|
confpatch $FACTORY $NVDIFF $CNFFILE
|
|
echo fbuild | cli -q
|
|
else
|
|
# Rebuild config profile from factory
|
|
echo 'Build router.conf from factory' >/dev/console
|
|
cp $DEFFILE $CNFFILE
|
|
echo fbuild | cli -q
|
|
RESET=1
|
|
fi
|
|
cp -f $WRKFILE $CNFFILE
|
|
fi
|
|
|
|
# Initialize working variables
|
|
. /etc/bewan/init.d/setparam
|
|
ARG=start
|
|
|
|
# Factory initializations such as...
|
|
# WiFi SSID, TR-069 login/password, UUIDs...
|
|
if [ $RESET = 1 ]; then
|
|
DO_COMMIT=0
|
|
for script in `find /etc/bewan/factory.d -follow -type f | sort`; do
|
|
DO_COMMIT=1
|
|
. $script
|
|
done
|
|
if [ $DO_COMMIT = 1 ]; then
|
|
# Commit changes
|
|
echo 'fcommit' | cli -q
|
|
# Reload configuration parameters
|
|
PARAM_LOADED=0
|
|
base_load_param
|
|
fi
|
|
fi
|
|
|
|
# Potentially modify old config parameters when the firmware is upgraded
|
|
if [ -f $INITD/update-config ]; then
|
|
base_call_initd 'update-config'
|
|
fi
|
|
|
|
echo 1 >/proc/sys/net/ipv4/tcp_syncookies
|
|
# mcast needs rp filter to be turned off only for non default iface
|
|
# The value 2 works too, and prevent a DHCP offer packet received on wan2 to be routed on default route
|
|
echo 2 >/proc/sys/net/ipv4/conf/all/rp_filter
|
|
echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
|
|
|
|
[ -f /proc/sys/net/ipv4/conf/default/rp_filter ] && echo 2 >/proc/sys/net/ipv4/conf/default/rp_filter
|
|
[ -f /proc/sys/net/ipv4/conf/default/arp_ignore ] && echo 1 >/proc/sys/net/ipv4/conf/default/arp_ignore
|
|
|
|
# Set hostname
|
|
hostname $Device_Hostname
|
|
|
|
# Take onchange mutex (used by configd, adsl-up...)
|
|
base_enter_critical 'onchange'
|
|
|
|
# Execute startup scripts
|
|
for script in `find /etc/bewan/rc.d -follow -type f | sort`; do
|
|
. $script
|
|
done
|
|
|
|
# Add console prompt to inittab
|
|
if [ $Device_Console_Enable = 1 ]; then
|
|
echo 'ttyS'${Device_Console_Index:-0}'::askfirst:-'${Device_Console_Shell:-/bin/ash} > $ITABD/console
|
|
fi
|
|
|
|
base_call_initd 'inittab'
|
|
|
|
# Release onchange mutex
|
|
base_exit_critical 'onchange'
|
|
|
|
touch $RC2RUNNING
|
|
start-stop-daemon -S -b -x /etc/bewan/rc2
|
|
base_log "bewan rc complete" notice
|
|
rm $RCRUNNING
|
|
exit 0
|