1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
|
#! /bin/sh
#
# Copyright (C) 2009-2024 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Usage: convert-archive FROM TO [FROMFILE [TOFILE]]
# where FROM is dir or dirgz or dirbz2 or dirxz or cvs or git
# and TO is dir or dirgz or dirbz2 or dirxz or cvs or git
# This will read FROMFILE (default: archive.$FROM.tar.gz)
# and produce TOFILE (default: archive.$TO.tar.gz).
progname=$0
package=@PACKAGE@
version=@VERSION@
# func_usage
# outputs to stdout the --help usage message.
func_usage ()
{
echo "\
Usage: convert-archive FROM TO [FROMFILE [TOFILE]]
Converts the archive of gettext infrastructure from the FROM format
to the TO format.
FROMFILE is the original file, defaulting to archive.\$FROM.tar.gz.
TOFILE is the destination file, defaulting to archive.\$TO.tar.gz.
Report bugs in the bug tracker at <https://savannah.gnu.org/projects/gettext>
or by email to <bug-gettext@gnu.org>."
}
# func_version
# outputs to stdout the --version message.
func_version ()
{
echo "$progname (GNU $package) $version"
echo "Copyright (C) 2009-2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law."
echo "Written by" "Bruno Haible"
}
# func_fatal_error message
# outputs to stderr a fatal error message, and terminates the program.
func_fatal_error ()
{
echo "convert-archive: *** $1" 1>&2
echo "convert-archive: *** Stop." 1>&2
exit 1
}
# Command-line option processing.
if { { test $# = 2 || test $# = 3 || test $# = 4; } \
&& case "$1" in dir | cvs | git ) true;; *) false;; esac \
&& case "$2" in dir | cvs | git ) true;; *) false;; esac; }; then
:
else
echo "Usage: convert-archive {dir|cvs|git} {dir|cvs|git} [fromfile [tofile]]"
exit 1
fi
from="$1"
to="$2"
fromfile="$3"
test -n "$fromfile" || fromfile=`pwd`/archive.$from.tar.gz
tofile="$4"
test -n "$tofile" || tofile=`pwd`/archive.$to.tar.gz
unpacked=`pwd`/unpacked-files
mkdir "$unpacked" || {
if test -d "$unpacked"; then
func_fatal_error "directory $unpacked already exists"
else
func_fatal_error "cannot create directory $unpacked"
fi
}
# Unpack the original archive.
case "$from" in
dir*)
{ case "$from" in
dir) cat < "$fromfile" ;;
dirgz) gzip -d -c < "$fromfile" ;;
dirbz2) bzip2 -d -c < "$fromfile" ;;
dirxz) xz -d -c < "$fromfile" ;;
esac
} \
| (cd "$unpacked" && tar xf -) \
|| func_fatal_error "file copy failed"
;;
cvs)
# Set variables
# - work_dir directory containing the temporary checkout
work_dir=tmpwrk$$
mkdir "$work_dir" || {
if test -d "$work_dir"; then
func_fatal_error "directory $work_dir already exists"
else
func_fatal_error "cannot create directory $work_dir"
fi
}
# Set variables
# - cvs_dir directory containing the temporary repository
cvs_dir=tmpcvs$$
# Use an umask of 077, to avoid attacks that work by overwriting files in
# the "$CVSROOT"/CVSROOT directory.
(umask 077 && mkdir "$cvs_dir") || {
if test -d "$cvs_dir"; then
func_fatal_error "directory $cvs_dir already exists"
else
func_fatal_error "cannot create directory $cvs_dir"
fi
}
CVSROOT=`pwd`/"$cvs_dir"
unset CVS_CLIENT_LOG
unset CVS_CLIENT_PORT
unset CVS_IGNORE_REMOTE_ROOT
unset CVS_LOCAL_BRANCH_NUM
unset CVS_NOBASES
unset CVS_PASSFILE
unset CVS_PASSWORD
unset CVS_PROXY_PORT
unset CVS_RCMD_PORT
unset CVS_RSH
unset CVS_SERVER
unset CVS_SERVER_SLEEP
CVS_SIGN_COMMITS=
export CVS_SIGN_COMMITS
unset CVS_SSH
unset CVS_VERIFY_CHECKOUTS
unset CVS_VERIFY_TEMPLATE
unset CVSIGNORE
unset CVSREAD
unset CVSREADONLYFS
unset CVSUMASK
unset CVSWRAPPERS
# Need to pass -d "$CVSROOT", because there may be a CVS directory in the
# current directory.
cvs -d "$CVSROOT" init || func_fatal_error "cvs init failed"
gzip -d -c < "$fromfile" | (cd "$cvs_dir" && tar xf -)
# A witness that contains all versions.
# Can be e.g. ABOUT-NLS, intl/ChangeLog, m4/gettext.m4.
witness='ABOUT-NLS'
# Get list of tags or versions.
sed_extract_tags_from_log1='/^symbolic names:/{
:a
/^ /p
n
ba
}
/^keyword substitution:/q'
sed_extract_tags_from_log2='s/^ \([^:]*\):.*/\1/'
rlog_harmless_warning_regex="warning: Unknown phrases like \`commitid \.\.\.;' are present\."
tags=`
( LC_ALL=C rlog "$cvs_dir"/archive/$witness,v 2>&1 1>&3 \
| grep -v "$rlog_harmless_warning_regex" 1>&2 ) 3>&1 \
| sed -n -e "$sed_extract_tags_from_log1" \
| sed -e "$sed_extract_tags_from_log2"`
test -n "$tags" || func_fatal_error "no release tags found"
sed_tag_to_version='s/_/./g'
for tag in $tags; do
if test $tag != release; then
version=`echo "$tag" | sed -e "$sed_tag_to_version"`
(cd "$work_dir"
cvs -d "$CVSROOT" checkout -r"$tag" archive > /dev/null 2> cvs.err \
|| { cat cvs.err 1>&2; exit 1; }
cat cvs.err | grep -v '^cvs checkout: Updating'
find archive -name CVS -type d -print | xargs rm -rf
rm -rf CVS
) || func_fatal_error "cvs checkout failed"
mv "$work_dir"/archive "$unpacked/$version"
fi
done
rm -rf "$cvs_dir"
rm -rf "$work_dir"
;;
git)
# Set variables
# - work_dir directory containing the temporary checkout
work_dir=tmpwrk$$
mkdir "$work_dir" || {
if test -d "$work_dir"; then
func_fatal_error "directory $work_dir already exists"
else
func_fatal_error "cannot create directory $work_dir"
fi
}
mkdir "$work_dir/master" || func_fatal_error "mkdir failed"
gzip -d -c < "$fromfile" | (cd "$work_dir/master" && tar xf -)
(unset GIT_CONFIG
unset XDG_CONFIG_HOME
unset HOME
GIT_CONFIG_NOSYSTEM=1; export GIT_CONFIG_NOSYSTEM
cd "$work_dir"
tags=`cd master && git tag`
test -n "$tags" || func_fatal_error "no release tags found"
for tag in $tags; do
if test $tag != empty; then
version=$tag
(cd master && git checkout -q $tag) \
|| func_fatal_error "git checkout failed"
rm -f master/.gitignore
mv master/.git .git
mkdir "$unpacked/$version" || func_fatal_error "mkdir failed"
(cd master && tar cf - .) | (cd "$unpacked/$version" && tar xf -) \
|| func_fatal_error "file copy failed"
mv .git master/.git
fi
done
)
rm -rf "$work_dir"
;;
esac
# Find a good 'tar' program.
existing_file=gettext-0.10.35/ABOUT-NLS
TAR=tar
TAR_OPTIONS=
for prog in tar gnutar gtar; do
if (cd "$unpacked" && $prog cf - --owner=root --group=root "$existing_file") >/dev/null 2>&1; then
TAR=$prog
TAR_OPTIONS='--owner=root --group=root'
break
fi
done
# Create the target archive.
case "$to" in
dir*)
(cd "$unpacked" && $TAR cf - $TAR_OPTIONS *) \
| { case "$to" in
dir) cat > "$tofile" ;;
dirgz) gzip -c -9 > "$tofile" ;;
dirbz2) bzip2 -c -9 > "$tofile" ;;
dirxz) xz -c -5 > "$tofile" ;;
esac
} \
|| func_fatal_error "archive creation failed"
;;
cvs)
# Set variables
# - cvs_dir directory containing the temporary repository
cvs_dir=autopoint-files
# Use an umask of 077, to avoid attacks that work by overwriting files in
# the "$CVSROOT"/CVSROOT directory.
(umask 077 && mkdir "$cvs_dir") || {
if test -d "$cvs_dir"; then
func_fatal_error "directory $cvs_dir already exists"
else
func_fatal_error "cannot create directory $cvs_dir"
fi
}
CVSROOT=`pwd`/"$cvs_dir"
unset CVS_CLIENT_LOG
unset CVS_CLIENT_PORT
unset CVS_IGNORE_REMOTE_ROOT
unset CVS_PASSFILE
unset CVS_PASSWORD
unset CVS_RCMD_PORT
unset CVS_RSH
unset CVS_SERVER
unset CVS_SERVER_SLEEP
unset CVSIGNORE
unset CVSREAD
unset CVSUMASK
unset CVSWRAPPERS
# Set a nonstandard variable, for a good-looking cvs history.
cvsuser=bruno
gcc -shared -fPIC -O cvsuser.c -o cvsuser.so
cvsuser_hack=`pwd`/cvsuser.so
# Need to pass -d "$CVSROOT", because there may be a CVS directory in the
# current directory.
cvs -d "$CVSROOT" init || func_fatal_error "cvs init failed"
# Add the contents of the unpacked directory to the repository.
(cd "$unpacked"
for version in *; do
cvsver=`echo "$version" | sed -e 's/\./_/g'`
(cd $version
CVSUSER=$cvsuser LD_PRELOAD=$cvsuser_hack \
cvs -d "$CVSROOT" import -m "Import $version" archive release "$cvsver" > /dev/null
) || func_fatal_error "cvs import failed"
# In order to avoid keyword substitution, we have to use "cvs admin"
# in a temporary checkout.
mkdir tmpcheckout || func_fatal_error "mkdir failed"
(cd tmpcheckout \
&& cvs -d "$CVSROOT" checkout -r"$cvsver" archive > /dev/null \
&& cvs -d "$CVSROOT" admin -ko `find . -type f -print | sed -e 's,^\./,,' | grep -v '^CVS/' | grep -v '/CVS/'` > /dev/null
) 2> cvs.err || { cat cvs.err 1>&2; func_fatal_error "cvs checkout or admin failed"; }
rm -rf tmpcheckout
done
)
(cd "$cvs_dir" && $TAR cf - $TAR_OPTIONS archive) \
| gzip -c -9 > "$tofile" \
|| func_fatal_error "archive creation failed"
rm -rf "$cvs_dir" cvsuser.so
;;
git)
git_dir=`pwd`/tmpgit$$
mkdir "$git_dir" || func_fatal_error "mkdir failed"
unset GIT_CONFIG
unset XDG_CONFIG_HOME
unset HOME
GIT_CONFIG_NOSYSTEM=1; export GIT_CONFIG_NOSYSTEM
(cd "$git_dir" && {
git init -q
git config user.name 'GNU Gettext Build'
git config user.email 'bug-gnu-gettext@gnu.org'
touch .gitignore
git add .
git commit --author="Bruno Haible <bruno@clisp.org>" \
--message="Empty directory" 2>&1 >/dev/null
git tag empty
}) || func_fatal_error "git init failed"
sed_remove_leading_dot='s,^\./,,'
sed_remove_git_infrastructure='/^\.git/d'
(cd "$unpacked"
for version in *; do
(cd $version && tar cf - .) | \
(cd "$git_dir" && {
prev_files=`find . -type f | sed -e "$sed_remove_leading_dot" -e "$sed_remove_git_infrastructure"`
if test -n "$prev_files"; then
git rm -q $prev_files
fi
tar xf -
git add .
git commit --author="Bruno Haible <bruno@clisp.org>" \
--message="Import $version" 2>&1 >/dev/null
git tag "$version"
}) || func_fatal_error "file copy into git repository failed"
done
)
(cd "$git_dir" && git reset -q --hard empty && git repack -a -d -q) \
|| func_fatal_error "git reset or repack failed"
(cd "$git_dir" && $TAR cf - $TAR_OPTIONS .git) \
| gzip -c -9 > "$tofile" \
|| func_fatal_error "archive creation failed"
rm -rf "$git_dir"
;;
esac
rm -rf "$unpacked"
|