potatogim / rpms / kernel

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