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