Skip to content

Instantly share code, notes, and snippets.

@ryanpdwyer
Created February 8, 2022 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanpdwyer/9cc63e1b0dadc4bd94a6f832d25507ac to your computer and use it in GitHub Desktop.
Save ryanpdwyer/9cc63e1b0dadc4bd94a6f832d25507ac to your computer and use it in GitHub Desktop.
#!/bin/sh
readonly hash_algo='sha256'
readonly key='MOK.priv'
readonly x509='MOK.der'
readonly name="$(basename $0)"
readonly esc='\\e'
readonly reset="${esc}[0m"
readonly fullver=$(uname -r)
readonly majorminor="$(echo $fullver | cut -d '.' -f1,2)"
green() { local string="${1}"; echo "${esc}[32m${string}${reset}"; }
blue() { local string="${1}"; echo "${esc}[34m${string}${reset}"; }
log() { local string="${1}"; echo "[$(blue $name)] ${string}"; }
# The exact location of `sign-file` might vary depending on your platform.
# This is for Ubuntu
alias sign-file="/usr/src/linux-headers-$(uname -r)/scripts/sign-file"
[ -z "${KBUILD_SIGN_PIN}" ] && read -p "Passphrase for ${key}: " KBUILD_SIGN_PIN
export KBUILD_SIGN_PIN
# In Debian, modinfo is not in the PATH even for root users. In other
# distributions it may not be located at /sbin
for module in $(dirname $(/sbin/modinfo -n vboxdrv))/*.ko; do
log "Signing $(green ${module})..."
sign-file "${hash_algo}" "${key}" "${x509}" "${module}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment