Skip to content

Instantly share code, notes, and snippets.

@nihilismus
Last active November 26, 2016 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nihilismus/12a10ec3152dadd069ff to your computer and use it in GitHub Desktop.
Save nihilismus/12a10ec3152dadd069ff to your computer and use it in GitHub Desktop.
Script to download, verify (sha256sum), uncompress and prepare a Linux kernel source tarball.
#!/bin/sh
# Copyright © 2016 Antonio Hernández Blas <hba.nihilismus@gmail.com>
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
me=$(basename $0)
mayor_version=$(echo $1 | cut -d '.' -f 1)
minor_version=$(echo $1 | cut -d '.' -f 2)
bugfix_version=$(echo $1 | cut -d '.' -f 3 | sed 's/-.*//')
newfix_version=$(echo $1 | sed 's/.*-//')
old_version=${mayor_version}.${minor_version}.${bugfix_version}
new_version=${mayor_version}.${minor_version}.${newfix_version}
old_source=linux-${mayor_version}.${minor_version}.${bugfix_version}
new_source=linux-${mayor_version}.${minor_version}.${newfix_version}
patch_name=patch-$1
if [ "${old_source}" = "linux-" ]; then
echo " $me: Error, version must be specified, example: 3.18.13-14"
exit 1
fi
if ! $(echo $1 | grep -q '\-'); then
echo " $me: Error, version must be *corrrectly* specified, example: 3.18.13-14"
exit 1
fi
if [ ! -d "${old_source}" ]; then
echo " $me: Error, directory '"${old_source}"' does not exists"
exit 1
fi
if [ -d "${new_source}" ]; then
echo " $me: Error, directory '"${new_source}"' already exists"
exit 1
fi
set -u
set -e
set -x
wget -c https://cdn.kernel.org/pub/linux/kernel/v${mayor_version}.x/incr/${patch_name}.xz && \
wget -c https://cdn.kernel.org/pub/linux/kernel/v${mayor_version}.x/incr/sha256sums.asc -O sha256sums.asc && \
grep -a ${patch_name}.xz sha256sums.asc > ${patch_name}.xz.sha256 && \
sha256sum -c ${patch_name}.xz.sha256 && \
rm sha256sums.asc && \
cp -rf ${old_source} ${new_source} && \
xzcat ${patch_name}.xz > ${new_source}/${patch_name}.diff && \
cd ${new_source} && \
patch -p1 < ${patch_name}.diff && \
make oldconfig
#!/bin/sh
# Copyright © 2016 Antonio Hernández Blas <hba.nihilismus@gmail.com>
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
me=$(basename $0)
source="https://www.kernel.org"
identify_release() {
while read release; do
if $(echo "$(uname -r)" | grep -qE "^${release}"); then
echo "** ${release}"
continue
fi
echo " ${release}"
done
echo "** $(uname -r)"
}
set -u
set -e
wget -o /dev/null ${source} -O - | \
grep '<td><strong>' | \
grep '</strong></td>' | \
sed 's:.*<td><strong>::' | \
sed 's:</strong></td>.*::' | \
sed 's: .*$::' | \
sed 's:^: :' | \
identify_release
#!/bin/sh
# Copyright © 2015 Antonio Hernández Blas <hba.nihilismus@gmail.com>
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
me=$(basename $0)
version=$1
mainline=$(echo $1 | cut -d '.' -f 1)
if [ -z "${version}" ]; then
echo " $me: Error, version must be specified. Example: 3.18.13"
exit 1
fi
set -u
set -e
set -x
wget -c https://www.kernel.org/pub/linux/kernel/v${mainline}.x/linux-${version}.tar.xz && \
wget -c https://www.kernel.org/pub/linux/kernel/v${mainline}.x/sha256sums.asc && \
grep "\-${version}.tar.xz" sha256sums.asc > linux-${version}.tar.xz.sha256 && \
sha256sum -c linux-${version}.tar.xz.sha256 && \
rm sha256sums.asc && \
tar xf linux-${version}.tar.xz && \
cat /boot/config > linux-${version}/.config && \
cd linux-${version} && \
make oldconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment