Blame SOURCES/mod-sign.sh

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