You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
2.8KB

  1. #!/usr/bin/env bash
  2. #
  3. # Copyright 2019, David Runge
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. #
  18. # Creates assets for $upstream based on a provided tag in the form of
  19. # ${output_package_name}-${version}.tar.gz' and moves the file to
  20. # ${output_dir}.
  21. # Optionally creates a detached PGP signature for the tarball.
  22. # Requires a writable /tmp folder.
  23. set -euo pipefail
  24. get_absolute_path() {
  25. cd "$(dirname "$0")" && pwd -P
  26. }
  27. remove_source_dir() {
  28. rm -rf "${source_dir:?}/${package_name}"* \
  29. "${source_dir:?}/${output_package_name}"*
  30. }
  31. checkout_project() {
  32. remove_source_dir
  33. cd "${source_dir}"
  34. git clone "$upstream" --recursive
  35. cd "${package_name}"
  36. git checkout "${version}"
  37. }
  38. clean_sources() {
  39. cd "${source_dir}/${package_name}"
  40. find . \( -iname "*.git*" -o \
  41. -iname "*.clang-format" -o \
  42. -iname "*.travis.yml" -o \
  43. -iname "*create_assets.sh" \) \
  44. -exec rm -rfv {} +
  45. }
  46. rename_sources() {
  47. cd "${source_dir}"
  48. mv -v "${package_name}" "${output_package_name}-${version}"
  49. }
  50. compress_sources() {
  51. cd "${source_dir}"
  52. tar cvfz "${output_package_name}-${version}.tar.gz" \
  53. "${output_package_name}-${version}"
  54. }
  55. move_sources() {
  56. cd "${source_dir}"
  57. mv -v "${output_package_name}-${version}.tar.gz" "${output_dir}/"
  58. }
  59. sign_sources() {
  60. cd "${output_dir}"
  61. gpg2 --default-key "${signer}" \
  62. --output "${output_package_name}-${version}.tar.gz.asc" \
  63. --detach-sign "${output_package_name}-${version}.tar.gz"
  64. }
  65. cleanup_source_dir() {
  66. cd "${source_dir}"
  67. rm -rf "${output_package_name}-${version}"
  68. }
  69. print_help() {
  70. echo "Usage: $0 -v <version tag> -s <signature email>"
  71. exit 1
  72. }
  73. upstream="https://github.com/vcvrack/rack"
  74. package_name="rack"
  75. output_package_name="rack"
  76. source_dir="/tmp"
  77. version=$(date "+%Y-%m-%d")
  78. signer=""
  79. output_dir=$(get_absolute_path "$0")
  80. if [ ${#@} -gt 0 ]; then
  81. while getopts 'hv:s:' flag; do
  82. case "${flag}" in
  83. h) print_help
  84. ;;
  85. s) signer=$OPTARG
  86. ;;
  87. v) version=$OPTARG
  88. ;;
  89. *)
  90. echo "Error! Try '${0} -h'."
  91. exit 1
  92. ;;
  93. esac
  94. done
  95. else
  96. print_help
  97. fi
  98. checkout_project
  99. clean_sources
  100. rename_sources
  101. compress_sources
  102. move_sources
  103. if [ -n "${signer}" ]; then
  104. sign_sources
  105. fi
  106. cleanup_source_dir
  107. exit 0
  108. # vim:set ts=2 sw=2 et: