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