#!/bin/bash
# Description: Launch diverses Mandrake Scripts on boot.
# (c) MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com>
# 	$Id: mandrake_everytime,v 1.20 2004/02/27 19:27:48 flepied Exp $	

. /etc/rc.d/init.d/functions

[ -e /etc/sysconfig/system ] && . /etc/sysconfig/system

# Disabling supermount if not here
if [[ $(uname -m) != sparc*  ]];then
    if grep -q '^\/.*supermount.*' /etc/fstab && \
	! grep -q '[[:space:]]supermount$' /proc/filesystems  && \
	! modprobe -n supermount >/dev/null 2>/dev/null && [ -x /usr/bin/perl ];then
	action "Disabling Supermount" /usr/sbin/supermount -i disable
    fi
fi

# setup eth* (without configuring it) interfaces before the
# hotplug/pcmcia started so we are sure that what we have configured
# in /etc/modules.conf get the device we have affected.
if [ -n "$(/sbin/modprobe -c)" ]; then
    oldhotplug=`sysctl kernel.hotplug  2>/dev/null | \
	        awk '{print $3}' 2>/dev/null`
    sysctl -n -w kernel.hotplug="/bin/true" > /dev/null 2>&1
    /sbin/modprobe -c | grep '^[[:space:]]*alias[[:space:]]*eth[0-9]' | sort | while read a if module; do
	/sbin/ifconfig $if 2>/dev/null >/dev/null
    done
    sysctl -n -w kernel.hotplug=$oldhotplug > /dev/null 2>&1
fi

#Clean up Tmp.
if [ -n "$CLEAN_TMP" ] && [ "$CLEAN_TMP" -ge 1 ];then
    ( 
	TEXPR="! -ctime -$CLEAN_TMP"
	echo -n "Clean-up /tmp directory: "
	cd /tmp && \
	    find . -xdev \
	    $TEXPR \
	    ! -name . \
	    ! \( -name lost+found -uid 0 \) \
	    ! \( -name quota.user -uid 0 \) \
	    ! \( -name quota.group -uid 0 \) \
	    -depth -print | while read i; do [ -d "$i" ] && rmdir "$i" 2>/dev/null ; rm -f "$i" 2>/dev/null; done
       	if [ "$?" = "0" ];then echo_success;else echo_failure;fi
	echo
    )
fi


# MandrakeGlobetrotter support:
if [ -x /usr/share/harddrake/hwprofile ]; then
    action "Starting %s: " Globetrotter /usr/share/harddrake/hwprofile
fi

# Call netprofile as it must be called before /etc/rc.d/rc to be able to change
# the active services.
if [ -x /sbin/set-netprofile ]; then
    action "Starting %s: " netprofile /sbin/set-netprofile
fi

# check if /etc/resolv.conf exist - if not creates it
[ -f /etc/resolv.conf ] || {
               touch /etc/resolv.conf
}

# Now that we have all of our basic modules loaded and the kernel going,
# let's dump the syslog ring somewhere so we can find it later
dmesg > /var/log/dmesg
