update kernel-builder

Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle 2018-05-28 22:21:15 -04:00
parent d4ce312cc2
commit 73175a0c6a
No known key found for this signature in database
GPG Key ID: 18F3685C0022BFF3
2 changed files with 100 additions and 70 deletions

View File

@ -1,28 +1,21 @@
FROM debian:buster FROM r.j3ss.co/wireguard:install
LABEL maintainer "Jessie Frazelle <jess@linux.com>" LABEL maintainer "Jessie Frazelle <jess@linux.com>"
RUN dpkg --add-architecture arm64 \ RUN apk add --no-cache \
&& dpkg --add-architecture ppc64el \ bash \
&& apt-get update && apt-get install -y \ bc \
bison \ bison \
ca-certificates \ ca-certificates \
cpio \
curl \ curl \
fakeroot \ fakeroot \
flex \ flex \
gnupg \
crossbuild-essential-arm64 \
crossbuild-essential-ppc64el \
gcc \
gcc-7-plugin-dev \
git \ git \
kernel-package \ gmp-dev \
libelf-dev \ libressl-dev \
make \ mpc1-dev \
libncurses5-dev \ mpfr-dev \
libssl-dev \ ncurses-dev \
--no-install-recommends \ tar
&& rm -rf /var/lib/apt/lists/*
ENV HOME /root ENV HOME /root
WORKDIR $HOME WORKDIR $HOME
@ -31,4 +24,4 @@ ENV JOBS 4
COPY build_kernel /usr/local/bin/build_kernel COPY build_kernel /usr/local/bin/build_kernel
CMD [ "bash" ] ENTRYPOINT [ "bash" ]

View File

@ -3,98 +3,135 @@ set -e
set -o pipefail set -o pipefail
linux_next(){ linux_next(){
( local dir="/usr/src/linux-next"
cd /usr/src
# check if we already have the source checked out # Check if we already have the source for linux-next checked out.
if [[ -d linux ]]; then if [[ -d "$dir" ]]; then
cd linux echo "Updating linux-next tree git remotes..."
(
cd "$dir"
git checkout master git checkout master
git remote update git remote update
)
else else
# clone the source files echo "Cloning the git source for linux..."
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git "$dir"
echo "Adding the linux-next git remote..."
(
cd "$dir"
# add the linux-next remote
cd linux
git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
)
# fetch linux-next and tags
git fetch linux-next
git fetch --tags linux-next
fi fi
git checkout -b next-$(date +%Y%m%d) next-$(date +%Y%m%d) echo "Fetching the linux-next remote and updating tags..."
(
cd "$dir"
if [[ ! -f .config ]] && [[ -f ../config ]]; then git fetch linux-next
cp ../config .config git fetch --tags linux-next
fi )
nice -19 make -j$JOBS KDEB_PKGVERSION=$PKGVERSION INSTALL_MOD_STRIP=1 deb-pkg local branch="next-$(date +%Y%m%d)"
echo "Checking out the correct branch ${branch}..."
(
cd "$dir"
git checkout -b "$branch" "$branch"
) )
} }
install_kernel(){ install_kernel(){
local VERSION=$1 local VERSION=$1
local OPT=$2 local OPT=$2
local DIR="/usr/src/linux-${VERSION}"
if [[ -z $VERSION ]]; then if [[ -z $VERSION ]]; then
echo "Please specify a kernel version." echo "Please specify a kernel version."
exit 1 exit 1
elif [[ "$VERSION" == "next" ]]; then elif [[ "$VERSION" == "next" ]]; then
DIR="/usr/src/linux-next"
linux_next linux_next
exit 0
fi fi
local MAJOR_VERSION=${VERSION:0:1} if [[ "$VERSION" != "next" ]]; then
local V=( ${VERSION//./ } ) local MAJOR_VERSION=${VERSION:0:1}
local MAJOR_MINOR_VERSION="${V[0]}.${V[1]}" local V=( ${VERSION//./ } )
local MAJOR_MINOR_VERSION="${V[0]}.${V[1]}"
# get the kernel source # Get the kernel source.
if [[ "$VERSION" == *-rc* ]]; then echo "Getting the kernel source for linux-${VERSION}..."
[ -d /usr/src/linux-${VERSION} ] || curl -sSL "https://git.kernel.org/torvalds/t/linux-${VERSION}.tar.gz" | tar -v -C /usr/src -xz echo "This might take a bit to download. Hang tight!"
if [[ "$VERSION" == *-rc* ]]; then
[ -d "$DIR" ] || curl -sSL "https://git.kernel.org/torvalds/t/linux-${VERSION}.tar.gz" | tar -C /usr/src -xz
MAJOR_MINOR_VERSION="${MAJOR_VERSION}.x-rcN" MAJOR_MINOR_VERSION="${MAJOR_VERSION}.x-rcN"
else else
[ -d /usr/src/linux-${VERSION} ] || curl -sSL "https://cdn.kernel.org/pub/linux/kernel/v${MAJOR_VERSION}.x/linux-${VERSION}.tar.xz" | tar -v -C /usr/src -xJ [ -d /usr/src/linux-${VERSION} ] || curl -sSL "https://cdn.kernel.org/pub/linux/kernel/v${MAJOR_VERSION}.x/linux-${VERSION}.tar.xz" | tar -C /usr/src -xJ
fi fi
if [[ "$OPT" == "aufs" ]]; then # Git clone and apply the patches for the aufs filesystem.
# get the aufs standalone source if [[ "$OPT" == "aufs" ]]; then
aufsdir=/tmp/aufs4-standalone aufsdir=/aufs4-standalone
if [[ -d $aufsdir ]]; then
rm -rf $aufsdir echo "Cloning the git patches for the aufs filesystem..."
git clone --depth 1 --branch aufs${MAJOR_MINOR_VERSION} --single-branch https://github.com/sfjro/aufs4-standalone.git $aufsdir
(
cd "$DIR"
echo "Applying patch for the aufs filesystem..."
git apply $aufsdir/aufs4-kbuild.patch
git apply $aufsdir/aufs4-base.patch
git apply $aufsdir/aufs4-mmap.patch
cp -r $aufsdir/{Documentation,fs} .
cp $aufsdir/include/uapi/linux/aufs_type.h include/uapi/linux/
)
fi fi
git clone --depth 1 --branch aufs${MAJOR_MINOR_VERSION} --single-branch https://github.com/sfjro/aufs4-standalone.git $aufsdir
fi fi
# apply the patches and compile the kernel
cd /usr/src/linux-${VERSION}
# apply the patches # Install Wireguard VPN into the kernel.
if [[ "$OPT" == "aufs" ]]; then if [[ ! -f "${DIR}/net/wireguard/allowedips.c" ]]; then
git apply $aufsdir/aufs4-kbuild.patch echo "Applying patch for Wireguard VPN..."
git apply $aufsdir/aufs4-base.patch (
git apply $aufsdir/aufs4-mmap.patch cd "$DIR"
cp -r $aufsdir/{Documentation,fs} . /wireguard/contrib/kernel-tree/create-patch.sh | patch -p1
cp $aufsdir/include/uapi/linux/aufs_type.h include/uapi/linux/ )
echo "Patch for Wireguard VPN successfully applied!"
else
echo "Patch for Wireguard VPN has already been applied!"
fi fi
if [[ "$OPT" == "aufs" ]]; then # Copy the config from /usr/src/config if it does not already exist.
# remove aufs source if [[ ! -f "${DIR}/.config" ]] && [[ -f "/usr/src/config" ]]; then
rm -rf $aufsdir (
fi cd "$DIR"
if [[ ! -f .config ]] && [[ -f ../config ]]; then
cp ../config .config cp ../config .config
# Add the config options for the aufs filesystem.
if [[ "$OPT" == "aufs" ]]; then if [[ "$OPT" == "aufs" ]]; then
echo "CONFIG_AUFS_FS=y" >> .config echo "CONFIG_AUFS_FS=y" >> .config
fi fi
# Add the config options for Wireguard VPN.
echo "CONFIG_WIREGUARD=y" >> .config
)
fi fi
nice -19 make -j$JOBS KDEB_PKGVERSION=$PKGVERSION DISABLE_PAX_PLUGINS=y INSTALL_MOD_STRIP=1 deb-pkg (
cd "$DIR"
echo "Building the kernel..."
make -j$JOBS
echo "Installing the modules..."
make modules_install
echo "Installing the kernel..."
make install
)
} }
install_kernel $@ install_kernel $@