3 # Copyright (C) 2009-2010 Free Software Foundation, Inc.
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.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Usage: convert-archive FROM TO [FROMFILE [TOFILE]]
20 # where FROM is dir or cvs or git
21 # and TO is dir or cvs or git
22 # This will read FROMFILE (default: archive.$FROM.tar.gz)
23 # and produce TOFILE (default: archive.$TO.tar.gz).
30 # outputs to stdout the --help usage message.
34 Usage: convert-archive FROM TO [FROMFILE [TOFILE]]
36 Converts the archive of gettext infrastructure from the FROM format
38 FROMFILE is the original file, defaulting to archive.\$FROM.tar.gz.
39 TOFILE is the destination file, defaulting to archive.\$TO.tar.gz.
41 Report bugs to <bug-gnu-gettext@gnu.org>."
45 # outputs to stdout the --version message.
48 echo "$progname (GNU $package) $version"
49 echo "Copyright (C) 2009-2010 Free Software Foundation, Inc.
50 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
51 This is free software: you are free to change and redistribute it.
52 There is NO WARRANTY, to the extent permitted by law."
53 echo "Written by" "Bruno Haible"
56 # func_fatal_error message
57 # outputs to stderr a fatal error message, and terminates the program.
60 echo "convert-archive: *** $1" 1>&2
61 echo "convert-archive: *** Stop." 1>&2
65 # Command-line option processing.
67 if ! { { test $# = 2 || test $# = 3 || test $# = 4; } \
68 && case "$1" in dir | cvs | git ) true;; *) false;; esac \
69 && case "$2" in dir | cvs | git ) true;; *) false;; esac; }; then
70 echo "Usage: convert-archive {dir|cvs|git} {dir|cvs|git} [fromfile [tofile]]"
77 test -n "$fromfile" || fromfile=`pwd`/archive.$from.tar.gz
79 test -n "$tofile" || tofile=`pwd`/archive.$to.tar.gz
81 unpacked=`pwd`/unpacked-files
82 mkdir "$unpacked" || {
83 if test -d "$unpacked"; then
84 func_fatal_error "directory $unpacked already exists"
86 func_fatal_error "cannot create directory $unpacked"
90 # Unpack the original archive.
93 gzip -d -c < "$fromfile" | (cd "$unpacked" && tar xf -) \
94 || func_fatal_error "file copy failed"
99 # - work_dir directory containing the temporary checkout
101 mkdir "$work_dir" || {
102 if test -d "$work_dir"; then
103 func_fatal_error "directory $work_dir already exists"
105 func_fatal_error "cannot create directory $work_dir"
110 # - cvs_dir directory containing the temporary repository
112 # Use an umask of 077, to avoid attacks that work by overwriting files in
113 # the "$CVSROOT"/CVSROOT directory.
114 (umask 077 && mkdir "$cvs_dir") || {
115 if test -d "$cvs_dir"; then
116 func_fatal_error "directory $cvs_dir already exists"
118 func_fatal_error "cannot create directory $cvs_dir"
121 CVSROOT=`pwd`/"$cvs_dir"
123 unset CVS_CLIENT_PORT
124 unset CVS_IGNORE_REMOTE_ROOT
125 unset CVS_LOCAL_BRANCH_NUM
133 unset CVS_SERVER_SLEEP
135 export CVS_SIGN_COMMITS
137 unset CVS_VERIFY_CHECKOUTS
138 unset CVS_VERIFY_TEMPLATE
145 # Need to pass -d "$CVSROOT", because there may be a CVS directory in the
147 cvs -d "$CVSROOT" init || func_fatal_error "cvs init failed"
148 gzip -d -c < "$fromfile" | (cd "$cvs_dir" && tar xf -)
150 # A witness that contains all versions.
151 # Can be e.g. ABOUT-NLS, intl/ChangeLog, m4/gettext.m4.
154 # Get list of tags or versions.
155 sed_extract_tags_from_log1='/^symbolic names:/{
161 /^keyword substitution:/q'
162 sed_extract_tags_from_log2='s/^ \([^:]*\):.*/\1/'
163 rlog_harmless_warning_regex="warning: Unknown phrases like \`commitid \.\.\.;' are present\."
165 ( LC_ALL=C rlog "$cvs_dir"/archive/$witness,v 2>&1 1>&3 \
166 | grep -v "$rlog_harmless_warning_regex" 1>&2 ) 3>&1 \
167 | sed -n -e "$sed_extract_tags_from_log1" \
168 | sed -e "$sed_extract_tags_from_log2"`
169 test -n "$tags" || func_fatal_error "no release tags found"
170 sed_tag_to_version='s/_/./g'
172 if test $tag != release; then
173 version=`echo "$tag" | sed -e "$sed_tag_to_version"`
175 cvs -d "$CVSROOT" checkout -r"$tag" archive > /dev/null 2> cvs.err \
176 || { cat cvs.err 1>&2; exit 1; }
177 cat cvs.err | grep -v '^cvs checkout: Updating'
178 find archive -name CVS -type d -print | xargs rm -rf
180 ) || func_fatal_error "cvs checkout failed"
181 mv "$work_dir"/archive "$unpacked/$version"
190 # - work_dir directory containing the temporary checkout
192 mkdir "$work_dir" || {
193 if test -d "$work_dir"; then
194 func_fatal_error "directory $work_dir already exists"
196 func_fatal_error "cannot create directory $work_dir"
200 mkdir "$work_dir/master" || func_fatal_error "mkdir failed"
201 gzip -d -c < "$fromfile" | (cd "$work_dir/master" && tar xf -)
203 tags=`cd master && git tag`
204 test -n "$tags" || func_fatal_error "no release tags found"
206 if test $tag != empty; then
208 (cd master && git checkout -q $tag) \
209 || func_fatal_error "git checkout failed"
210 rm -f master/.gitignore
212 mkdir "$unpacked/$version" || func_fatal_error "mkdir failed"
213 (cd master && tar cf - .) | (cd "$unpacked/$version" && tar xf -) \
214 || func_fatal_error "file copy failed"
223 # Find a good 'tar' program.
224 existing_file=gettext-0.10.35/ABOUT-NLS
227 for prog in tar gnutar gtar; do
228 if (cd "$unpacked" && $prog cf - --owner=root --group=root "$existing_file") >/dev/null 2>&1; then
230 TAR_OPTIONS='--owner=root --group=root'
235 # Create the target archive.
238 (cd "$unpacked" && $TAR cf - $TAR_OPTIONS *) \
239 | gzip -c -9 > "$tofile" \
240 || func_fatal_error "archive creation failed"
245 # - cvs_dir directory containing the temporary repository
246 cvs_dir=autopoint-files
247 # Use an umask of 077, to avoid attacks that work by overwriting files in
248 # the "$CVSROOT"/CVSROOT directory.
249 (umask 077 && mkdir "$cvs_dir") || {
250 if test -d "$cvs_dir"; then
251 func_fatal_error "directory $cvs_dir already exists"
253 func_fatal_error "cannot create directory $cvs_dir"
256 CVSROOT=`pwd`/"$cvs_dir"
258 unset CVS_CLIENT_PORT
259 unset CVS_IGNORE_REMOTE_ROOT
265 unset CVS_SERVER_SLEEP
271 # Set a nonstandard variable, for a good-looking cvs history.
273 gcc -shared -fPIC -O cvsuser.c -o cvsuser.so
274 cvsuser_hack=`pwd`/cvsuser.so
276 # Need to pass -d "$CVSROOT", because there may be a CVS directory in the
278 cvs -d "$CVSROOT" init || func_fatal_error "cvs init failed"
280 # Add the contents of the unpacked directory to the repository.
283 cvsver=`echo "$version" | sed -e 's/\./_/g'`
285 CVSUSER=$cvsuser LD_PRELOAD=$cvsuser_hack \
286 cvs -d "$CVSROOT" import -m "Import $version" archive release "$cvsver" > /dev/null
287 ) || func_fatal_error "cvs import failed"
288 # In order to avoid keyword substitution, we have to use "cvs admin"
289 # in a temporary checkout.
290 mkdir tmpcheckout || func_fatal_error "mkdir failed"
292 && cvs -d "$CVSROOT" checkout -r"$cvsver" archive > /dev/null \
293 && cvs -d "$CVSROOT" admin -ko `find . -type f -print | sed -e 's,^\./,,' | grep -v '^CVS/' | grep -v '/CVS/'` > /dev/null
294 ) 2> cvs.err || { cat cvs.err 1>&2; func_fatal_error "cvs checkout or admin failed"; }
298 (cd "$cvs_dir" && $TAR cf - $TAR_OPTIONS archive) \
299 | gzip -c -9 > "$tofile" \
300 || func_fatal_error "archive creation failed"
301 rm -rf "$cvs_dir" cvsuser.so
305 git_dir=`pwd`/tmpgit$$
306 mkdir "$git_dir" || func_fatal_error "mkdir failed"
310 git config user.name 'GNU Gettext Build'
311 git config user.email 'bug-gnu-gettext@gnu.org'
314 git commit --author="Bruno Haible <bruno@clisp.org>" \
315 --message="Empty directory" 2>&1 \
318 }) || func_fatal_error "git init failed"
319 sed_remove_leading_dot='s,^\./,,'
320 sed_remove_git_infrastructure='/^\.git/d'
323 (cd $version && tar cf - .) | \
325 prev_files=`find . -type f | sed -e "$sed_remove_leading_dot" -e "$sed_remove_git_infrastructure"`
326 if test -n "$prev_files"; then
327 git rm -q $prev_files
331 git commit --author="Bruno Haible <bruno@clisp.org>" \
332 --message="Import $version" 2>&1 \
335 }) || func_fatal_error "file copy into git repository failed"
338 (cd "$git_dir" && git reset -q --hard empty && git repack -a -d -q) \
339 || func_fatal_error "git reset or repack failed"
340 (cd "$git_dir" && $TAR cf - $TAR_OPTIONS .git) \
341 | gzip -c -9 > "$tofile" \
342 || func_fatal_error "archive creation failed"