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