potatogim / rpms / kernel

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