Update metadata_display plugin for Python 3.
[mediagoblin.git] / devtools / maketarball.sh
1 #!/bin/sh
2
3 # GNU MediaGoblin -- federated, autonomous media hosting
4 # Copyright (C) 2011, 2012 GNU MediaGoblin Contributors. See AUTHORS.
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
20 # usage: maketarball [-drh] REVISH
21 #
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.
30 #
31 # Examples:
32 #
33 # ./maketarball v0.0.2
34 # ./maketarball -d master
35 # ./maketarball -r v0.0.2
36
37
38 USAGE="Usage: $0 -h | [-dr] REVISH"
39
40 REVISH="none"
41 PREFIX="none"
42 NOWDATE=""
43 RELEASE="no"
44
45 while getopts ":dhr" opt;
46 do
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
71 done
72
73 if [[ -z "$1" ]]; then
74 echo "$USAGE";
75 exit 1;
76 fi
77
78 REVISH=$1
79 PREFIX="$NOWDATE$REVISH"
80
81 # convert PREFIX to all lowercase and nix the v from tag names.
82 PREFIX=`echo "$PREFIX" | tr '[A-Z]' '[a-z]' | sed s/v//`
83
84 # build the filename base minus the .tar.gz stuff--this is also
85 # the directory in the tarball.
86 FNBASE="mediagoblin-$PREFIX"
87
88 STARTDIR=`pwd`
89
90 function 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 }
100
101 echo "+ Building tarball from: $REVISH"
102 echo "+ Using prefix: $PREFIX"
103 echo "+ Release?: $RELEASE"
104
105 echo ""
106
107 if [[ -e tmp ]]
108 then
109 echo "+ there's an existing tmp/. please remove it."
110 exit 1
111 fi
112
113 mkdir $STARTDIR/tmp
114 echo "+ generating archive...."
115 git archive \
116 --format=tar \
117 --prefix=$FNBASE/ \
118 $REVISH > tmp/$FNBASE.tar
119
120 if [[ $? -ne 0 ]]
121 then
122 echo "+ git archive command failed. See above text for reason."
123 cleanup
124 exit 1
125 fi
126
127
128 if [[ $RELEASE = "yes" ]]
129 then
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 ]]
139 then
140 echo "+ sphinx docs generation failed. See above text for reason."
141 cleanup
142 exit 1
143 fi
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
158 # this is the old directory structure pre-0.0.4
159 mv docs/_build/html/ docs/html/
160
161 rm -rf docs/_build/
162 fi
163
164 # Remove .pyc files that may have been generated by sphinx
165 find mediagoblin -name '*.pyc' -exec rm {} \;
166
167 popd
168
169 tar -cvf $FNBASE.tar $FNBASE
170 popd
171 fi
172
173
174 echo "+ compressing...."
175 gzip tmp/$FNBASE.tar
176
177 echo "+ archive at tmp/$FNBASE.tar.gz"
178
179 echo "+ done."