pengqianheng / rpms / kernel

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