Sophie

Sophie

distrib > Mandriva > 9.1 > i586 > by-pkgid > 8c6202abd5c23d52fed280e28dc23b0a > files > 31

initscripts-7.06-12.3.91mdk.i586.rpm

#!/bin/sh
# (c) MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com>
# 	$Id: kheader,v 1.13 2002/02/11 10:10:04 chmouel Exp $	
#
# kheader: This shell script regenerate the /boot/kernel.h header for \
#	   /usr/src/linux/include/{autoconf,version}.h
#
# chkconfig: 235 95 20
# description: This shell script regenerate the /boot/kernel.h header for \
#	   /usr/src/linux/include/{autoconf,version}.h
#

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

: ${KERNEL_H:=/boot/kernel.h}
: ${HEADERFILE:=${KERNEL_H}-`uname -r`}
[ -d $(dirname $HEADERFILE) ] || exit 0

table() {
k=$(uname -r|sed 's/.*mdk//')
case $k in
	fb)
	    ENT=0;FB=1;SMP=0;SECURE=0;STD=0;
	;;
	smp)
	    ENT=0;FB=0;SMP=1;SECURE=0;STD=0;   
	;;
	enterprise)
	    ENT=1;FB=0;SMP=0;SECURE=0;STD=0;   
	;;
	secure)
	    ENT=0;FB=0;SMP=0;SECURE=1;STD=0;   
	;;
	*)
	    ENT=0;FB=0;SMP=0;SECURE=0;STD=1;   
	esac
}

generate () {
    table;
    # do not overwrite exsisting header, it confuses
    # kernel make and forces it to recompile everything
    cat > $HEADERFILE.tmp << EOF
/* This file is automatically generated at boot time. */
#ifndef __BOOT_KERNEL_H_
#define __BOOT_KERNEL_H_

#ifndef __BOOT_KERNEL_SMP
#define __BOOT_KERNEL_SMP $SMP
#endif

#ifndef __BOOT_KERNEL_FB
#define __BOOT_KERNEL_FB $FB
#endif

#ifndef __BOOT_KERNEL_SECURE
#define __BOOT_KERNEL_SECURE $SECURE
#endif

#ifndef __BOOT_KERNEL_ENTERPRISE
#define __BOOT_KERNEL_ENTERPRISE $ENT
#endif

#ifndef __BOOT_KERNEL_UP
#define __BOOT_KERNEL_UP $STD
#endif

#endif
EOF

cmp -s $HEADERFILE $HEADERFILE.tmp || mv -f $HEADERFILE.tmp $HEADERFILE
rm -f $HEADERFILE.tmp

if [ -f $KERNEL_H ] ; then
    rm -f $KERNEL_H
fi

ln -sf $HEADERFILE $KERNEL_H
}

function remove_orphaned {
    local version= i=
    for i in /boot/kernel.h-* /boot/System.map-* /boot/config-*; do
	version=${i#*-}
	[[ -f /boot/vmlinuz-${version} ]] || rm -f ${i}
    done
}

case $1 in 
    start)
    # We don't log this command, because most users don't want to hear this (c) Chmou
	generate
	touch /var/lock/subsys/kheader
	;;
    restart)
	;;
    reload)
	generate
	;;
    stop)
	remove_orphaned;
	rm -f /var/lock/subsys/kheader
	;;
    status)
	;;
    *)
    gprintf "Usage: %s\n" "$(basename $0) {start|stop|reload|restart}"
    exit 0
    ;;
esac