maketarball.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/bin/sh
  2. # GNU MediaGoblin -- federated, autonomous media hosting
  3. # Copyright (C) 2011, 2012 GNU MediaGoblin Contributors. See AUTHORS.
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero 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 Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. # usage: maketarball [-drh] REVISH
  18. #
  19. # Creates a tarball of the repository at rev REVISH.
  20. # If -d is passed in, then it adds the date to the directory name.
  21. #
  22. # If -r is passed in, then it does some additional things required
  23. # for a release-ready tarball.
  24. #
  25. # If -h is passed in, shows help and exits.
  26. #
  27. # Examples:
  28. #
  29. # ./maketarball v0.0.2
  30. # ./maketarball -d master
  31. # ./maketarball -r v0.0.2
  32. USAGE="Usage: $0 -h | [-dr] REVISH"
  33. REVISH="none"
  34. PREFIX="none"
  35. NOWDATE=""
  36. RELEASE="no"
  37. while getopts ":dhr" opt;
  38. do
  39. case "$opt" in
  40. h)
  41. echo "$USAGE"
  42. echo ""
  43. echo "Creates a tarball of the repository at rev REVISH."
  44. echo ""
  45. echo " -h Shows this help message"
  46. echo " -d Includes date in tar file name and directory"
  47. echo " -r Performs other release-related actions"
  48. exit 0
  49. ;;
  50. d)
  51. NOWDATE=`date "+%Y-%m-%d-"`
  52. shift $((OPTIND-1))
  53. ;;
  54. r)
  55. RELEASE="yes"
  56. shift $((OPTIND-1))
  57. ;;
  58. \?)
  59. echo "Invalid option: -$OPTARG" >&2
  60. echo "$USAGE" >&2
  61. ;;
  62. esac
  63. done
  64. if [[ -z "$1" ]]; then
  65. echo "$USAGE";
  66. exit 1;
  67. fi
  68. REVISH=$1
  69. PREFIX="$NOWDATE$REVISH"
  70. # convert PREFIX to all lowercase and nix the v from tag names.
  71. PREFIX=`echo "$PREFIX" | tr '[A-Z]' '[a-z]' | sed s/v//`
  72. # build the filename base minus the .tar.gz stuff--this is also
  73. # the directory in the tarball.
  74. FNBASE="mediagoblin-$PREFIX"
  75. STARTDIR=`pwd`
  76. function cleanup {
  77. pushd $STARTDIR
  78. if [[ -e tmp ]]
  79. then
  80. echo "+ cleaning up tmp/"
  81. rm -rf tmp
  82. fi
  83. popd
  84. }
  85. echo "+ Building tarball from: $REVISH"
  86. echo "+ Using prefix: $PREFIX"
  87. echo "+ Release?: $RELEASE"
  88. echo ""
  89. if [[ -e tmp ]]
  90. then
  91. echo "+ there's an existing tmp/. please remove it."
  92. exit 1
  93. fi
  94. mkdir $STARTDIR/tmp
  95. echo "+ generating archive...."
  96. git archive \
  97. --format=tar \
  98. --prefix=$FNBASE/ \
  99. $REVISH > tmp/$FNBASE.tar
  100. if [[ $? -ne 0 ]]
  101. then
  102. echo "+ git archive command failed. See above text for reason."
  103. cleanup
  104. exit 1
  105. fi
  106. if [[ $RELEASE = "yes" ]]
  107. then
  108. pushd tmp/
  109. tar -xvf $FNBASE.tar
  110. pushd $FNBASE
  111. pushd docs
  112. echo "+ generating html docs"
  113. make html
  114. if [[ $? -ne 0 ]]
  115. then
  116. echo "+ sphinx docs generation failed. See above text for reason."
  117. cleanup
  118. exit 1
  119. fi
  120. # NOTE: this doesn't work for gmg prior to v0.0.4.
  121. echo "+ generating texinfo docs (doesn't work prior to v0.0.4)"
  122. make info
  123. popd
  124. echo "+ moving docs to the right place"
  125. if [[ -e docs/build/html/ ]]
  126. then
  127. mv docs/build/html/ docs/html/
  128. mv docs/build/texinfo/ docs/texinfo/
  129. rm -rf docs/build/
  130. else
  131. # this is the old directory structure pre-0.0.4
  132. mv docs/_build/html/ docs/html/
  133. rm -rf docs/_build/
  134. fi
  135. # Remove .pyc files that may have been generated by sphinx
  136. find mediagoblin -name '*.pyc' -exec rm {} \;
  137. popd
  138. tar -cvf $FNBASE.tar $FNBASE
  139. popd
  140. fi
  141. echo "+ compressing...."
  142. gzip tmp/$FNBASE.tar
  143. echo "+ archive at tmp/$FNBASE.tar.gz"
  144. echo "+ done."