did make dist
[findutils.git] / po / fetch-po-files
blobdfaed2606dac2dbc3e93be9d4ae28a47058c0dd5
1 #! /bin/sh
3 # fetch-po-files -- fetches the .po files from the Translation Project website
4 # Copyright (C) 2005 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
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 General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 # USA.
21 # Written by James Youngman.
23 URLBASE="http://www.iro.umontreal.ca/translation/maint"
26 if [ $# -ne 2 ]; then
27 echo "You need to specify the package name and a destination directory on the command line." >&2
28 exit 1
33 PACKAGE="$1"
34 DESTDIR="$2"
35 shift
37 debug () {
38 : nothing
41 info () {
42 echo "$@"
46 v_update_needed() {
47 debug "update_required: Checking $@"
48 vnew=$1
49 vexisting=$2
51 major_new=$(echo $vnew | cut -s -d. -f1)
52 major_existing=$(echo $vexisting | cut -s -d. -f1)
53 if [ -z "$major_new" ]; then
54 debug "New version number empty, update not needed"
55 false
56 elif [ -z "$major_existing" ]; then
57 debug "Existing version number empty, update is needed"
58 true
59 elif [ $major_new -gt $major_existing ]; then
60 debug "$vnew > $vexisting, update needed"
61 true
62 elif [ $major_new -lt $major_existing ]; then
63 debug "$vnew < $vexisting, update NOT needed"
64 true
65 else
66 v_update_needed \
67 $(echo $vnew | cut -s -d. -f2-) \
68 $(echo $vexisting | cut -s -d. -f2-)
72 d_update_needed() {
73 # Determine if an update is neeededon the basis of the version numbers.
74 cat "$@" |
75 tr -d '"' |
76 grep "^PO-Revision-Date: " |
77 sed -e 's/PO-Revision-Date: //' -e 's/\\n$//' |
78 LANG=C sort -c >/dev/null
83 getversion() {
84 grep Project-Id-Version: < "$1" |
85 tr -d '"' |
86 sed -e 's/^.*'$PACKAGE' //' -e 's/\\n$//'
90 check_versions() {
91 if vnew=$(getversion "$1"); then
92 if vexisting=$(getversion "$2"); then
93 if v_update_needed "$vnew" "$vexisting"; then
94 true
95 else
96 d_update_needed "$2" "$1" && \
97 info "Timestamp fields indicate $1 is newer than $2"
99 else
100 false
102 else
103 false
108 update_required() {
109 new="$1"
110 existing="$2"
111 # ls -ltrd "$new" "$existing"
113 if ! [ -e "$existing" ] ; then
114 debug "$existing does not exist, using $new"
115 true
116 elif cmp $new $existing >/dev/null 2>&1; then
117 info "$new and $existing are identical"
118 false
119 elif check_versions "$new" "$existing"; then
120 info "Fetched file has newer version number or date stamp"
121 true
122 else
123 false
128 possible_update() {
130 debug "Possible update of $3/$1"
132 new="$2/$1"
133 existing="$3/$1"
135 if update_required $new $existing; then
136 info "Updating $1..."
137 rm -f $existing
138 mv $new $existing
139 else
140 rm -f $new
146 main () {
147 potfile=$DESTDIR/$PACKAGE.pot
148 if [ -f $potfile ] ; then
149 echo "OK".
150 else
151 echo "$potfile is not present. Did you specify the right command line?" >&2
152 exit 1
154 tmpdir=`mktemp -d`
157 # set -x
158 printf "Fetching .po files..."
159 wget --quiet --recursive --directory-prefix="$tmpdir" --level=1 --accept "*.po" --no-directories "$URLBASE"/"$PACKAGE"
160 echo done
161 # cp /tmp/po-updates/$PACKAGE/*.po "$tmpdir"
162 # touch "$tmpdir"/*.po
164 for f in $(cd $tmpdir && ls *.po ); do
165 possible_update "$f" "$tmpdir" "$DESTDIR"
166 done
167 cd /
168 rm -rf "$tmpdir"
172 # getversion gl.po
173 # update_needed 4.1.5 4.1.5
174 # update_needed 4.1.15 4.1.5
175 # update_needed 5.0 4.1.5
176 # update_needed 4.2.6 5.0
177 # exit 0
179 main "$@"