[1811274 views]

[]

Odi's astoundingly incomplete notes

New entries | Code

Creating a kernel source diff

When you roll your own kernel and frequently update it to the current stable version from git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git, then this script may be helpful. It creates the diff from the currently running kernel version to the latest stable one. You can easily apply it to your build source tree with: patch -p1 <~/patch.diff
#!/bin/bash
REPO=~/code/linux-stable
OUT=~/patch.diff
cd "${REPO}" || exit 1
[ -d .git ] || {
  echo "${REPO} is not a git repo" >&2
  exit 1
}


CUR=$(uname -r)
MAJ=$(echo "${CUR}"| sed 's/\.[^.]*$//')
MIN=$(echo "${CUR}"| sed 's/[0-9]\+\.[0-9]\+\.//')
if [ "${MIN}" = "0" ]; then
  # strip .0 
  CUR="${MAJ}"
fi
BR=$(git branch --show-current)

echo "Using git repo: ${REPO}"
echo "Current kernel: ${CUR}"
echo "Major version: ${MAJ}"
echo "git branch: ${BR}"
if [ "${BR}" != "linux-${MAJ}.y" ]; then
  echo "linux-stable on branch ${BR} which is not compatible with kernel ${CUR}" >&2
  EX=$(git branch | fgrep linux-${MAJ}.y)
  if [ -z "${EX}" ]; then
    echo "Please do: git checkout -t origin/linux-${MAJ}.y" >&2
  else
    echo "Please do: git checkout linux-${MAJ}.y" >&2
  fi
  exit 1
fi

# starts with v
NEXT=$(git tag --sort='-v:refname' | egrep "v${MAJ}" | head -1)

if [ "${NEXT}" = "v${CUR}" ]; then
  # are we uptodate at all?
  echo "Pulling git"
  git pull -q
  NEXT=$(git tag --sort='-v:refname' | egrep "v${MAJ}" | head -1)
fi

echo "Next version: ${NEXT}"
if [ "${NEXT}" = "v${CUR}" ]; then
  echo "Kernel is uptodate, nothing to do" >&2
  exit 1
fi

echo "Creating diff v${CUR}..${NEXT}"
git diff "v${CUR}..${NEXT}" >"${OUT}"
echo "Done: ${OUT}"

posted on 2022-06-09 12:13 UTC in Code | 0 comments | permalink