2018-09-10 15:51:20 +02:00
|
|
|
#!/bin/bash -ex
|
|
|
|
|
2018-09-12 16:44:03 +02:00
|
|
|
usage() {
|
|
|
|
cat << EOF
|
2018-10-23 16:12:16 +02:00
|
|
|
Usage: $PROGNAME [OPTION] LATEST.JSON
|
2018-09-12 16:44:03 +02:00
|
|
|
|
|
|
|
-h, --help Display this help
|
2018-09-13 10:15:54 +02:00
|
|
|
--nosign Don't sign the EFI executable
|
2018-10-19 14:32:53 +02:00
|
|
|
--key KEY Use KEY as certification key for EFI signing
|
|
|
|
--crt CRT Use CRT as certification for EFI signing
|
2018-09-12 16:44:03 +02:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
TEMP=$(
|
|
|
|
getopt -o '' \
|
2018-10-19 14:32:53 +02:00
|
|
|
--long key: \
|
|
|
|
--long crt: \
|
2018-09-13 10:15:54 +02:00
|
|
|
--long nosign \
|
2018-09-13 10:58:26 +02:00
|
|
|
--long notar \
|
2018-10-23 16:12:16 +02:00
|
|
|
--long help \
|
2018-09-12 16:44:03 +02:00
|
|
|
-- "$@"
|
|
|
|
)
|
|
|
|
|
|
|
|
if (( $? != 0 )); then
|
|
|
|
usage >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval set -- "$TEMP"
|
|
|
|
unset TEMP
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
2018-10-19 14:32:53 +02:00
|
|
|
'--key')
|
|
|
|
KEY="$(readlink -e $2)"
|
2018-09-14 11:37:19 +02:00
|
|
|
shift 2; continue
|
|
|
|
;;
|
2018-10-19 14:32:53 +02:00
|
|
|
'--crt')
|
|
|
|
CRT="$(readlink -e $2)"
|
2018-09-12 16:44:03 +02:00
|
|
|
shift 2; continue
|
|
|
|
;;
|
2018-09-13 10:15:54 +02:00
|
|
|
'--nosign')
|
2018-09-14 11:37:19 +02:00
|
|
|
NOSIGN="1"
|
2018-09-13 10:15:54 +02:00
|
|
|
shift 1; continue
|
|
|
|
;;
|
2018-09-13 10:58:26 +02:00
|
|
|
'--notar')
|
2018-09-14 11:37:19 +02:00
|
|
|
NOTAR="1"
|
2018-09-13 10:58:26 +02:00
|
|
|
shift 1; continue
|
|
|
|
;;
|
2018-09-12 16:44:03 +02:00
|
|
|
'--help')
|
2018-09-14 11:37:19 +02:00
|
|
|
usage
|
|
|
|
exit 0
|
2018-09-12 16:44:03 +02:00
|
|
|
;;
|
|
|
|
'--')
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo 'Internal error!' >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2018-10-23 16:12:16 +02:00
|
|
|
PROGNAME=${0##*/}
|
|
|
|
BASEDIR=$(realpath ${0%/*})
|
2018-09-12 16:44:03 +02:00
|
|
|
|
2018-09-10 15:51:20 +02:00
|
|
|
JSON="$(realpath -e $1)"
|
2018-10-23 16:12:16 +02:00
|
|
|
JSONDIR="${JSON%/*}"
|
2018-10-19 14:32:53 +02:00
|
|
|
NAME="$(jq -r '.name' ${JSON})"
|
|
|
|
VERSION="$(jq -r '.version' ${JSON})"
|
2018-10-23 16:12:16 +02:00
|
|
|
ROOTHASH="$(jq -r '.roothash' ${JSON})"
|
|
|
|
IMAGE="${JSONDIR}/${NAME}-${VERSION}"
|
|
|
|
HASH_IMAGE="${JSONDIR}/${NAME}-${ROOTHASH}"
|
2018-10-19 14:32:53 +02:00
|
|
|
CRT=${CRT:-${BASEDIR}/${NAME}.crt}
|
|
|
|
KEY=${KEY:-${BASEDIR}/${NAME}.key}
|
2018-09-10 15:51:20 +02:00
|
|
|
|
2018-09-17 17:32:13 +02:00
|
|
|
pushd "$IMAGE"
|
|
|
|
if ! [[ $NOSIGN ]]; then
|
2018-10-19 14:32:53 +02:00
|
|
|
if ! [[ $KEY ]] || ! [[ $CRT ]]; then
|
|
|
|
echo "Cannot find $KEY and $CRT"
|
|
|
|
echo "Need --key KEY --crt CRT options"
|
2018-09-17 17:32:13 +02:00
|
|
|
exit 1
|
2018-09-13 10:15:54 +02:00
|
|
|
fi
|
2018-09-17 17:32:13 +02:00
|
|
|
for i in $(find . -type f -name '*.efi'); do
|
|
|
|
[[ -f "$i" ]] || continue
|
2018-10-19 14:32:53 +02:00
|
|
|
if ! sbverify --cert "$CRT" "$i" &>/dev/null ; then
|
|
|
|
sbsign --key "$KEY" --cert "$CRT" --output "${i}signed" "$i"
|
2018-09-17 17:32:13 +02:00
|
|
|
mv "${i}signed" "$i"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2018-10-23 16:12:16 +02:00
|
|
|
|
2018-09-17 17:32:13 +02:00
|
|
|
[[ -f sha512sum.txt ]] || sha512sum $(find . -type f) > sha512sum.txt
|
2018-10-19 14:32:53 +02:00
|
|
|
[[ -f sha512sum.txt.sig ]] || openssl dgst -sha256 -sign "$KEY" -out sha512sum.txt.sig sha512sum.txt
|
2018-09-17 17:32:13 +02:00
|
|
|
|
2018-10-23 16:12:16 +02:00
|
|
|
if ! [[ $NOTAR ]]; then
|
|
|
|
[[ -e "$IMAGE".tgz ]] || tar cf - -C "${IMAGE%/*}" "${IMAGE##*/}" | pigz -c > "${IMAGE}.tgz"
|
|
|
|
if ! [[ -e "$HASH_IMAGE-efi".tgz ]]; then
|
|
|
|
tar cf - efi | pigz -c > "$HASH_IMAGE-efi.tgz"
|
|
|
|
fi
|
|
|
|
[[ $NOSIGN ]] || openssl dgst -sha256 -sign "$KEY" \
|
|
|
|
-out "${HASH_IMAGE}-efi.tgz.sig" "${HASH_IMAGE}-efi.tgz"
|
|
|
|
[[ $NOSIGN ]] || openssl dgst -sha256 -sign "$KEY" \
|
|
|
|
-out "${JSONDIR}/${NAME}-${ROOTHASH}.img.sig" "$IMAGE/root.img"
|
2018-09-10 15:51:20 +02:00
|
|
|
fi
|
2018-10-23 16:12:16 +02:00
|
|
|
|
|
|
|
popd
|