2015-06-06 03:18:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2017-04-27 22:58:43 +02:00
|
|
|
set -o pipefail
|
2015-06-06 03:18:27 +02:00
|
|
|
|
2015-09-11 00:39:22 +02:00
|
|
|
linux_next(){
|
2018-05-29 04:21:15 +02:00
|
|
|
local dir="/usr/src/linux-next"
|
2015-09-11 00:39:22 +02:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
# Check if we already have the source for linux-next checked out.
|
|
|
|
if [[ -d "$dir" ]]; then
|
|
|
|
echo "Updating linux-next tree git remotes..."
|
|
|
|
(
|
|
|
|
cd "$dir"
|
2015-09-11 00:39:22 +02:00
|
|
|
|
|
|
|
git checkout master
|
|
|
|
git remote update
|
2018-05-29 04:21:15 +02:00
|
|
|
)
|
2015-09-11 00:39:22 +02:00
|
|
|
else
|
2018-05-29 04:21:15 +02:00
|
|
|
echo "Cloning the git source for linux..."
|
|
|
|
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git "$dir"
|
2015-09-11 00:39:22 +02:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
echo "Adding the linux-next git remote..."
|
|
|
|
(
|
|
|
|
cd "$dir"
|
2015-09-11 00:39:22 +02:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
|
|
|
|
)
|
2015-09-11 00:39:22 +02:00
|
|
|
fi
|
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
echo "Fetching the linux-next remote and updating tags..."
|
|
|
|
(
|
|
|
|
cd "$dir"
|
2016-03-18 00:34:38 +01:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
git fetch linux-next
|
|
|
|
git fetch --tags linux-next
|
|
|
|
)
|
|
|
|
|
2018-09-25 01:31:37 +02:00
|
|
|
local branch
|
|
|
|
branch="next-$(date +%Y%m%d)"
|
2018-05-29 04:21:15 +02:00
|
|
|
echo "Checking out the correct branch ${branch}..."
|
|
|
|
(
|
|
|
|
cd "$dir"
|
2015-09-11 00:39:22 +02:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
git checkout -b "$branch" "$branch"
|
2015-09-11 00:39:22 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2015-06-06 03:18:27 +02:00
|
|
|
install_kernel(){
|
|
|
|
local VERSION=$1
|
2016-03-23 18:42:00 +01:00
|
|
|
local OPT=$2
|
2018-05-29 04:21:15 +02:00
|
|
|
local DIR="/usr/src/linux-${VERSION}"
|
2015-06-06 03:18:27 +02:00
|
|
|
|
|
|
|
if [[ -z $VERSION ]]; then
|
|
|
|
echo "Please specify a kernel version."
|
|
|
|
exit 1
|
2015-09-11 00:39:22 +02:00
|
|
|
elif [[ "$VERSION" == "next" ]]; then
|
2018-05-29 04:21:15 +02:00
|
|
|
DIR="/usr/src/linux-next"
|
2015-09-11 00:39:22 +02:00
|
|
|
linux_next
|
2015-06-06 03:18:27 +02:00
|
|
|
fi
|
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
if [[ "$VERSION" != "next" ]]; then
|
|
|
|
local MAJOR_VERSION=${VERSION:0:1}
|
2018-09-25 01:31:37 +02:00
|
|
|
local V=( "${VERSION//./ }" )
|
2018-05-29 04:21:15 +02:00
|
|
|
local MAJOR_MINOR_VERSION="${V[0]}.${V[1]}"
|
2015-09-03 06:33:43 +02:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
# Get the kernel source.
|
|
|
|
echo "Getting the kernel source for linux-${VERSION}..."
|
|
|
|
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
|
2015-09-11 00:39:22 +02:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
MAJOR_MINOR_VERSION="${MAJOR_VERSION}.x-rcN"
|
|
|
|
else
|
2018-09-25 01:31:37 +02:00
|
|
|
[ -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
|
2018-05-29 04:21:15 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Git clone and apply the patches for the aufs filesystem.
|
2018-05-29 17:23:08 +02:00
|
|
|
if [[ "$OPT" == "aufs" ]] && [[ ! -d "${DIR}/fs/aufs" ]]; then
|
2018-05-29 04:21:15 +02:00
|
|
|
aufsdir=/aufs4-standalone
|
2015-06-06 03:18:27 +02:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
echo "Cloning the git patches for the aufs filesystem..."
|
2018-09-25 01:31:37 +02:00
|
|
|
git clone --depth 1 --branch "aufs${MAJOR_MINOR_VERSION}" --single-branch https://github.com/sfjro/aufs4-standalone.git "$aufsdir"
|
2018-05-29 04:21:15 +02:00
|
|
|
|
|
|
|
(
|
|
|
|
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/
|
|
|
|
)
|
2016-03-23 18:42:00 +01:00
|
|
|
fi
|
2015-09-03 06:33:43 +02:00
|
|
|
fi
|
|
|
|
|
2015-06-06 03:18:27 +02:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
# Install Wireguard VPN into the kernel.
|
2018-06-25 20:46:30 +02:00
|
|
|
if [[ "$OPT" == "wireguard" ]] && [[ ! -f "${DIR}/net/wireguard/allowedips.c" ]]; then
|
2018-05-29 04:21:15 +02:00
|
|
|
echo "Applying patch for Wireguard VPN..."
|
|
|
|
(
|
|
|
|
cd "$DIR"
|
|
|
|
/wireguard/contrib/kernel-tree/create-patch.sh | patch -p1
|
|
|
|
)
|
|
|
|
echo "Patch for Wireguard VPN successfully applied!"
|
2016-03-23 18:42:00 +01:00
|
|
|
fi
|
2015-09-03 06:33:43 +02:00
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
# Copy the config from /usr/src/config if it does not already exist.
|
|
|
|
if [[ ! -f "${DIR}/.config" ]] && [[ -f "/usr/src/config" ]]; then
|
|
|
|
(
|
|
|
|
cd "$DIR"
|
2015-09-03 06:33:43 +02:00
|
|
|
|
2015-06-16 21:52:08 +02:00
|
|
|
cp ../config .config
|
2018-05-29 04:21:15 +02:00
|
|
|
|
|
|
|
# Add the config options for the aufs filesystem.
|
2016-03-23 18:42:00 +01:00
|
|
|
if [[ "$OPT" == "aufs" ]]; then
|
|
|
|
echo "CONFIG_AUFS_FS=y" >> .config
|
|
|
|
fi
|
2018-05-29 04:21:15 +02:00
|
|
|
|
|
|
|
# Add the config options for Wireguard VPN.
|
2018-06-25 20:46:30 +02:00
|
|
|
if [[ "$OPT" == "wireguard" ]]; then
|
|
|
|
echo "CONFIG_WIREGUARD=y" >> .config
|
|
|
|
fi
|
2018-05-29 04:21:15 +02:00
|
|
|
)
|
2015-06-16 21:52:08 +02:00
|
|
|
fi
|
|
|
|
|
2018-05-29 04:21:15 +02:00
|
|
|
(
|
|
|
|
cd "$DIR"
|
|
|
|
|
|
|
|
echo "Building the kernel..."
|
2018-09-25 01:31:37 +02:00
|
|
|
make -j"$JOBS"
|
2018-05-29 04:21:15 +02:00
|
|
|
echo "Installing the modules..."
|
|
|
|
make modules_install
|
|
|
|
echo "Installing the kernel..."
|
|
|
|
make install
|
|
|
|
)
|
2018-07-04 18:16:55 +02:00
|
|
|
(
|
|
|
|
echo "Stripping the modules..."
|
2018-09-25 01:31:37 +02:00
|
|
|
find /lib/modules/ -name "*.ko" -exec strip --strip-unneeded {} +
|
2018-07-04 18:16:55 +02:00
|
|
|
)
|
2015-06-06 03:18:27 +02:00
|
|
|
}
|
|
|
|
|
2018-09-25 01:17:06 +02:00
|
|
|
# shellcheck disable=SC2068
|
2015-06-06 03:18:27 +02:00
|
|
|
install_kernel $@
|
2018-05-29 17:23:08 +02:00
|
|
|
|
|
|
|
echo "Kernel successfully installed!"
|
2018-05-29 17:55:03 +02:00
|
|
|
echo "You will now want to run:"
|
2018-05-29 18:00:08 +02:00
|
|
|
echo " update-initramfs -u -k all"
|
|
|
|
echo "and"
|
|
|
|
echo " update-grub2"
|
2018-05-29 17:23:08 +02:00
|
|
|
echo "or the equivalent for your system."
|