Blame src/perfctr-2.6.x/update-kernel

Packit Service a1973e
#!/bin/sh
Packit Service a1973e
# $Id: update-kernel,v 1.9.2.7 2010/07/01 17:22:27 mikpe Exp $
Packit Service a1973e
# usage:
Packit Service a1973e
#	cd ${kernelsrcdir}
Packit Service a1973e
#	${perfctrsrcdir}/update-kernel
Packit Service a1973e
Packit Service a1973e
perfctr=
Packit Service a1973e
patch=
Packit Service a1973e
patchtype=
Packit Service a1973e
nopatch=
Packit Service a1973e
dryrun=
Packit Service a1973e
sym=
Packit Service a1973e
backup=
Packit Service a1973e
maybe_redhat=
Packit Service a1973e
maybe_suse=
Packit Service a1973e
VERSION=
Packit Service a1973e
PATCHLEVEL=
Packit Service a1973e
SUBLEVEL=
Packit Service a1973e
EXTRAVERSION=
Packit Service a1973e
kernel=
Packit Service a1973e
Packit Service a1973e
usage() {
Packit Service a1973e
    echo 'Usage: cd ${kernelsrcdir}; ${perfctrsrcdir}/update-kernel [options]'
Packit Service a1973e
    echo 'Available options:'
Packit Service a1973e
    echo '--patch=version force use of patch for particular kernel version'
Packit Service a1973e
    echo '-p version      ditto'
Packit Service a1973e
    echo '--nopatch       do not apply patch, only install new files'
Packit Service a1973e
    echo '-n              ditto'
Packit Service a1973e
    echo '--test          apply the patch but do not change any files'
Packit Service a1973e
    echo '-t              ditto'
Packit Service a1973e
    exit 1
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
get_perfctr_srcdir() {
Packit Service a1973e
    # XXX: use dirname instead?
Packit Service a1973e
    perfctr=`echo $0 | sed 's+/update-kernel$++'`
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
get_arch() {
Packit Service a1973e
    if [ -z "$ARCH" ]; then
Packit Service a1973e
	OLDARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/`
Packit Service a1973e
	ARCH=`echo $OLDARCH | sed -e s/i386/x86/ -e s/x86_64/x86/ -e s/ppc.*/powerpc/`
Packit Service a1973e
    fi
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
get_options() {
Packit Service a1973e
    while [ $# -gt 0 ]; do
Packit Service a1973e
	case "$1" in
Packit Service a1973e
	  --patch=*)
Packit Service a1973e
	    patch=`echo "$1" | sed s/--patch=//`
Packit Service a1973e
	    ;;
Packit Service a1973e
	  -p)
Packit Service a1973e
	    shift
Packit Service a1973e
	    if [ $# -eq 0 ]; then
Packit Service a1973e
		echo Error: option "'-p'" requires an argument
Packit Service a1973e
		usage
Packit Service a1973e
	    fi
Packit Service a1973e
	    patch="$1"
Packit Service a1973e
	    ;;
Packit Service a1973e
	  --nopatch|-n)
Packit Service a1973e
	    nopatch=1
Packit Service a1973e
	    ;;
Packit Service a1973e
	  --test|-t)
Packit Service a1973e
	    dryrun="--dry-run"
Packit Service a1973e
	    ;;
Packit Service a1973e
	  --sym)
Packit Service a1973e
	    # not for general use
Packit Service a1973e
	    sym=1
Packit Service a1973e
	    ;;
Packit Service a1973e
	  --backup)
Packit Service a1973e
	    # not for general use
Packit Service a1973e
	    backup=1
Packit Service a1973e
	    ;;
Packit Service a1973e
	  *)
Packit Service a1973e
	    echo Error: unknown option "$1"
Packit Service a1973e
	    usage
Packit Service a1973e
	    ;;
Packit Service a1973e
	esac
Packit Service a1973e
	shift
Packit Service a1973e
    done
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
check_pwd_is_kernel_srcdir() {
Packit Service a1973e
    if [ ! -f drivers/Makefile -o \( ! -f "arch/$ARCH/kernel/Makefile" -a ! -f "arch/$OLDARCH/kernel/Makefile" \) ]; then
Packit Service a1973e
	echo "Error: `pwd` does not appear to be the top-level kernel source directory"
Packit Service a1973e
	usage
Packit Service a1973e
    fi
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
check_kernel_srcdir_is_clean() {
Packit Service a1973e
    if [ -f System.map -o -f .version ]; then
Packit Service a1973e
	echo 'Error: kernel source is not clean; please do a "make mrproper"'
Packit Service a1973e
	exit 1
Packit Service a1973e
    fi
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
get_makefile_variable() {
Packit Service a1973e
    eval `grep "^$1 *=" Makefile | head -n 1 | sed 's/ *= */=/'`
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
get_extra_version() {
Packit Service a1973e
    EXTRAVERSION=`grep "^EXTRAVERSION *=" Makefile | head -n 1 | sed 's/ *= */=/'`
Packit Service a1973e
    case "$EXTRAVERSION" in
Packit Service a1973e
    'EXTRAVERSION=-$(shell echo $(CONFIG_RELEASE)-$(CONFIG_CFGNAME))')
Packit Service a1973e
	maybe_suse=1
Packit Service a1973e
	EXTRAVERSION='EXTRAVERSION=-$(shell echo $(CONFIG_RELEASE))'
Packit Service a1973e
	;;
Packit Service a1973e
    esac
Packit Service a1973e
    MKF=`cat <
Packit Service a1973e
-include .config
Packit Service a1973e
$EXTRAVERSION
Packit Service a1973e
default:
Packit Service a1973e
	@echo EXTRAVERSION='\\$(EXTRAVERSION)'
Packit Service a1973e
EOF`
Packit Service a1973e
    eval `echo "$MKF" | make -f -`
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
get_kernel_version() {
Packit Service a1973e
    get_makefile_variable VERSION
Packit Service a1973e
    get_makefile_variable PATCHLEVEL
Packit Service a1973e
    get_makefile_variable SUBLEVEL
Packit Service a1973e
    get_extra_version
Packit Service a1973e
    case "$EXTRAVERSION" in
Packit Service a1973e
    *custom)
Packit Service a1973e
	maybe_redhat=1
Packit Service a1973e
	EXTRAVERSION=`echo $EXTRAVERSION | sed 's/\(.*\)custom/\1/'`
Packit Service a1973e
	;;
Packit Service a1973e
    esac
Packit Service a1973e
    kernel="$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION"
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
check_given_patch() {
Packit Service a1973e
    if [ ! -f "$perfctr/patches/patch-kernel-$patch" ]; then
Packit Service a1973e
	alias=`grep ^$patch/ $perfctr/patches/aliases | awk -F/ '{ print $2 }'`
Packit Service a1973e
	if [ -n "$alias" -a -f "$perfctr/patches/patch-kernel-$alias" ]; then
Packit Service a1973e
	    patch="$alias"
Packit Service a1973e
	    echo Using patch "$alias" for kernel "$kernel"
Packit Service a1973e
	else
Packit Service a1973e
	    echo Error: no patch for user-specified version "$patch" found
Packit Service a1973e
	    echo See "$perfctr/patches/" for supported kernel versions
Packit Service a1973e
	    exit 1
Packit Service a1973e
	fi
Packit Service a1973e
    fi
Packit Service a1973e
    patchtype="(forced, kernel is $kernel)"
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
try_standard() {
Packit Service a1973e
    if [ -f "$perfctr/patches/patch-kernel-$kernel" ]; then
Packit Service a1973e
	patch="$kernel"
Packit Service a1973e
	echo Found patch for kernel "$kernel"
Packit Service a1973e
    else
Packit Service a1973e
	alias=`grep ^$kernel/ $perfctr/patches/aliases | awk -F/ '{ print $2 }'`
Packit Service a1973e
	if [ -n "$alias" -a -f "$perfctr/patches/patch-kernel-$alias" ]; then
Packit Service a1973e
	    patch="$alias"
Packit Service a1973e
	    echo Using patch "$alias" for kernel "$kernel"
Packit Service a1973e
	fi
Packit Service a1973e
    fi
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
try_redhat() {
Packit Service a1973e
    if [ -f /etc/redhat-release ]; then
Packit Service a1973e
	maybe_redhat=1
Packit Service a1973e
    fi
Packit Service a1973e
    if [ -n "$EXTRAVERSION" -a -n "$maybe_redhat" ]; then
Packit Service a1973e
	if [ -f "$perfctr/patches/patch-kernel-$kernel-redhat" ]; then
Packit Service a1973e
	    patch="$kernel-redhat"
Packit Service a1973e
	    echo Found patch for RedHat kernel "$kernel"
Packit Service a1973e
	else
Packit Service a1973e
	    alias=`grep ^$kernel-redhat $perfctr/patches/aliases | awk -F/ '{ print $2 }'`
Packit Service a1973e
	    if [ -n "$alias" -a -f "$perfctr/patches/patch-kernel-$alias" ]; then
Packit Service a1973e
		patch="$alias"
Packit Service a1973e
		echo Using patch "$alias" for RedHat kernel "$kernel"
Packit Service a1973e
	    fi
Packit Service a1973e
	fi
Packit Service a1973e
    fi
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
try_suse() {
Packit Service a1973e
    if [ -n "$EXTRAVERSION" -a -n "$maybe_suse" ]; then
Packit Service a1973e
	if [ -f "$perfctr/patches/patch-kernel-$kernel-suse" ]; then
Packit Service a1973e
	    patch="$kernel-suse"
Packit Service a1973e
	    echo Found patch for SuSE kernel "$kernel"
Packit Service a1973e
	else
Packit Service a1973e
	    alias=`grep ^$kernel-suse $perfctr/patches/aliases | awk -F/ '{ print $2 }'`
Packit Service a1973e
	    if [ -n "$alias" -a -f "$perfctr/patches/patch-kernel-$alias" ]; then
Packit Service a1973e
		patch="$alias"
Packit Service a1973e
		echo Using patch "$alias" for SuSE kernel "$kernel"
Packit Service a1973e
	    fi
Packit Service a1973e
	fi
Packit Service a1973e
    fi
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
deduce_patch() {
Packit Service a1973e
    try_standard
Packit Service a1973e
    if [ -z "$patch" ]; then
Packit Service a1973e
	try_redhat
Packit Service a1973e
    fi
Packit Service a1973e
    if [ -z "$patch" ]; then
Packit Service a1973e
	try_suse
Packit Service a1973e
    fi
Packit Service a1973e
    if [ -z "$patch" ]; then
Packit Service a1973e
	echo Error: no suitable patch found for kernel "$kernel"
Packit Service a1973e
	echo See "$perfctr/patches/" for supported kernel versions
Packit Service a1973e
	exit 1
Packit Service a1973e
    fi
Packit Service a1973e
    patchtype="(auto-detected)"
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
identify_patch() {
Packit Service a1973e
    if [ -n "$patch" ]; then
Packit Service a1973e
	check_given_patch
Packit Service a1973e
    else
Packit Service a1973e
	deduce_patch
Packit Service a1973e
    fi
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
apply_patch() {
Packit Service a1973e
    echo
Packit Service a1973e
    echo Applying kernel source patch for "$patch" "$patchtype"
Packit Service a1973e
    echo
Packit Service a1973e
    bVt=
Packit Service a1973e
    if [ "$backup" ]; then
Packit Service a1973e
	bVt="-bVt"
Packit Service a1973e
    fi
Packit Service a1973e
    patch $dryrun $bVt -p1 < "$perfctr/patches/patch-kernel-$patch"
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
install_file() {
Packit Service a1973e
    if [ -n "$sym" ]; then
Packit Service a1973e
	echo ln -sf ${perfctr}/$1/$2 $3/
Packit Service a1973e
	if [ -z "$dryrun" ]; then
Packit Service a1973e
	    ln -sf ${perfctr}/$1/$2 $3/
Packit Service a1973e
	fi
Packit Service a1973e
    else
Packit Service a1973e
	echo tar -C "${perfctr}/$1/" --exclude CVS -cf - $2 '|' tar -C $3/ -xf -
Packit Service a1973e
	if [ -z "$dryrun" ]; then
Packit Service a1973e
	    tar -C "${perfctr}/$1/" --exclude CVS -cf - $2 | tar -C $3/ -xf -
Packit Service a1973e
	fi
Packit Service a1973e
    fi
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
install_files() {
Packit Service a1973e
    echo
Packit Service a1973e
    echo Installing new kernel source files
Packit Service a1973e
    echo
Packit Service a1973e
    if [ -d arch/x86/include/asm ]; then
Packit Service a1973e
	install_file linux/include/asm-x86 perfctr.h arch/x86/include/asm
Packit Service a1973e
    elif [ -d include/asm-x86 ]; then
Packit Service a1973e
	install_file linux/include/asm-x86 perfctr.h include/asm-x86
Packit Service a1973e
    else
Packit Service a1973e
	install_file linux/include/asm-x86 perfctr.h include/asm-i386
Packit Service a1973e
	install_file linux/include/asm-x86 perfctr.h include/asm-x86_64
Packit Service a1973e
    fi
Packit Service a1973e
    if [ -d arch/powerpc/include/asm ]; then
Packit Service a1973e
	install_file linux/include/asm-powerpc perfctr.h arch/powerpc/include/asm
Packit Service a1973e
    elif [ -d include/asm-powerpc ]; then
Packit Service a1973e
	install_file linux/include/asm-powerpc perfctr.h include/asm-powerpc
Packit Service a1973e
    else
Packit Service a1973e
	install_file linux/include/asm-powerpc perfctr.h include/asm-ppc
Packit Service a1973e
    fi
Packit Service a1973e
    if [ -d arch/arm/include/asm ]; then
Packit Service a1973e
	install_file linux/include/asm-arm perfctr.h arch/arm/include/asm
Packit Service a1973e
    else
Packit Service a1973e
	install_file linux/include/asm-arm perfctr.h include/asm-arm
Packit Service a1973e
    fi
Packit Service a1973e
    install_file linux/include/linux perfctr.h include/linux
Packit Service a1973e
    install_file linux/drivers perfctr drivers
Packit Service a1973e
}
Packit Service a1973e
Packit Service a1973e
get_perfctr_srcdir
Packit Service a1973e
get_arch
Packit Service a1973e
get_options "$@"
Packit Service a1973e
check_pwd_is_kernel_srcdir
Packit Service a1973e
check_kernel_srcdir_is_clean
Packit Service a1973e
get_kernel_version
Packit Service a1973e
if [ -z "$nopatch" ]; then
Packit Service a1973e
    identify_patch
Packit Service a1973e
    apply_patch
Packit Service a1973e
fi
Packit Service a1973e
install_files