helper/buildCurrentSymlinkedKernel.sh

97 lines
2.3 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 [ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]; then
CHROOTED=1
fi
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 "$OLDCONFIG" > .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") > "buildlog-$TIMESTAMP" || tail -n 20 "buildlog-$TIMESTAMP"
SUCCESS=$?
if [[ $SUCCESS == 0 ]] && [[ $CHROOTED == 1 ]] ; then
( make tarxz-pkg ) >> "buildlog-$TIMESTAMP"
elif [[ $SUCCESS == 0 ]] ; then
( make install ; make modules_install ) >> "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
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