cvsimport
[findutils.git] / po / fetch-po-files
blob3fd84fccbaf8216a672b74c008ae91000a83214a
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 3 of the License, or
9 # (at your option) 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, see <http://www.gnu.org/licenses/>.
19 # Written by James Youngman.
21 URLBASE="http://www.iro.umontreal.ca/translation/maint"
24 if [ $# -ne 2 ]; then
25 echo "You need to specify the package name and a destination directory on the command line." >&2
26 exit 1
31 PACKAGE="$1"
32 DESTDIR="$2"
33 shift
35 debug () {
36 : nothing
39 info () {
40 echo "$@"
44 v_update_needed() {
45 debug "update_required: Checking $@"
46 vnew=$1
47 vexisting=$2
49 major_new=$(echo $vnew | cut -s -d. -f1)
50 major_existing=$(echo $vexisting | cut -s -d. -f1)
51 if [ -z "$major_new" ]; then
52 debug "New version number empty, update not needed"
53 false
54 elif [ -z "$major_existing" ]; then
55 debug "Existing version number empty, update is needed"
56 true
57 elif [ $major_new -gt $major_existing ]; then
58 debug "$vnew > $vexisting, update needed"
59 true
60 elif [ $major_new -lt $major_existing ]; then
61 debug "$vnew < $vexisting, update NOT needed"
62 true
63 else
64 v_update_needed \
65 $(echo $vnew | cut -s -d. -f2-) \
66 $(echo $vexisting | cut -s -d. -f2-)
70 d_update_needed() {
71 # Determine if an update is neeededon the basis of the version numbers.
72 cat "$@" |
73 tr -d '"' |
74 grep "^PO-Revision-Date: " |
75 sed -e 's/PO-Revision-Date: //' -e 's/\\n$//' |
76 LANG=C sort -c >/dev/null
81 getversion() {
82 grep Project-Id-Version: < "$1" |
83 tr -d '"' |
84 sed -e 's/^.*'$PACKAGE' //' -e 's/\\n$//'
88 check_versions() {
89 if vnew=$(getversion "$1"); then
90 if vexisting=$(getversion "$2"); then
91 if v_update_needed "$vnew" "$vexisting"; then
92 true
93 else
94 d_update_needed "$2" "$1" && \
95 info "Timestamp fields indicate $1 is newer than $2"
97 else
98 false
100 else
101 false
106 update_required() {
107 new="$1"
108 existing="$2"
109 # ls -ltrd "$new" "$existing"
111 if ! [ -e "$existing" ] ; then
112 debug "$existing does not exist, using $new"
113 true
114 elif cmp $new $existing >/dev/null 2>&1; then
115 info "$new and $existing are identical"
116 false
117 elif check_versions "$new" "$existing"; then
118 info "Fetched file has newer version number or date stamp"
119 true
120 else
121 false
126 possible_update() {
128 debug "Possible update of $3/$1"
130 new="$2/$1"
131 existing="$3/$1"
133 if update_required $new $existing; then
134 info "Updating $1..."
135 rm -f $existing
136 mv $new $existing
137 else
138 rm -f $new
144 main () {
145 potfile=$DESTDIR/$PACKAGE.pot
146 if [ -f $potfile ] ; then
147 echo "OK".
148 else
149 echo "$potfile is not present. Did you specify the right command line?" >&2
150 exit 1
152 tmpdir=`mktemp -d`
155 # set -x
156 printf "Fetching .po files..."
157 wget --quiet --recursive --directory-prefix="$tmpdir" --level=1 --accept "*.po" --no-directories "$URLBASE"/"$PACKAGE"
158 echo done
159 # cp /tmp/po-updates/$PACKAGE/*.po "$tmpdir"
160 # touch "$tmpdir"/*.po
162 for f in $(cd $tmpdir && ls *.po ); do
163 possible_update "$f" "$tmpdir" "$DESTDIR"
164 done
165 cd /
166 rm -rf "$tmpdir"
170 # getversion gl.po
171 # update_needed 4.1.5 4.1.5
172 # update_needed 4.1.15 4.1.5
173 # update_needed 5.0 4.1.5
174 # update_needed 4.2.6 5.0
175 # exit 0
177 main "$@"