#!/bin/sh
export PATH=/bin:/sbin:/usr/bin:/usr/sbin

echo "Starting SMLinux..."

mount -t proc proc /proc
mount -t sysfs sysfs /sys

mount -v -n -t tmpfs tmpfs /run -o mode=0755

if which udevd > /dev/null 2>&1 ; then
	udevd --daemon
	udevadm trigger --action=add --type=subsystems
	udevadm trigger --action=add --type=devices
	udevadm trigger --action=change --type=devices
	udevadm settle
else
	echo /sbin/mdev > /proc/sys/kernel/hotplug
	mdev -s
fi

[ -e /dev/rtc0 ] && hwclock -u -s

echo "Mounting root device read-only."
mount -o ro,remount /

echo "Running fsck on root file system."
fsck -V -C -A -p
mkdir -p /dev/shm /dev/pts

echo "Mounting root device read-write."
mount -v -o remount,rw /

rm -f /etc/mtab{,-,.tmp} && touch /etc/mtab

# Add entry for / to /etc/mtab:
mount -f -w /

echo "Mounting non-root local file system."
mount -a

# Clean up some temporary files:
rm -f /var/run/* /var/run/*/* /var/run/*/*/* /etc/nologin \
  /tmp/.XAuth* 1> /dev/null 2>/dev/null
  ( cd /var/log/setup/tmp && rm -rf * )
rm -f /var/lock/* /tmp/.X*lock /tmp/.X11-unix/* 2> /dev/null

hostname $(cat /etc/hostname)
ifconfig lo up

[ -f /etc/random-seed ] && cat /etc/random-seed >/dev/urandom
dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2>/dev/null

echo "Logging dmesg output to /var/log/dmesg"
dmesg > /var/log/dmesg.log

ulimit -c unlimited

for i in /etc/rc.d/rc.modules \
	 /etc/rc.d/rc.gtk \
	 /etc/rc.d/rc.network \
	 /etc/rc.d/rc.local ;
    do [ -x "$i" ] && "$i" ; done

[ -x /bin/haveged ] && /bin/haveged -w 1024
[ -x /bin/crond ] && /bin/crond -S
[ -x /etc/rc.d/rc.messagebus ] && /etc/rc.d/rc.messagebus start
