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