| 1 |
fjpop-guest |
24848 |
#!/bin/bash |
| 2 |
|
|
|
| 3 |
|
|
# This script will allow to check for changes in the original |
| 4 |
|
|
# English docs for languages that use po files for translation. |
| 5 |
|
|
# It combines the function of the old doc-check and rev-update |
| 6 |
|
|
# scripts (resulting in the name rev-check :-) |
| 7 |
|
|
|
| 8 |
|
|
# For each language, the last three revisions for which the |
| 9 |
|
|
# translation has been updated are saved in a file. |
| 10 |
|
|
# The current revision of English documents is checked against |
| 11 |
|
|
# the most recent revisions in this file. |
| 12 |
|
|
|
| 13 |
|
|
lang="" |
| 14 |
|
|
default_lang="nl" |
| 15 |
|
|
file="" |
| 16 |
|
|
|
| 17 |
|
|
print_usage () { |
| 18 |
|
|
echo "Usage: $(basename $0) [options] [language] [file]" |
| 19 |
|
|
echo " TODO: explanation of syntax and options" |
| 20 |
|
|
} |
| 21 |
|
|
|
| 22 |
|
|
print_usage_err () { |
| 23 |
|
|
print_usage |
| 24 |
|
|
exit 1 |
| 25 |
|
|
} |
| 26 |
|
|
|
| 27 |
|
|
check_parm_lang () { |
| 28 |
|
|
# Check that directory exists won't work after conversion to po... |
| 29 |
|
|
if [ -d "$1" ] ; then |
| 30 |
|
|
lang="$1" |
| 31 |
|
|
else |
| 32 |
|
|
echo "Info: no valid language specified, using default '$default_lang'" |
| 33 |
|
|
if [ -d "$default_lang" ] ; then |
| 34 |
|
|
lang="$default_lang" |
| 35 |
|
|
return 1 |
| 36 |
|
|
else |
| 37 |
|
|
echo "Error: directory for language '$default_lang' not found" |
| 38 |
|
|
print_usage_err |
| 39 |
|
|
fi |
| 40 |
|
|
fi |
| 41 |
|
|
return 0 |
| 42 |
|
|
} |
| 43 |
|
|
|
| 44 |
|
|
check_parm_file () { |
| 45 |
|
|
file=$(echo "$1" | sed "s:^./::" | sed "s:^en/::") |
| 46 |
|
|
if [ ! -f "./en/$file" ] ; then |
| 47 |
|
|
echo "Error: file '$file' does not exist" |
| 48 |
|
|
return 1 |
| 49 |
|
|
fi |
| 50 |
|
|
return 0 |
| 51 |
|
|
} |
| 52 |
|
|
|
| 53 |
|
|
parse_opts () { |
| 54 |
|
|
command="check" |
| 55 |
|
|
do_diff="" |
| 56 |
|
|
do_all="" |
| 57 |
|
|
parm_count=0 |
| 58 |
|
|
|
| 59 |
|
|
for opt in $@; do |
| 60 |
|
|
case "$opt" in |
| 61 |
|
|
--update|-u) |
| 62 |
|
|
[ $command = "check" ] || print_usage_err |
| 63 |
|
|
command="update" |
| 64 |
|
|
;; |
| 65 |
|
|
--add|-a) |
| 66 |
|
|
[ $command = "check" ] || print_usage_err |
| 67 |
|
|
command="add" |
| 68 |
|
|
;; |
| 69 |
|
|
--diff|-d) |
| 70 |
|
|
do_diff=1 |
| 71 |
|
|
;; |
| 72 |
|
|
--all|-A) |
| 73 |
|
|
do_all=1 |
| 74 |
|
|
;; |
| 75 |
|
|
--convert) |
| 76 |
|
|
[ $command = "check" ] || print_usage_err |
| 77 |
|
|
command="convert" |
| 78 |
|
|
;; |
| 79 |
|
|
--help|-h) |
| 80 |
|
|
print_usage |
| 81 |
|
|
exit 0 |
| 82 |
|
|
;; |
| 83 |
|
|
-*) |
| 84 |
|
|
print_usage_err |
| 85 |
|
|
;; |
| 86 |
|
|
*) |
| 87 |
|
|
parm_count=$(($parm_count + 1)) |
| 88 |
|
|
if [ $parm_count -eq 1 ] ; then |
| 89 |
|
|
check_parm_lang "$opt" |
| 90 |
|
|
[ $? -ne 0 ] && parm_count=$(($parm_count + 1)) |
| 91 |
|
|
fi |
| 92 |
|
|
if [ $parm_count -eq 2 ] ; then |
| 93 |
|
|
check_parm_file "$opt" |
| 94 |
|
|
[ $? -ne 0 ] && print_usage_err |
| 95 |
|
|
fi |
| 96 |
|
|
|
| 97 |
|
|
[ $parm_count -gt 2 ] && print_usage_err |
| 98 |
|
|
;; |
| 99 |
|
|
esac |
| 100 |
|
|
|
| 101 |
|
|
done |
| 102 |
|
|
|
| 103 |
|
|
[ -z "$lang" ] && check_parm_lang "<none>" |
| 104 |
|
|
|
| 105 |
|
|
case $command in |
| 106 |
|
|
check) |
| 107 |
|
|
[ "$do_all" ] && print_usage_err |
| 108 |
|
|
;; |
| 109 |
|
|
convert) |
| 110 |
|
|
[ "$do_all" ] && print_usage_err |
| 111 |
|
|
if [ -n "$file" ] ; then |
| 112 |
|
|
echo "Error: parameter [file] not allowed with --$command option" |
| 113 |
|
|
print_usage_err |
| 114 |
|
|
fi |
| 115 |
|
|
if [ ! -d $lang ] ; then |
| 116 |
|
|
echo "Error: directory for language '$lang' not found" |
| 117 |
|
|
exit 1 |
| 118 |
|
|
fi |
| 119 |
|
|
;; |
| 120 |
|
|
add|update) |
| 121 |
|
|
if [ ! "$do_all" ] && [ -z "$file" ] ; then |
| 122 |
|
|
echo "Error: parameter [file] missing, to update all files add --all option" |
| 123 |
|
|
print_usage_err |
| 124 |
|
|
fi |
| 125 |
|
|
if [ "$do_all" ] && [ ! -z "$file" ] ; then |
| 126 |
|
|
echo "Error: parameter [file] not allowed with --all option" |
| 127 |
|
|
print_usage_err |
| 128 |
|
|
fi |
| 129 |
|
|
;; |
| 130 |
|
|
esac |
| 131 |
|
|
} |
| 132 |
|
|
|
| 133 |
|
|
get_rev () { |
| 134 |
|
|
local REV |
| 135 |
|
|
REV="$(egrep '^<\!--[[:space:]]*\$Id:' ./en/$1 | \ |
| 136 |
|
|
sed 's/^.*$Id:[[:space:]]*//' | cut -d " " -f 2)" |
| 137 |
|
|
if [ -z "$REV" ] ; then |
| 138 |
|
|
echo "Error: could not determine revision of './en/$1'" |
| 139 |
|
|
return 1 |
| 140 |
|
|
fi |
| 141 |
|
|
echo "$REV" |
| 142 |
|
|
return 0 |
| 143 |
|
|
} |
| 144 |
|
|
|
| 145 |
|
|
get_trev () { |
| 146 |
|
|
local TREV |
| 147 |
|
|
[ "$2" = "all" ] && fields="2-" || fields="2" |
| 148 |
|
|
TREV="$(egrep "^$1" $rev_file | cut -f $fields)" |
| 149 |
|
|
if [ -z "$TREV" ] ; then |
| 150 |
|
|
return 1 |
| 151 |
|
|
fi |
| 152 |
|
|
echo "$TREV" |
| 153 |
|
|
return 0 |
| 154 |
|
|
} |
| 155 |
|
|
|
| 156 |
|
|
print_diff () { |
| 157 |
|
|
local TREV |
| 158 |
|
|
local TREV_PREV="" |
| 159 |
|
|
for TREV in $2; do |
| 160 |
|
|
[ "$TREV_PREV" ] && echo "Diff against revision $TREV_PREV failed, trying next oldest: $TREV" |
| 161 |
|
|
svn diff -r $TREV:$3 ./en/$1 |
| 162 |
|
|
[ $? -eq 0 ] && break |
| 163 |
|
|
TREV_PREV=$TREV |
| 164 |
|
|
done |
| 165 |
|
|
} |
| 166 |
|
|
|
| 167 |
|
|
check_one () { |
| 168 |
|
|
REV=$(get_rev $1) |
| 169 |
|
|
[ $? -ne 0 ] && return 9 |
| 170 |
|
|
TREV=$(get_trev $1) |
| 171 |
|
|
if [ $? -ne 0 ] ; then |
| 172 |
|
|
echo "$1: N/A -> $REV" |
| 173 |
|
|
return 2 |
| 174 |
|
|
fi |
| 175 |
|
|
|
| 176 |
|
|
local RET=0 |
| 177 |
|
|
if [ ! "$TREV" = "$REV" ] ; then |
| 178 |
|
|
RET=1 |
| 179 |
|
|
echo "$1: $TREV -> $REV" |
| 180 |
|
|
if [ "$do_diff" ] ; then |
| 181 |
|
|
print_diff $1 "$(get_trev $1 all)" $REV |
| 182 |
|
|
echo |
| 183 |
|
|
fi |
| 184 |
|
|
fi |
| 185 |
|
|
return $RET |
| 186 |
|
|
} |
| 187 |
|
|
|
| 188 |
|
|
do_check () { |
| 189 |
|
|
local RESULT=0 |
| 190 |
|
|
if [ -n "$file" ] ; then |
| 191 |
|
|
check_one $file |
| 192 |
|
|
RESULT=$? |
| 193 |
|
|
else |
| 194 |
|
|
for file in $(find ./en/ -name "*.xml" | sed "s:^./::" | sed "s:^en/::"); do |
| 195 |
|
|
check_one $file |
| 196 |
|
|
[ $? -eq 1 ] && RESULT=1 |
| 197 |
|
|
done |
| 198 |
|
|
fi |
| 199 |
|
|
[ $RESULT -ne 1 ] && echo "No updates found" |
| 200 |
|
|
} |
| 201 |
|
|
|
| 202 |
|
|
update_revdata () { |
| 203 |
|
|
cp $rev_file $rev_file~ |
| 204 |
|
|
egrep -v "^$1" $rev_file~ >$rev_file |
| 205 |
|
|
|
| 206 |
|
|
# Keep the last three revisions in $rev_file |
| 207 |
|
|
local REV |
| 208 |
|
|
local counter=1 |
| 209 |
|
|
echo -n "$1" >>$rev_file |
| 210 |
|
|
for REV in $2; do |
| 211 |
|
|
echo -en "\t$REV" >>$rev_file |
| 212 |
|
|
counter=$(($counter + 1)) |
| 213 |
|
|
[ $counter -gt 3 ] && break |
| 214 |
|
|
done |
| 215 |
|
|
echo >>$rev_file |
| 216 |
|
|
echo " Revision updated" |
| 217 |
|
|
} |
| 218 |
|
|
|
| 219 |
|
|
update_one () { |
| 220 |
|
|
local file=$1 |
| 221 |
|
|
check_one $file |
| 222 |
|
|
if [ $? -eq 1 ] ; then |
| 223 |
|
|
update_revdata $1 "$REV $(get_trev $1 all)" |
| 224 |
|
|
fi |
| 225 |
|
|
} |
| 226 |
|
|
|
| 227 |
|
|
do_update () { |
| 228 |
|
|
if [ -n "$file" ] ; then |
| 229 |
|
|
update_one $file |
| 230 |
|
|
else |
| 231 |
|
|
for file in $(find ./en/ -name "*.xml" | sed "s:^./::" | sed "s:^en/::"); do |
| 232 |
|
|
update_one $file |
| 233 |
|
|
done |
| 234 |
|
|
fi |
| 235 |
|
|
} |
| 236 |
|
|
|
| 237 |
|
|
do_add_one () { |
| 238 |
|
|
if egrep "^$file" $rev_file ; then |
| 239 |
|
|
echo "Error: revision data already has '$file'" |
| 240 |
|
|
exit 1 |
| 241 |
|
|
fi |
| 242 |
|
|
|
| 243 |
|
|
REV=$(get_rev $1) |
| 244 |
|
|
[ $? -ne 0 ] && exit 1 |
| 245 |
|
|
|
| 246 |
|
|
echo -e "$file\t$REV" >>$rev_file |
| 247 |
|
|
} |
| 248 |
|
|
|
| 249 |
|
|
do_add_all () { |
| 250 |
|
|
for file in $(find ./en/ -name "*.xml" | sed "s:^./::" | sed "s:^en/::"); do |
| 251 |
|
|
if [ -f $rev_file ] && egrep "^$file" $rev_file ; then |
| 252 |
|
|
continue |
| 253 |
|
|
fi |
| 254 |
|
|
|
| 255 |
|
|
REV=$(get_rev $file) |
| 256 |
|
|
[ $? -ne 0 ] && continue |
| 257 |
|
|
|
| 258 |
|
|
echo -e "$file\t$REV" >>$rev_file |
| 259 |
|
|
echo "Added '$file' at $REV" |
| 260 |
|
|
done |
| 261 |
|
|
} |
| 262 |
|
|
|
| 263 |
|
|
do_convert () { |
| 264 |
|
|
for file in $(find ./en/ -name "*.xml" | sed "s:^./::" | sed "s:^en/::"); do |
| 265 |
|
|
if [ -f ./$lang/$file ]; then |
| 266 |
|
|
REV="$(egrep '^<\!--[[:space:]]*original version:' ./$lang/$file | \ |
| 267 |
|
|
sed 's/^.*original version:[[:space:]]*//' | cut -d " " -f 1)" |
| 268 |
|
|
if [ -z "$REV" ] ; then |
| 269 |
|
|
echo "Warning: no revision comment found for './$lang/$file'" |
| 270 |
|
|
else |
| 271 |
|
|
echo -e "$file\t$REV" >>$rev_file |
| 272 |
|
|
fi |
| 273 |
|
|
else |
| 274 |
|
|
echo "Warning: file './$lang/$file' not found" |
| 275 |
|
|
fi |
| 276 |
|
|
done |
| 277 |
|
|
} |
| 278 |
|
|
|
| 279 |
|
|
|
| 280 |
|
|
## MAINLINE |
| 281 |
|
|
|
| 282 |
|
|
[ -d ./po/revdata ] || exit 1 |
| 283 |
|
|
|
| 284 |
|
|
parse_opts "$@" |
| 285 |
|
|
rev_file=./po/revdata/$lang.dat |
| 286 |
|
|
|
| 287 |
|
|
if [ "$command" = "convert" ] || \ |
| 288 |
|
|
( [ "$command" = "add" ] && [ "$do_all" ] ) ; then |
| 289 |
|
|
if [ -s $rev_file ] ; then |
| 290 |
|
|
echo "Error: file with revision data already exists" |
| 291 |
|
|
exit 1 |
| 292 |
|
|
fi |
| 293 |
|
|
else |
| 294 |
|
|
if [ ! -s $rev_file ] ; then |
| 295 |
|
|
echo "Error: file with revision data does not exist" |
| 296 |
|
|
exit 1 |
| 297 |
|
|
fi |
| 298 |
|
|
fi |
| 299 |
|
|
|
| 300 |
|
|
case $command in |
| 301 |
|
|
check) |
| 302 |
|
|
do_check |
| 303 |
|
|
;; |
| 304 |
|
|
update) |
| 305 |
|
|
do_update |
| 306 |
|
|
;; |
| 307 |
|
|
add) |
| 308 |
|
|
[ "$do_all" ] && do_add_all || do_add_one |
| 309 |
|
|
;; |
| 310 |
|
|
convert) |
| 311 |
|
|
do_convert |
| 312 |
|
|
;; |
| 313 |
|
|
esac |
| 314 |
|
|
|
| 315 |
|
|
exit 0 |