#!/bin/ash
#
#
# We will ask udev to (re)handle kernel events
# so that 4MLinux could (re)configure some basic services.
#
#
# Requesting events from the kernel:
 udevadm trigger
 udevadm settle
#
#
# Making sure that USB host is ready:
 for i in ehci ohci uhci xhci; do
   modprobe $i-hcd 2>/dev/null
   modprobe $i-pci 2>/dev/null
 done
#
#
# Checking the /dev directory:
 mdev -s
 if [ ! -e /dev/bus/usb ]; then
   mkdir /dev/bus 2>/dev/null
   ln -s /sys/bus/usb /dev/bus/usb 2>/dev/null
 fi
 if [ ! -e /dev/dri ]; then
   ln -s /dev /dev/dri
 fi
 if [ ! -e /dev/input ]; then
   ln -s /dev /dev/input
 fi
 if [ ! -e /dev/snd ]; then
   ln -s /dev /dev/snd
 fi
#
#
# (Re)starting acpid:
 killall acpid 2>/dev/null
 sleep 0.5
 acpid
#
#
# Perhaps udev has switched on the GPU framebuffer?
# If so, the GPM daemon must have gone crazy. Restarting it:
 mouse >/dev/null 2>&1
#
#
# Sound mixer:
 alsactl restore -f /etc/asound.state 2>/dev/null
#
#
# Removable (USB?) disks:
 MOUNT_REMOVABLE_DISK=no
 if [ -e /etc/automount.conf ]; then
   . /etc/automount.conf
 fi
 if [ $MOUNT_REMOVABLE_DISK = yes ]; then
   mountall 2>/dev/null
 fi
#
#
# Dark monitor (with poor backlight) makes me crazy.
# Let's fix it:
 cd /sys/class/backlight
 for i in $(ls); do
   if [ -e $i/max_brightness ]; then
     if [ -e $i/brightness ]; then
       cat $i/max_brightness > $i/brightness
     fi
   fi
 done
#
#
# The Internet (DHCP Client):
 INTERFACE=ppp0
 if [ -e /etc/interface ]; then
   INTERFACE=$(cat /etc/interface)
 fi
 if [ ! $INTERFACE = ppp0 ]; then
   if [ ! -e /var/run/dhcp.pid ]; then
     connect >/dev/null 2>&1 &
   fi
 fi
