#!/bin/sh # # Update the 2.6 ism workarea with a 2.6 kernel src tree # # Useful commands for the exercise: # ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.tar.gz 50Mb # cd isms # bzcat /build/kaos/kernel.org-sgidev/linux-2.6.18.tar.bz2 | tar xvf - # cd linux-2.6.18 # mkdir patches # quilt import ~/patches/patch-2.6.19-rc3 # quilt push # tmp=/tmp/$$ here=`pwd` prog=`basename $0` status=1 debug=false trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15 patches="split-patches" tmp_linux_dir=/tmp/$USER.linux_src.$$ cat <$tmp.skip xfs dmapi mainline-patches patches split-patches *.out.$USER \.pc final.* \.modheader \.workarea \.census census census,v *\.prj *\.prcs_aux EOF _usage() { cat << EOF Usage: $prog version workarea mainline-2.6 version kernel version like 2.6.19 or 2.6.19-rc3 workarea ptools 2.6.x-xfs workarea mainline-2.6 fresh 2.6 mainline src tree or .tar or .tar.gz or .tar.bz2 file (won't delete this tree on exit) EOF exit 1 } _kdb_find_latest() { #Example: #-r--r--r-- 1 10133 10133 111934 Feb 6 02:05 kdb-v4.4-2.6.20-common-1.bz2 #-r--r--r-- 1 10133 10133 111958 Feb 16 04:47 kdb-v4.4-2.6.20-common-2.bz2 #-r--r--r-- 1 10133 10133 111868 Feb 16 05:12 kdb-v4.4-2.6.20-common-3.bz2 #-r--r--r-- 1 10133 10133 85996 Feb 6 02:05 kdb-v4.4-2.6.20-i386-1.bz2 #-r--r--r-- 1 10133 10133 86157 Feb 16 04:46 kdb-v4.4-2.6.20-i386-2.bz2 #-r--r--r-- 1 10133 10133 134922 Feb 6 02:05 kdb-v4.4-2.6.20-ia64-1.bz2 #-r--r--r-- 1 10133 10133 134901 Feb 16 04:46 kdb-v4.4-2.6.20-ia64-2.bz2 #-r--r--r-- 1 10133 10133 84248 Feb 6 02:05 kdb-v4.4-2.6.20-x86_64-1.bz2 #-r--r--r-- 1 10133 10133 84248 Feb 16 04:46 kdb-v4.4-2.6.20-x86_64-2.bz2 arch=$1 echo ls $kdb_ftp_dir | ftp -ai $kdb_ftp_host >$tmp.ftpout if [ $? -ne 0 ] then echo "ls $kdb_ftp_dir | ftp -ai $kdb_ftp_host failed" exit 1 fi grep ${kdb_prefix}$arch $tmp.ftpout | tail -1 | awk '{print $NF}' } _kdb_find_all_latest() { if [ -e $kdbfile ] then nl=`wc -l $kdbfile` if [ $nl -ne 4 ] then echo "$kdbfile is corrupted - wrong number of lines" exit 1 fi kdb1=`head 1 $kdbfile` kdb2=`head 2 $kdbfile | tail 1` kdb3=`head 3 $kdbfile | tail 1` kdb4=`head 4 $kdbfile | tail 1` else kdb1=`_kdb_find_latest i386` kdb2=`_kdb_find_latest ia64` kdb3=`_kdb_find_latest common` kdb4=`_kdb_find_latest x86_64` echo $kdb1 >$kdbfile echo $kdb2 >>$kdbfile echo $kdb3 >>$kdbfile echo $kdb4 >>$kdbfile fi } _kdb_all_there() { for file in $kdb1 $kdb2 $kdb3 $kdb4 do [ ! -e $file ] && return 1 done return 0 } _kdb_ftp_them() { echo "ftp'ing kdb files: $kdb1, $kdb2, $kdb3, $kdb4" ftp -aiv \ $kdb_ftp_host:$kdb_ftp_dir/$kdb1 \ $kdb_ftp_host:$kdb_ftp_dir/$kdb2 \ $kdb_ftp_host:$kdb_ftp_dir/$kdb3 \ $kdb_ftp_host:$kdb_ftp_dir/$kdb4 if [ $? -ne 0 ] then echo "ftp $kdb_ftp_host:$kdb_ftp_dir failed" exit 1 fi } _fixup_new_kdb_patches() { cd $ism/$patches _kdb_find_all_latest if _kdb_all_there then echo "All kdb patches already present in 2.6 workarea" p_state `p_list -c` return fi # fix up kdb patches if ls kdb* >/dev/null 2>&1 then p_delete kdb* fi _kdb_ftp_them if ! ls kdb* >/dev/null 2>&1 then echo "Failed to download kdb patches: $kdb_ftp_host:$kdb_ftp_dir/$kdb1,$kdb2,$kdb3,$kdb4" exit fi p_fetal -kb kdb* # fix up series file p_modify series >series # truncate it for f in kdb* do echo $f | sed 's/\.bz2//' >>series done echo dmapi-enable >>series p_state `p_list -c` } # apply to current 2.6 mainline tree _apply_custom_patches() { cd $kernel_src if [ -d kdb ] then echo "kdb subdir exists assuming kernel already patched" else echo "apply kdb patches using quilt..." [ -d patches ] || mkdir patches for p in $ism/$patches/{$kdb1,$kdb2,$kdb3,$kdb4} do quilt import $p quilt push done fi if grep -iq dmapi MAINTAINERS then echo "DMAPI in MAINTAINERS assuming dmapi patch already applied" else echo "apply dmapi patches using quilt (in case of failure)..." [ -d patches ] || mkdir patches quilt import $ism/$patches/dmapi-enable quilt push fi } _new_files() { lsdiff -s $1 | grep '^+' | cut -c3- } _deleted_files() { lsdiff -s $1 | grep '^-' | cut -c3- } _modified_files() { lsdiff -s $1 | grep '^!' | cut -c3- } _process_args() { [ $# -ne 3 ] && _usage # kernel version needed for kdb kernel_version=$1 # process ism/workarea argument ism=$2 if [ ! -d $ism ] then echo "$prog: $ism is not a directory" _usage fi if [ ! -s $ism/.workarea ] then echo "$prog: can't find $ism/.workarea" _usage fi kdbfile=$ism/split-patches/.kdbfiles # process linux kernel source argument kernel_src=$3 if [ ! -e $kernel_src ] then echo "$prog: $kerenel_src does not exist" _usage fi # extra handling for kernel src archives if [ ! -d $kernel_src ] then echo "Making $tmp_linux_dir (will leave behind)" mkdir $tmp_linux_dir cd $tmp_linux_dir echo "$prog: $kerenel_src is not a directory" if echo $kernel_src | egrep -q 'tar.bz2$' then echo "Uncompressing and untarring src..." bzcat $kernel_src | tar xvf - elif echo $kernel_src | egrep -q 'tar.gz2$' then echo "Uncompressing and untarring src..." tar -zxvf $kernel_src elif echo $kernel_src | egrep -q 'tar$' then echo "Untaring src..." tar -xvf $kernel_src else echo "$prog: $kerenel_src is not a directory or known extension" _usage fi # need to go down 1 level kernel_src=$tmp_linux_dir/`ls $tmp_linux_dir` echo "using kernel source from $kernel_src" elif [ ! -e $kernel_src/MAINTAINERS ] then echo "Are you sure the kernel src argument is correct: $kernel_src" echo "$kernel_src/MAINTAINERS not found" _usage fi echo "Using mainline source tree of $kernel_src" } # --------- main ------------ _process_args $* kdb_prefix="kdb-v4.4-${kernel_version}-" kdb_ftp_host=oss.sgi.com kdb_ftp_dir=/projects/kdb/download/latest which lsdiff > $tmp.which if [ ! -s $tmp.which ] then echo "lsdiff not in your path!" exit 1 fi echo "Update workarea..." export WORKAREA=$ism cd $ism p_tupdate echo "Files which are not in the census for workarea:" p_list -W echo "Update new kdb..." _fixup_new_kdb_patches echo "Apply patches to mainline src..." _apply_custom_patches echo "Diff 2.6.x-xfs with patched mainline src..." diff -Naur -X $tmp.skip $ism $kernel_src |\ sed \ -e "s#^--- ${ism}#--- #" \ -e "s#^--- /#--- #" \ -e "s#^+++ ${kernel_src}#+++ #" \ -e "s#^+++ /#+++ #" \ >$tmp.patch if $debug then cp $tmp.patch $here/THE_PATCH fi _new_files $tmp.patch >$tmp.new _deleted_files $tmp.patch >$tmp.deleted _modified_files $tmp.patch >$tmp.modified if $debug then cp $tmp.modified $here/THE_MODIFIED cp $tmp.new $here/THE_NEW cp $tmp.deleted $here/THE_DELETED fi echo "Fix up modified/deleted state for patched files..." cd $ism [ -s $tmp.deleted ] && p_delete -I $tmp.deleted [ -s $tmp.modified ] && p_modify -I $tmp.modified echo "Copy over the new and modified files..." cat $tmp.new $tmp.modified | \ while read file do src_file=$kernel_src/$file dst_file=$ism/$file dst_dir=`dirname $dst_file` [ -d $dst_dir ] || mkdir -p $dst_dir echo "cp $src_file $dst_file" if ! cp $src_file $dst_file then echo "Failed to copy from $src_file to $dst_file" exit fi done echo "Fix up fetal state for patched files..." [ -s $tmp.new ] && p_fetal -I $tmp.new status=0