Last active
August 29, 2015 14:02
-
-
Save obfusk/f83d79e85680a2ee1f4d to your computer and use it in GitHub Desktop.
fake update for fsfe website translations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -- ; {{{1 | |
# | |
# File : fake-update.sh | |
# Maintainer : Felix C. Stegerman <flx@fsfe.org> | |
# Date : 2014-06-02 | |
# | |
# Copyright : Copyright (C) 2014 Felix C. Stegerman | |
# Licence : AGPLv3+ | |
# | |
# Usage : fake-update.sh <file> | |
# | |
# Description: | |
# | |
# Given an updated (and committed!) English xhtml file, determines | |
# the date of the previous commit of that file and determines which | |
# translations were not outdated (i.e. more than 2 hours older). It | |
# then asks whether to add <!-- fake-updated ... --> comments to | |
# those files to fake-update them. Then it shows the svn status and | |
# asks the user whether to perform an svn diff and an svn commit. | |
# | |
# Example: | |
# | |
# $ vim foo.en.xhtml # fix some small error that should not | |
# # impact up-to-date translations | |
# $ svn commit ... # commit the fix | |
# $ fake-update.sh # fake-update the previously not-outdated | |
# # translations and commit | |
# | |
# -- ; }}}1 | |
set -e; shopt -s nullglob; set -o pipefail | |
export LC_ALL=C TZ=UTC | |
file="$1" | |
base="$( basename "$file" .en.xhtml )" | |
[ -n "$file" ] || { echo 'Usage: fake-update.sh <file>' >&2; exit 1; } | |
v () { test "$VERBOSE" = yes; } | |
# Usage: get_date <file> [<n>] | |
get_date () { | |
local f="$1" n="${2:-1}" | |
local date="$( svn log --non-interactive -l "$n" ./"$f" \ | |
| grep -E '^r[0-9]+ \|' | tail -n 1 \ | |
| sed -r 's!^.*\| ([0-9]{4}-[^\|]*) \|.*$!\1!' )" | |
date +%s -d "$date" | |
} | |
now="$( date +'%F %T' )" | |
rev="$( svn log --non-interactive -l 1 "$file" | head -n 2 \ | |
| grep -Eo '^r[0-9]+' | head -n 1 )" | |
cur_date="$( get_date "$file" )" | |
prev_date="$( get_date "$file" 2 )" | |
! v || { | |
echo "revision: $rev" | |
echo "current date: $cur_date" "| $( date +'%F %T' -d "@$cur_date" )" | |
echo "previous date: $prev_date" "| $( date +'%F %T' -d "@$prev_date" )" | |
} | |
not_outdated=() | |
for x in "$base".*.xhtml; do | |
[[ "$x" != "$base".en.xhtml ]] || continue | |
x_date="$( get_date "$x" )" | |
! v || echo "date of $x: $x_date" "| $( date +'%F %T' -d "@$x_date" )" | |
if (( cur_date > x_date + 7200 && prev_date <= x_date + 7200 )); then | |
not_outdated+=( "$x" ) | |
echo "$x was not outdated" | |
fi | |
done | |
echo; read -r -p 'fake-update? [Yn] ' | |
if [[ "$REPLY" != [Nn]* ]]; then | |
for x in "${not_outdated[@]}"; do | |
echo "<!-- fake-updated $now; see $rev -->" >> "$x" | |
done | |
else | |
exit 0 | |
fi | |
echo; echo '==> svn status' | |
svn status | |
echo; read -r -p 'diff? [Yn] ' | |
[[ "$REPLY" = [Nn]* ]] || svn diff | |
echo; read -r -p 'commit? [Yn] ' | |
[[ "$REPLY" = [Nn]* ]] || svn commit -m "fake-updated translations of $file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment