make_archive.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env bash
  2. USAGE="Usage:\n\
  3. $(basename "$0") <version-number>\n\
  4. Arguments:\n\
  5. version-number: Version number to use for the archive.\n\
  6. There is currently no logic to infer or check this for you, make sure to check the \`releases\` directory to make sure your version is larger than existing versions and does not overwrite them.\n\
  7. Options:\n\
  8. -h: displays help message."
  9. PACKAGE_NAME="freie-fraktur"
  10. # Reads options
  11. while getopts "h" flag
  12. do
  13. case "$flag" in
  14. h)
  15. echo -e "$USAGE"
  16. exit 0
  17. ;;
  18. \?)
  19. echo "Invalid option: -$OPTARG" >&2
  20. exit 1
  21. ;;
  22. :)
  23. echo "Option -$OPTARG requires an argument." >&2
  24. exit 1
  25. ;;
  26. esac
  27. done
  28. # shifts pointer to read mandatory version number specification
  29. shift $((OPTIND - 1))
  30. VERSION="${1}"
  31. # checks for correct output file specification
  32. if [ -z "$VERSION" ]
  33. then
  34. echo "$(basename "$0"): no archive version specified."
  35. echo -e "$USAGE"
  36. exit 1
  37. fi
  38. echo "This is ./make_archive.sh working on the \`${PACKAGE_NAME}\` package."
  39. ARCHIVE_NAME="${PACKAGE_NAME}-${VERSION}"
  40. ARCHIVE_DIR="/tmp/${ARCHIVE_NAME}"
  41. SCRIPT_DIR="$(dirname "$0")/"
  42. RELEASE_DIR="${SCRIPT_DIR}../releases/"
  43. echo "Creating temporary archive directory under \`${ARCHIVE_DIR}\`."
  44. mkdir "${ARCHIVE_DIR}"
  45. cp "${SCRIPT_DIR}../README.md" "${ARCHIVE_DIR}"
  46. # `-L` is important here, as the data is recorded in datalad and otherwise only the (relative!) symlinks will be copied.
  47. cp -rL "${SCRIPT_DIR}../doc" "${ARCHIVE_DIR}"
  48. cp -rL "${SCRIPT_DIR}../fonts" "${ARCHIVE_DIR}"
  49. pushd "${ARCHIVE_DIR}" &> /dev/null
  50. echo "# Font Package Release \`${ARCHIVE_NAME}\`
  51. Note that this is a font package release, and does not include associated scripts or a package-wide license (individual font licences are to be found in the documentation directory).
  52. This message was autogenerated during archive creation.
  53. " | cat - README.md | tee README.md &> /dev/null
  54. popd &> /dev/null
  55. echo " ✔"
  56. echo "Creating release archive \`${ARCHIVE_NAME}.tar.xz\`."
  57. # `-C` is important here, as otherwise the full path would be encoded into the tar archive (i.e. including the `tmp/` prefix)
  58. tar cJf "${RELEASE_DIR}${ARCHIVE_NAME}.tar.xz" -C $(dirname ${ARCHIVE_DIR}) $(basename ${ARCHIVE_DIR})
  59. echo " ✔"
  60. echo "Cleaning up.."
  61. rm -rf "${ARCHIVE_DIR}"
  62. echo " 💛"