sign.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. manifest="$1"
  3. keyfile="$2"
  4. if [ $# != 2 ]; then
  5. echo "Usage: `basename $0` manifest_file keyfile" >&2
  6. exit 1
  7. fi
  8. if [ ! -w "${manifest}" ]; then
  9. echo "ERROR: Manifest \"${manifest}\" does not exists or is not writeable!" >&2
  10. exit 1
  11. fi
  12. if [ ! -r "${keyfile}" ]; then
  13. echo "ERROR: Keyfile \"${keyfile}\" does not exist or is not readable!" >&2
  14. exit 1
  15. fi
  16. echo -en "Signing '${manifest}' with '${keyfile}' using ECDSA, this might take some time ... "
  17. BRANCH=$(grep -i branch "${manifest}" | cut -d"=" -f 2)
  18. upper="$(mktemp)"
  19. lower="$(mktemp)"
  20. awk "BEGIN { sep=0 }
  21. /^---\$/ { sep=1; next }
  22. { if(sep==0) print > \"$upper\";
  23. else print > \"$lower\"}" \
  24. "${manifest}"
  25. if type "ecdsautil" > /dev/null 2>&1; then
  26. ecdsautil sign "${upper}" < "${keyfile}" >> "${lower}"
  27. elif type "ecdsasign" > /dev/null 2>&1; then
  28. ecdsasign "${upper}" < "${keyfile}" >> "${lower}"
  29. else
  30. echo "ERROR: ecdsautil not found" >&2
  31. exit 1
  32. fi
  33. cat "${upper}" > "${manifest}"
  34. echo --- >> "${manifest}"
  35. cat "${lower}" >> "${manifest}"
  36. rm -f -- "${upper}" "${lower}"
  37. echo "done"