misc/linux/build-and-push.sh
Georg Pfuetzenreuter 852c2e4699
Add kernel build and install scripts
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2024-08-23 15:05:08 +02:00

88 lines
2.5 KiB
Bash
Executable File

#!/bin/ksh
# Sloppy tool to assist with Linux kernel bisection
#
# 1. Resets upstream kernel sources
# 2. Applies SUSE patches on upstream Linux sources
# 3. Builds Linux
# 4. Copies result to a target over SSH
# 5. Installs result on target, including initrd (Dracut) and boot entry (GRUB)
#
# Copyright 2024 Georg Pfuetzenreuter <mail+opensuse@georg-pfuetzenreuter.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -Ceux
GIT_LINUX=~/Work/git/linux
GIT_LINUX_PATCHES=~/Work/git/kernel-source
LINUX_BUILD=~/Work/kernel-build
LINUX_CONFIG=default
LINUX_VERSION=6.4.0-"$LINUX_CONFIG"-dirty
TARGET_USER=root
TARGET_HOST=192.168.5.92
TARGET_HOST_IP="$TARGET_HOST"/24
TARGET_PIPE=/run/user/"$(id -u)"/bisect
TARGET_BUILD=/tmp/build
SSH_KEY=~/.ssh/bisect.pub
SSH="ssh -i $SSH_KEY -q -l $TARGET_USER $TARGET_HOST"
if ! $SSH -- true
then
echo "Host $TARGET_HOST is not ready."
exit 1
fi
GIT_COMMIT="$(git -C "$GIT_LINUX_PATCHES" rev-parse --short HEAD)"
LINUX_BUILD="$LINUX_BUILD"/"$GIT_COMMIT"
if [ -d "$LINUX_BUILD" ]
then
echo "Commit $GIT_COMMIT has already been built!"
exit 1
fi
install -dv "$LINUX_BUILD"
pushd "$GIT_LINUX"
git clean -df
git restore .
"$GIT_LINUX_PATCHES"/rpm/apply-patches "$GIT_LINUX_PATCHES"/series.conf "$GIT_LINUX_PATCHES"
popd
install -vm0644 "$GIT_LINUX_PATCHES"/config/x86_64/"$LINUX_CONFIG" "$LINUX_BUILD"/.config
make -C"$GIT_LINUX" -j"$(nproc)" O="$LINUX_BUILD"
$SSH -- rm -fr "$TARGET_BUILD"
rsync --exclude='.tmp*' --info=progress2 -lr "$LINUX_BUILD"/ "$TARGET_USER"@"$TARGET_HOST":"$TARGET_BUILD"
$SSH -- make -C/usr/src/linux O="$TARGET_BUILD" modules_install
$SSH -- make -C/usr/src/linux O="$TARGET_BUILD" install
VMLINUZ=/boot/vmlinuz-"$GIT_COMMIT"
INITRD=/boot/initrd-"$GIT_COMMIT"
$SSH -- install -vm0644 "$TARGET_BUILD"/arch/x86/boot/bzImage "$VMLINUZ"
$SSH -- dracut --kernel-image "$VMLINUZ" "$INITRD" "$LINUX_VERSION"
$SSH -- grub2-mkconfig -o /boot/grub2/grub.cfg
ROOT="$($SSH -- blkid -o value -s UUID -t LABEL=ROOT)"
echo "Root partition UUID: $ROOT"
echo 'Now reboot, test, and update the bisection.'