alexl / rpms / kernel-automotive

Forked from rpms/kernel-automotive 2 years ago
Clone

Blame SOURCES/mod-sign.sh

6bca4c
#! /bin/bash
6bca4c
6bca4c
# The modules_sign target checks for corresponding .o files for every .ko that
6bca4c
# is signed. This doesn't work for package builds which re-use the same build
6bca4c
# directory for every variant, and the .config may change between variants.
6bca4c
# So instead of using this script to just sign lib/modules/$KernelVer/extra,
6bca4c
# sign all .ko in the buildroot.
6bca4c
6bca4c
# This essentially duplicates the 'modules_sign' Kbuild target and runs the
6bca4c
# same commands for those modules.
6bca4c
6bca4c
MODSECKEY=$1
6bca4c
MODPUBKEY=$2
6bca4c
moddir=$3
6bca4c
6bca4c
modules=$(find "$moddir" -type f -name '*.ko')
6bca4c
6bca4c
NPROC=$(nproc)
6bca4c
[ -z "$NPROC" ] && NPROC=1
6bca4c
6bca4c
# NB: this loop runs 2000+ iterations. Try to be fast.
6bca4c
echo "$modules" | xargs -r -n16 -P $NPROC sh -c "
6bca4c
for mod; do
6bca4c
    ./scripts/sign-file sha256 $MODSECKEY $MODPUBKEY \$mod
6bca4c
    rm -f \$mod.sig \$mod.dig
6bca4c
done
6bca4c
" DUMMYARG0   # xargs appends ARG1 ARG2..., which go into $mod in for loop.
6bca4c
6bca4c
RANDOMMOD=$(echo "$modules" | sort -R | head -n 1)
6bca4c
if [ "~Module signature appended~" != "$(tail -c 28 "$RANDOMMOD")" ]; then
6bca4c
    echo "*****************************"
6bca4c
    echo "*** Modules are unsigned! ***"
6bca4c
    echo "*****************************"
6bca4c
    exit 1
6bca4c
fi
6bca4c
6bca4c
exit 0