SHARE
TWEET

Golan Zakai

a guest Jul 12th, 2010 148 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SRPM_URL='http://mirror.centos.org/centos/5/updates/SRPMS/'
  2. PATCH_URL='http://www.ssi.bg/~ja/nfct/'
  3. PATCH_FILE='ipvs-nfct-2.6.16-1.diff'
  4. BUILD_OPTIONS='--with baseonly --without debug --without debuginfo'
  5.  
  6. cd
  7. rm rpmbuild -rf                
  8. mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
  9. echo '%_topdir %(echo $HOME)/rpmbuild' > .rpmmacros
  10.  
  11. mkdir files -p
  12. cd files
  13. if [ $# -eq "1" ]; then
  14.         echo "selected kernel -> $1"
  15.         if [ -f $1 ]; then
  16.                 echo "kernel source rpm exist"
  17.         else
  18.                 echo "fetching kernel source rpm"
  19.                 wget $SRPM_URL$1
  20.         fi
  21. else
  22.         echo "please provide one of the following kerenels as parameter:"
  23.         curl -s $SRPM_URL | grep -i kernel | sed s/"\(.*<a href=\"\)\([^\"]*\)\">\(.*\)"/\\2/g;
  24.         exit 1
  25. fi
  26.  
  27. echo "extracting package"
  28. rpm -i $1 2>&1 | grep -v mockb
  29.  
  30. cd ~/rpmbuild/SOURCES
  31.  
  32. echo "downloading NFCT PATCH"
  33. wget $PATCH_URL$PATCH_FILE
  34.  
  35. echo "patching kernel configs"
  36.  
  37. for i in `ls kernel-2.6.18-*.config`; do
  38.         total_lines=`cat $i | wc -l`
  39.         line_number=`cat $i | grep -n CONFIG_IP_VS_FTP | grep -o "[0-9]\+"`
  40.         head -n $line_number $i > $i.tmp
  41.         echo "CONFIG_IP_VS_NFCT=y" >> $i.tmp
  42.         tail -n $(($total_lines - $line_number)) $i >> $i.tmp
  43.         mv $i.tmp $i
  44. done;
  45.  
  46. echo "patching kernel spec file"
  47.  
  48. PATCH_LOCATION1='# adds rhel version info to version.h'
  49. PATCH_LOCATION2='# correction of SUBLEVEL/EXTRAVERSION in top-level source tree Makefile'
  50.  
  51. cd ~/rpmbuild/SPECS/
  52.  
  53. cat kernel-2.6.spec |
  54. sed -e "s,$PATCH_LOCATION1,Patch40000: ipvs-nfct-2.6.16-1.diff\n$PATCH_LOCATION1,g" |
  55. sed -e "s,$PATCH_LOCATION2,%patch40000 -p1\n$PATCH_LOCATION2,g" > kernel-2.6.spec.tmp
  56. mv kernel-2.6.spec.tmp kernel-2.6.spec
  57. echo "unpacking kernel and applying patches"
  58. rpmbuild -bp --target=`uname -m` kernel-2.6.spec 2> prep-err-step1.log | tee prep-out-step1.log
  59.  
  60. cp ~/rpmbuild/BUILD/kernel-2.6.18/linux-2.6.18.`uname -m`/configs/* ~/rpmbuild/SOURCES
  61. echo "building kernel rpms"
  62. rpmbuild -bb $BUILD_OPTIONS --target=`uname -m` kernel-2.6.spec 2> build-err.log | tee build-out.log
RAW Paste Data
Top