helper/buildCurrentSymlinkedKernel.sh
layman 30dc18a5dc buildCurrentSymlinkedKernel: add support for chroot build
Save config to /etc/kernelconf and use it for rebuilds. this should
prevent raceconditions between enabling a feature and rebooting and
upgrading the kernel. (the upgraded kernel should no be based on the new
feature build.)
2019-06-25 10:35:39 +02:00

87 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
SRC_TREE="/usr/src/linux"
SRC_CONFIG=".config"
CONFIGDIR="/etc/kernelconf"
declare -a OUT
umask 022
LWD="$PWD"
cd "$SRC_TREE" || exit 1
if [[ ! -f $SRC_CONFIG ]] ; then
NOCONFIG="1"
fi
if [[ "$1" == "--force" ]] ; then
FORCE="1"
fi
for config in "/proc/config.gz" "$CONFIGDIR/latest" ; do
if [[ -f "$config" ]] ; then
OLDCONFIG="$config"
fi
done
if [[ "$NOCONFIG" || "$FORCE" ]] ; then
echo "**************** building kernel ***********"
TIMESTAMP=$(date +%F-%H_%M_%S)
if [[ "$NOCONFIG" ]] ; then
if [[ -n "$OLDCONFIG" ]] ; then
OUT+=("********** Using old config ************")
echo "${OUT[-1]}"
zcat -f "$config" > .config
else
OUT+=("********** WARNING! No old config has been found! Using defconfig! ************")
echo "${OUT[-1]}"
make defconfig
fi
else
OUT+=("Found kernel config in source tree!")
echo "${OUT[-1]}"
fi
make olddefconfig
echo mounting boot if not yet mounted
mount /boot 2> /dev/null
CORES="$(getconf _NPROCESSORS_ONLN)"
(nice make -j -l$((CORES-1)) CC="ccache gcc" && make install ; make modules_install) > "buildlog-$TIMESTAMP" || tail -n 20 "buildlog-$TIMESTAMP"
GRUBMKONFIG="$(which grub2-mkconfig 2> /dev/null)"
if [[ -z "$GRUBMKONFIG" ]] ; then
GRUBMKONFIG="$(which grub-mkconfig)"
fi
if [[ -f /boot/grub2/grub.cfg && -n "$GRUBMKONFIG" ]] ; then
"$GRUBMKONFIG" -o /boot/grub2/grub.cfg
elif [[ -f /boot/grub/grub.cfg && -n "$GRUBMKONFIG" ]] ; then
"$GRUBMKONFIG" -o /boot/grub/grub.cfg
else
echo "please update bootloader manually!"
fi
echo
echo
echo Summary:
IFS=$'\n' echo -e "${OUT[*]}"
echo diff between current running und last build config:
diff .config <(zcat -f "${OLDCONFIG}" )
if [[ -d "$CONFIGDIR" ]] ; then
VERSIONSTRING=$(basename $(realpath $(pwd)))
TARGET="$CONFIGDIR/${VERSIONSTRING}_$(date --iso=minutes)"
cp .config "$TARGET"
ln -f -rs "$TARGET" "$CONFIGDIR/latest"
fi
fi
cd "${LWD}" || exit 1
emerge @module-rebuild