]> git.lyx.org Git - features.git/blob - development/tools/update-po.sh
Port changes to update-po.sh.
[features.git] / development / tools / update-po.sh
1 #!/bin/sh
2 # A script to check whether there have been any string changes.
3 # If it finds some, it commits the new po files and then updates
4 # the stats.
5
6 # The script expects an environment variable FARM that will provide 
7 # it with the location of the LyX www tree.
8
9 DEBUG="";
10
11 while getopts ":dh" options $ARGS; do
12   case $options in
13     d)  DEBUG="echo";;
14     h)  echo "check-po.sh [-d]"; 
15         echo "You must also point the FARM variable to LyX's www tree."; 
16         exit 0;;
17   esac
18 done
19
20 if [ -z "$FARM" ]; then
21   echo "You must set the FARM variable to run this script, e.g.:";
22   echo "# FARM=/cvs/lyx-www/ bash check-po.sh";
23   exit 1;
24 fi
25
26 FARM=${FARM%/};
27 FARM="$FARM/farm/cookbook/LyX";
28 # Sanity check
29 if [ ! -f "$FARM/i18n.php" ]; then 
30   echo "$FARM does not look like LyX's www tree!";
31   exit 1;
32 fi
33
34 # Get us to the root of the tree we are in.
35 MYDIR=${0%check-po.sh};
36 if [ -n "$MYDIR" ]; then
37   cd $MYDIR;
38 fi
39 cd ../../;
40 LYXROOT=$(pwd);
41
42 # Are we in trunk or branch?
43 TRUNK="TRUE";
44 if ls status.* 2>/dev/null | grep -q status; then 
45   TRUNK="";
46 fi
47
48 # Git or SVN?
49 VCS="";
50 if svn log >/dev/null 2>&1; then
51   VCS="svn";
52 elif git diff >/dev/null 2>&1; then
53   VCS="git";
54 fi
55
56 if [ -z "$VCS" ]; then 
57   echo "Unable to determine version control system!";
58   exit 1;
59 fi
60
61 # Sanity check
62 if ! cd po/; then 
63   echo "Cannot cd to po/ directory!";
64   pwd
65   exit 1;
66 fi
67
68 echo Remerging...
69 make update-po >/dev/null 2>&1;
70 echo
71
72 if [ -n "$TRUNK" ]; then
73   I18NFILE=i18n_trunk.inc;
74 else
75   I18NFILE=i18n.inc;
76 fi
77
78 # make sure things are clean
79 rm -f i18n.inc;
80 svn revert $FARM/$I18NFILE;
81
82 echo Running make i18n.inc...
83 make i18n.inc  >/dev/null 2>&1;
84 if [ -n "$TRUNK" ]; then
85   mv -f i18n.inc i18n_trunk.inc
86 fi
87
88 if diff -w -q $I18NFILE $FARM/$I18NFILE >/dev/null 2>&1; then
89   echo No string differences found.
90   # So we will revert the changes to po files, which are probably
91   # just dates and such.
92   if [ "$VCS" = "svn" ]; then
93     svn revert *.po;
94   else
95     git checkout *.po;
96   fi
97   exit 0;
98 fi
99
100 # So there are differences.
101 if [ "$VCS" = "svn" ]; then
102   $DEBUG svn ci *.po;
103 else
104   # We need to make sure that we have a tree without any unpushed 
105   # commits. Otherwise git svn dcommit would commit more than we
106   # want.
107   NOTSAFE="";
108   if git status | grep -Pq 'Your branch is (?:ahead|behind)'; then
109     NOTSAFE="TRUE";
110   fi
111   $DEBUG git commit *.po -m "Remerge strings.";
112   if [ -z "$NOTSAFE" ]; then
113     $DEBUG git svn dcommit;
114   fi
115 fi
116
117 echo
118
119 if ! cd $FARM; then
120   echo "Unable to cd to $FARM!";
121   exit 1;
122 fi
123
124 echo Updating the www-user tree...
125 # note that we're assuming this one is svn.
126 svn up;
127
128 echo Moving $I18NFILE...;
129 mv $LYXROOT/po/$I18NFILE .;
130
131 echo Committing...;
132 $DEBUG svn commit -m "* $I18NFILE: update stats" $I18NFILE;
133
134 if [ -n "$NOTSAFE" ]; then
135   echo
136   echo "Your LyX tree was not clean.";
137   echo "Your will need to push changes to po files manually."
138 fi