chengshan / rpms / kernel

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