l30013671 / rpms / kernel

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