VerityBook/mkrelease.sh

88 lines
1.9 KiB
Bash
Raw Normal View History

2018-09-10 15:51:20 +02:00
#!/bin/bash -ex
2018-09-12 16:44:03 +02:00
usage() {
cat << EOF
Usage: $PROGNAME [OPTION]
-h, --help Display this help
2018-09-13 10:15:54 +02:00
--nosign Don't sign the EFI executable
--dbkey KEY Use KEY as certification key for EFI signing
--dbcrt CRT Use CRT as certification for EFI signing
2018-09-12 16:44:03 +02:00
EOF
}
TEMP=$(
getopt -o '' \
--long dbkey: \
--long dbcrt: \
2018-09-13 10:15:54 +02:00
--long nosign \
2018-09-13 10:58:26 +02:00
--long notar \
--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
'--dbkey')
DBKEY="$(readlink -e $2)"
shift 2; continue
;;
'--dbcrt')
DBCRT="$(readlink -e $2)"
2018-09-12 16:44:03 +02:00
shift 2; continue
;;
2018-09-13 10:15:54 +02:00
'--nosign')
NOSIGN="1"
2018-09-13 10:15:54 +02:00
shift 1; continue
;;
2018-09-13 10:58:26 +02:00
'--notar')
NOTAR="1"
2018-09-13 10:58:26 +02:00
shift 1; continue
;;
2018-09-12 16:44:03 +02:00
'--help')
usage
exit 0
2018-09-12 16:44:03 +02:00
;;
'--')
shift
break
;;
*)
echo 'Internal error!' >&2
exit 1
;;
esac
done
2018-09-10 15:51:20 +02:00
JSON="$(realpath -e $1)"
BASEDIR="${JSON%/*}"
IMAGE="${BASEDIR}/$(jq -r '.name' ${JSON})-$(jq -r '.version' ${JSON})"
(
cd "$IMAGE"
2018-09-13 10:15:54 +02:00
if ! [[ $NOSIGN ]]; then
if ! [[ $DBKEY ]] || ! [[ $DBCRT ]]; then
echo "Need --dbkey KEY --dbcrt CRT options"
exit 1
fi
2018-09-14 12:43:15 +02:00
if ! sbverify --cert "$DBCRT" bootx64.efi &>/dev/null ; then
sbsign --key "$DBKEY" --cert "$DBCRT" --output bootx64-signed.efi bootx64.efi
mv bootx64-signed.efi bootx64.efi
fi
2018-09-13 10:15:54 +02:00
fi
2018-09-10 15:51:20 +02:00
[[ -f sha512sum.txt ]] || sha512sum * > sha512sum.txt
[[ -f sha512sum.txt.sig ]] || gpg2 --detach-sign sha512sum.txt
)
2018-09-13 10:58:26 +02:00
if ! [[ $NOTAR ]] && ! [[ -e "$IMAGE".tgz ]]; then
2018-09-10 15:51:20 +02:00
tar cf - -C "${IMAGE%/*}" "${IMAGE##*/}" | pigz -c > "$IMAGE".tgz
fi