#!/bin/sh # (c) Mandriva, Pixel <pixel@mandriva.com> # $Id: kheader.pl 84121 2006-11-14 16:12:11Z pixel $ # # kheader: Regenerates kernel headers # # chkconfig: 235 95 20 # description: This shell script regenerates the /boot/kernel.h header for \ # /usr/src/linux/include/{autoconf,version}.h # ### BEGIN INIT INFO # Provides: kheader # Default-Start: 2 3 5 # Short-Description: Regenerates kernel headers # Description: This shell script regenerates the /boot/kernel.h header for # /usr/src/linux/include/{autoconf,version}.h ### END INIT INFO . /etc/rc.d/init.d/functions : ${KERNEL_H:=/boot/kernel.h} : ${HEADERFILE:=${KERNEL_H}-`uname -r`} [ -d $(dirname $HEADERFILE) ] || exit 0 table() { SMP=0;XEN0=0;DEFAULT=0;LEGACY=0;ENTERPRISE=0;SECURE=0;I686_UP_4GB=0;I686_UP_64GB=0;P3_SMP_64GB=0;I586_UP_1GB=0;DESKTOP=0;DESKTOPSMP=0;DESKTOP_I586=0;DESKTOPSMP_I586=0;LAPTOP=0;LAPTOPSMP=0;SERVER=0;SERVERSMP=0;UP=0 # this will do the trick until gprintf.py expands variables echo_no_gprintf="echo" ver=$(uname -r) mdk="md[kv]" k=$($echo_no_gprintf $ver|sed "s/.*$mdk//") # for tmb & multimedia kernels case $ver in *-desktop-*) k=desktop$k;; *-laptop-*) k=laptop$k;; *-server-*) k=server$k;; esac case $k in smp) SMP=1;; xen0) XEN0=1;; default) DEFAULT=1;; legacy) LEGACY=1;; enterprise) ENTERPRISE=1;; secure) SECURE=1;; -i686-up-4GB) I686_UP_4GB=1;; -i686-up-64GB) I686_UP_64GB=1;; -p3-smp-64GB) P3_SMP_64GB=1;; -i586-up-1GB) I586_UP_1GB=1;; desktop) DESKTOP=1;; desktopsmp) DESKTOPSMP=1;; desktop-i586) DESKTOP_I586=1;; desktopsmp-i586) DESKTOPSMP_I586=1;; laptop) LAPTOP=1;; laptopsmp) LAPTOPSMP=1;; server) SERVER=1;; serversmp) SERVERSMP=1;; *) UP=1;; esac # since 2.6.17-2mdv, default kernels can be SMP enabled by # default, hence a new name $echo_no_gprintf "$UP:$ver" | grep -q "^1:.*$mdk" && { case $ver in # XXX simpler to maintain a skip list [01].*|2.[0-5].*|2.6.[0-9]-*|2.6.1[0-6]-*|2.6.17-1mdk);; *) UP=0; DEFAULT=1;; esac } unset echo_no_gprintf } 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_XEN0 #define __BOOT_KERNEL_XEN0 $XEN0 #endif #ifndef __BOOT_KERNEL_DEFAULT #define __BOOT_KERNEL_DEFAULT $DEFAULT #endif #ifndef __BOOT_KERNEL_LEGACY #define __BOOT_KERNEL_LEGACY $LEGACY #endif #ifndef __BOOT_KERNEL_ENTERPRISE #define __BOOT_KERNEL_ENTERPRISE $ENTERPRISE #endif #ifndef __BOOT_KERNEL_SECURE #define __BOOT_KERNEL_SECURE $SECURE #endif #ifndef __BOOT_KERNEL_I686_UP_4GB #define __BOOT_KERNEL_I686_UP_4GB $I686_UP_4GB #endif #ifndef __BOOT_KERNEL_I686_UP_64GB #define __BOOT_KERNEL_I686_UP_64GB $I686_UP_64GB #endif #ifndef __BOOT_KERNEL_P3_SMP_64GB #define __BOOT_KERNEL_P3_SMP_64GB $P3_SMP_64GB #endif #ifndef __BOOT_KERNEL_I586_UP_1GB #define __BOOT_KERNEL_I586_UP_1GB $I586_UP_1GB #endif #ifndef __BOOT_KERNEL_DESKTOP #define __BOOT_KERNEL_DESKTOP $DESKTOP #endif #ifndef __BOOT_KERNEL_DESKTOPSMP #define __BOOT_KERNEL_DESKTOPSMP $DESKTOPSMP #endif #ifndef __BOOT_KERNEL_DESKTOP_I586 #define __BOOT_KERNEL_DESKTOP_I586 $DESKTOP_I586 #endif #ifndef __BOOT_KERNEL_DESKTOPSMP_I586 #define __BOOT_KERNEL_DESKTOPSMP_I586 $DESKTOPSMP_I586 #endif #ifndef __BOOT_KERNEL_LAPTOP #define __BOOT_KERNEL_LAPTOP $LAPTOP #endif #ifndef __BOOT_KERNEL_LAPTOPSMP #define __BOOT_KERNEL_LAPTOPSMP $LAPTOPSMP #endif #ifndef __BOOT_KERNEL_SERVER #define __BOOT_KERNEL_SERVER $SERVER #endif #ifndef __BOOT_KERNEL_SERVERSMP #define __BOOT_KERNEL_SERVERSMP $SERVERSMP #endif #ifndef __BOOT_KERNEL_UP #define __BOOT_KERNEL_UP $UP #endif #endif EOF mv -f $HEADERFILE.tmp $HEADERFILE 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