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