Roland McGrath 4a89409
#!/bin/bash
Roland McGrath 4a89409
Roland McGrath 4a89409
if [ ! -f /usr/bin/curl ]; then
Roland McGrath 4a89409
  echo yum install curl
Roland McGrath 4a89409
  exit 0
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
Roland McGrath 4a89409
# Current kernel bits
Roland McGrath 4a89409
if [ `grep -c ^patch upstream` -ge 1 ]; then
Roland McGrath 4a89409
  export OLD=`grep ^patch upstream | tail -n1 | sed s/patch-// | sed s/\.bz2//`
Roland McGrath 4a89409
else
Roland McGrath 4a89409
  export OLD=`grep linux-2.6 upstream | tail -n1 | sed s/linux-// | sed s/\.tar\.bz2//`
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
export OLDBASE=`echo $OLD | sed s/-/\ /g | sed s/2\.6\.// | awk '{ print $1 }'`
Roland McGrath 4a89409
if [ `echo $OLD | grep -c rc` -ge 1 ]; then
Roland McGrath 4a89409
  export OLDRC=`echo $OLD | sed s/-/\ /g | sed s/rc// | awk '{ print $2 }'`
Roland McGrath 4a89409
  if [ `echo $OLD | grep -c git` -ge 1 ]; then
Roland McGrath 4a89409
    export OLDGIT=`echo $OLD | sed s/-/\ /g | sed s/git// | awk '{ print $3 }'`
Roland McGrath 4a89409
  else
Roland McGrath 4a89409
    export OLDGIT=0
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
else
Roland McGrath 4a89409
  export OLDRC=0
Roland McGrath 4a89409
  if [ `echo $OLD | grep -c git` -ge 1 ]; then
Roland McGrath 4a89409
    export OLDGIT=`echo $OLD | sed s/-/\ /g | sed s/git// | awk '{ print $2 }'`
Roland McGrath 4a89409
  else
Roland McGrath 4a89409
    export OLDGIT=0
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
Roland McGrath 4a89409
# Is there a new snapshot or prepatch ?
Roland McGrath 4a89409
NEW=`curl -s http://www.kernel.org/kdist/finger_banner | grep "latest snapshot 2.6 version"`
Roland McGrath 4a89409
if [ -z "$NEW" ] ; then
Roland McGrath 4a89409
  NEW=`curl -s http://www.kernel.org/kdist/finger_banner | grep "latest mainline 2.6 version"`
Roland McGrath 4a89409
  if [ -z "$NEW" ] ; then
Roland McGrath 4a89409
    if [ "$OLDRC" -ne 0 ] ; then
Roland McGrath 4a89409
      NEW=`curl -s http://www.kernel.org/kdist/finger_banner | grep "latest stable 2.6." | head -n1`
Roland McGrath 4a89409
    else
Roland McGrath 4a89409
      echo "No new rc or git snapshot of stable branch".
Roland McGrath 4a89409
      exit 0
Roland McGrath 4a89409
    fi
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
export N=`echo $NEW | awk '{ print $11 }'`
Roland McGrath 4a89409
if [ -z "$N" ]; then
Roland McGrath 4a89409
  # "Stable version"
Roland McGrath 4a89409
  export NEW=`echo $NEW | awk '{ print $10 }'`
Roland McGrath 4a89409
else
Roland McGrath 4a89409
  export NEW=`echo $NEW | awk '{ print $11 }'`
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
Roland McGrath 4a89409
export NEWBASE=`echo $NEW | sed s/-/\ /g | sed s/2\.6\.// | awk '{ print $1 }'`
Roland McGrath 4a89409
if [ `echo $NEW | grep -c rc` -ge 1 ]; then
Roland McGrath 4a89409
  export NEWRC=`echo $NEW | sed s/-/\ /g | sed s/rc// | awk '{ print $2 }'`
Roland McGrath 4a89409
  if [ `echo $NEW | grep -c git` -ge 1 ]; then
Roland McGrath 4a89409
    export NEWGIT=`echo $NEW | sed s/-/\ /g | sed s/git// | awk '{ print $3 }'`
Roland McGrath 4a89409
  else
Roland McGrath 4a89409
    export NEWGIT=0
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
else
Roland McGrath 4a89409
  export NEWRC=0
Roland McGrath 4a89409
  if [ `echo $NEW | grep -c git` -ge 1 ]; then
Roland McGrath 4a89409
    export NEWGIT=`echo $NEW | sed s/-/\ /g | sed s/git// | awk '{ print $2 }'`
Roland McGrath 4a89409
  else
Roland McGrath 4a89409
    export NEWGIT=0
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
Roland McGrath 4a89409
echo "OLD kernel was $OLD  BASE=$OLDBASE RC=$OLDRC GIT=$OLDGIT"
Roland McGrath 4a89409
echo "NEW kernel is  $NEW  BASE=$NEWBASE RC=$NEWRC GIT=$NEWGIT"
Roland McGrath 4a89409
Roland McGrath 4a89409
if [ "$OLDRC" -eq 0 -a "$OLDGIT" -eq 0 -a "$OLDGIT" -ne "$NEWGIT" ]; then
Roland McGrath 4a89409
  echo "Rebasing from a stable release to a new git snapshot"
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ released_kernel\ 1/\%define\ released_kernel\ 0/' kernel.spec
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ rawhide_skip_docs\ 1/\%define\ rawhide_skip_docs\ 0/' kernel.spec
Roland McGrath 4a89409
  # force these to zero in this case, they may not have been when we rebased to stable
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ rcrev.*/\%define\ rcrev\ 0/' kernel.spec
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ gitrev.*/\%define\ gitrev\ 0/' kernel.spec
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
Roland McGrath 4a89409
# make sure we build docs at least once per -rc kernel, shut it off otherwise
Roland McGrath 4a89409
if [ "$OLDRC" -ne 0 -a "$NEWRC" -gt "$OLDRC" ]; then
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ rawhide_skip_docs\ 1/\%define\ rawhide_skip_docs\ 0/' kernel.spec
Roland McGrath 4a89409
else
Roland McGrath 4a89409
  if [ "$NEWRC" -eq "$OLDRC" -a "$NEWGIT" -gt "$OLDGIT" ]; then
Roland McGrath 4a89409
    # common case, same -rc, new -git, make sure docs are off.
Roland McGrath 4a89409
    perl -p -i -e 's/^%define\ rawhide_skip_docs\ 0/\%define\ rawhide_skip_docs\ 1/' kernel.spec
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
Roland McGrath 4a89409
if [ "$NEWRC" -eq 0 -a "$NEWGIT" -eq 0 ]; then
Roland McGrath 4a89409
  echo "Rebasing from -rc to final release."
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ released_kernel\ 0/\%define\ released_kernel\ 1/' kernel.spec
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ rawhide_skip_docs\ 1/\%define\ rawhide_skip_docs\ 0/' kernel.spec
Roland McGrath 4a89409
  export OLD_TARBALL_BASE=$(($OLDBASE-1))
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ base_sublevel\ $ENV{OLD_TARBALL_BASE}/%define\ base_sublevel\ $ENV{NEWBASE}/' kernel.spec
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ rcrev.*/\%define\ rcrev\ 0/' kernel.spec
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ gitrev.*/\%define\ gitrev\ 0/' kernel.spec
Roland McGrath 4a89409
Roland McGrath 4a89409
  grep -v kernel-2.6.$OLD_TARBALL_BASE .cvsignore >.cvsignore.tmp ; mv .cvsignore.tmp .cvsignore
Roland McGrath 4a89409
  echo kernel-2.6.$NEWBASE >> .cvsignore
Roland McGrath 4a89409
Roland McGrath 4a89409
  for i in upstream sources .cvsignore
Roland McGrath 4a89409
  do
Roland McGrath 4a89409
   grep -v linux-2.6.$OLD_TARBALL_BASE.tar.bz2 $i > .$i.tmp; mv .$i.tmp $i
Roland McGrath 4a89409
   grep -v patch-2.6.$OLDBASE-rc$OLDRC.bz2 $i > .$i.tmp; mv .$i.tmp $i
Roland McGrath 4a89409
   grep -v patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2 $i > .$i.tmp; mv .$i.tmp $i
Roland McGrath 4a89409
  done
Roland McGrath 4a89409
Roland McGrath 4a89409
  echo linux-2.6.$NEWBASE.tar.bz2 >> upstream
Roland McGrath 4a89409
Roland McGrath 4a89409
  rm -f linux-2.6.$OLD_TARBALL_BASE.tar.bz2
Roland McGrath 4a89409
  rm -f linux-2.6.$OLD_TARBALL_BASE.tar.bz2.sign
Roland McGrath 4a89409
  rm -f patch-2.6.$OLDBASE-rc$OLDRC.bz2
Roland McGrath 4a89409
  rm -f patch-2.6.$OLDBASE-rc$OLDRC.bz2.sign
Roland McGrath 4a89409
  rm -f patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2
Roland McGrath 4a89409
  rm -f patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2.sign
Roland McGrath 4a89409
Roland McGrath 4a89409
  cvs remove linux-2.6.$OLD_TARBALL_BASE.tar.bz2.sign
Roland McGrath 4a89409
  cvs remove patch-2.6.$OLDBASE-rc$OLDRC.bz2.sign
Roland McGrath 4a89409
  cvs remove patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2.sign
Roland McGrath 4a89409
Roland McGrath 4a89409
  make download
Roland McGrath 4a89409
  make upload FILES=linux-$NEW.tar.bz2
Roland McGrath 4a89409
Roland McGrath 4a89409
  cvs add linux-$NEW.tar.bz2.sign
Roland McGrath 4a89409
Roland McGrath 4a89409
  bumpspecfile.py kernel.spec "- $NEW"
Roland McGrath 4a89409
  make clog
Roland McGrath 4a89409
  echo FIXME! Fix up fedora_cvs_origin
Roland McGrath 4a89409
  make verrel
Roland McGrath 4a89409
  exit 1
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
Roland McGrath 4a89409
if [ "$OLDRC" != "$NEWRC" ]; then
Roland McGrath 4a89409
  echo "Different rc. Rebasing from $OLDRC to $NEWRC"
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ rcrev.*/\%define\ rcrev\ $ENV{"NEWRC"}/' kernel.spec
Roland McGrath 4a89409
  perl -p -i -e 's/$ENV{OLDBASE}-rc$ENV{OLDRC}.bz2/$ENV{NEWBASE}-rc$ENV{NEWRC}.bz2/' .cvsignore
Roland McGrath 4a89409
  perl -p -i -e 's/$ENV{OLDBASE}-rc$ENV{OLDRC}.bz2/$ENV{NEWBASE}-rc$ENV{NEWRC}.bz2/' upstream
Roland McGrath 4a89409
  grep -v patch-2.6.$OLDBASE-rc$OLDRC.bz2 sources > .sources.tmp; mv .sources.tmp sources
Roland McGrath 4a89409
  grep -v patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2 .cvsignore >.cvsignore.tmp ; mv .cvsignore.tmp .cvsignore
Roland McGrath 4a89409
  if [ `grep -c patch-2.6.$NEWBASE-rc$NEWRC.bz2 upstream` -eq 0 ]; then
Roland McGrath 4a89409
    echo patch-2.6.$NEWBASE-rc$NEWRC.bz2 >> .cvsignore
Roland McGrath 4a89409
    echo patch-2.6.$NEWBASE-rc$NEWRC.bz2 >> upstream
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
  rm -f patch-2.6.$OLDBASE-rc$OLDRC.bz2
Roland McGrath 4a89409
  rm -f patch-2.6.$OLDBASE-rc$OLDRC.bz2.sign
Roland McGrath 4a89409
  cvs remove patch-2.6.$OLDBASE-rc$OLDRC.bz2.sign
Roland McGrath 4a89409
  make download
Roland McGrath 4a89409
  make upload FILES=patch-2.6.$NEWBASE-rc$NEWRC.bz2
Roland McGrath 4a89409
  cvs add patch-2.6.$NEWBASE-rc$NEWRC.bz2.sign
Roland McGrath 4a89409
Roland McGrath 4a89409
  # Another awkward (albeit unlikely) corner case.
Roland McGrath 4a89409
  # Moving from say 26-rc3-git1 to 26-rc4-git1
Roland McGrath 4a89409
  # The above will grab the new -rc, but the below will
Roland McGrath 4a89409
  # think that the -git hasn't changed.
Roland McGrath 4a89409
  # Fudge around this, by pretending the old git was something crazy.
Roland McGrath 4a89409
  OLDGIT=99
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
Roland McGrath 4a89409
if [ "$OLDGIT" != "$NEWGIT" ]; then
Roland McGrath 4a89409
  if [ "$OLDRC" -eq 0 -a "$OLDGIT" -eq 0 ]; then
Roland McGrath 4a89409
    echo "Rebasing to pre-rc git$NEWGIT"
Roland McGrath 4a89409
  else
Roland McGrath 4a89409
    echo "Different git. Rebasing from git$OLDGIT to git$NEWGIT"
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
  perl -p -i -e 's/^%define\ gitrev.*/\%define\ gitrev\ $ENV{"NEWGIT"}/' kernel.spec
Roland McGrath 4a89409
  if [ "$OLDGIT" -ne 0 ]; then
Roland McGrath 4a89409
    if [ "$NEWGIT" -ne 0 ]; then
Roland McGrath 4a89409
      perl -p -i -e 's/$ENV{OLD}/$ENV{NEW}/' .cvsignore
Roland McGrath 4a89409
      perl -p -i -e 's/$ENV{OLD}/$ENV{NEW}/' upstream
Roland McGrath 4a89409
    fi
Roland McGrath 4a89409
    grep -v patch-$OLD.bz2 sources > .sources.tmp; mv .sources.tmp sources
Roland McGrath 4a89409
    grep -v patch-$OLD.bz2 upstream > .upstream.tmp; mv .upstream.tmp upstream
Roland McGrath 4a89409
  else
Roland McGrath 4a89409
    echo patch-$NEW.bz2 >> .cvsignore
Roland McGrath 4a89409
    echo patch-$NEW.bz2 >> upstream
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
Roland McGrath 4a89409
  make download
Roland McGrath 4a89409
  make upload FILES=patch-$NEW.bz2
Roland McGrath 4a89409
Roland McGrath 4a89409
  cvs add patch-$NEW.bz2.sign
Roland McGrath 4a89409
  if [ "$OLDGIT" -ne 0 ]; then
Roland McGrath 4a89409
    rm -f patch-$OLD.bz2
Roland McGrath 4a89409
    rm -f patch-$OLD.bz2.sign
Roland McGrath 4a89409
    cvs remove patch-$OLD.bz2.sign
Roland McGrath 4a89409
  fi
Roland McGrath 4a89409
fi
Roland McGrath 4a89409
Roland McGrath 4a89409
if [ "$OLDRC" != "$NEWRC" -o "$OLDGIT" != "$NEWGIT" ]; then
Roland McGrath 4a89409
  perl -p -i -e 's|^ApplyPatch\ git-linus.diff|#ApplyPatch\ git-linus.diff|' kernel.spec
Roland McGrath 4a89409
  > git-linus.diff
Roland McGrath 4a89409
  bumpspecfile.py kernel.spec "- $NEW"
Roland McGrath 4a89409
  make clog
Roland McGrath 4a89409
  exit 1
Roland McGrath 4a89409
else
Roland McGrath 4a89409
  exit 0
Roland McGrath 4a89409
fi