From 9c8f2901403eb3c2e1ace23dbfd6490cd074ca61 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 15 Feb 2010 17:34:22 +0000 Subject: [PATCH] Added to repository. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@1509 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scripts/generate-patched-kernel | 117 ++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 scripts/generate-patched-kernel diff --git a/scripts/generate-patched-kernel b/scripts/generate-patched-kernel new file mode 100755 index 000000000..77e3f54cf --- /dev/null +++ b/scripts/generate-patched-kernel @@ -0,0 +1,117 @@ +#!/bin/bash + +############################################################################ +# +# Script for generating a kernel source tree with the SCST patches applied. +# +# Copyright (C) 2010 Bart Van Assche +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, version 2 +# of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +############################################################################ + + +######################## +# Function definitions # +######################## + +function usage { + echo "Usage: $0 " +} + +# First three components of the kernel version number. +function kernel_version { + echo "$1" | sed -n 's/^\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/p' +} + +# Last component of the kernel version, or the empty string if $1 has only +# three components. +function patchlevel { + echo "$1" | sed -n 's/^\([0-9]*\.[0-9]*\.[0-9]*\)[.-]\(.*\)$/\2/p' +} + +# Download the file from URL $1 and save it in the current directory. +function download_file { + if [ ! -e "$(basename "$1")" ]; then + if [ "${quiet_download}" = "false" ]; then + echo "Downloading $1 ..." + fi + if ! wget -q -nc "$1"; then + echo "Downloading $1 failed." + return 1 + fi + fi +} + +# Make sure the kernel tarball and patch file are present in directory +# ${kernel_sources}. Download any missing files from ${kernel_mirror}. +function download_kernel { + local kver="$(kernel_version $1)" + local plevel="$(patchlevel $1)" + + mkdir -p "${kernel_sources}" || return $? + test -w "${kernel_sources}" || return $? + ( + cd "${kernel_sources}" || return $? + download_file "${kernel_mirror}/linux-$(kernel_version $1).tar.bz2" \ + || return $? + if [ "${plevel}" != "" ]; then + download_file "${kernel_mirror}/patch-$1.bz2" || return $? + fi + ) +} + + +######################### +# Argument verification # +######################### + +set -e + +if [ "$1" = "" ]; then + echo "Error: missing kernel version argument." + exit 1 +fi + + +########################## +# Kernel tree generation # +########################## + +kernel_mirror="ftp://ftp.eu.kernel.org/pub/linux/kernel/v2.6" +kernel_sources="$HOME/software/downloads" + +target="linux-$1" +kernel_version="$(kernel_version "$1")" +patchlevel="$(patchlevel "$1")" + +download_kernel "$1" + +mkdir "${target}" || exit $? +cd "${target}" || exit $? + +tar --strip-components=1 -xjf "${kernel_sources}/linux-${kernel_version}.tar.bz2" + +echo "==== ${kernel_sources}/patch-$1.bz2" +bzip2 -cd < "${kernel_sources}/patch-$1.bz2" | patch -s -p1 + +# Note: the command below will only work correctly when $0 is an absolute +# directory, i.e. starts with a slash. +svn status -v "$(dirname $(dirname $0))" \ +| grep -v '^Performing' \ +| cut -c41- \ +| grep -- "-${kernel_version}.*.patch$" \ +| grep -v /in-tree/ \ +| while read p + do + echo "==== $p" + patch -p1 <$p + done