helper/buildCurrentSymlinkedKernel.sh

73 lines
1.6 KiB
Bash
Executable file

#!/usr/bin/env bash
SRC_TREE="/usr/src/linux"
SRC_CONFIG=".config"
declare -a OUT
LWD="$PWD"
cd "$SRC_TREE" || exit 1
if [[ ! -f $SRC_CONFIG ]] ; then
NOCONFIG="1"
fi
if [[ "$1" == "--force" ]] ; then
FORCE="1"
fi
if [[ -f /proc/config.gz ]] ; then
OLDCONFIG="1"
fi
if [[ "$NOCONFIG" || "$FORCE" ]] ; then
echo "**************** building kernel ***********"
TIMESTAMP=$(date +%F-%H_%M_%S)
if [[ "$NOCONFIG" ]] ; then
if [[ "$OLDCONFIG" ]] ; then
OUT+=("********** Using old config ************")
echo "${OUT[-1]}"
zcat /proc/config.gz > .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
(make -j17 -l15 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 /proc/config.gz )
fi
cd "${LWD}" || exit 1
emerge @module-rebuild