[extra] Import Firefox 3.0 beta 5 tarball
[mozilla-extra.git] / extensions / irc / xpi / makelocalexpi.sh
blob567bb4a55379240f76cc35dad2080ac2d1183465
1 #!/bin/sh
3 # Set up locale.
4 if [ -z "$AB_CD" ]; then
5 if [ -z "$1" ]; then AB_CD=en-US; else AB_CD=$1; fi
6 fi
7 # Set up settings and paths for finding files.
8 if [ -z "$DEBUG" ]; then DEBUG=0; fi
9 if [ -z "$PERL" ]; then PERL=perl; fi
10 if [ -z "$FEDIR" ]; then FEDIR=$PWD/..; fi
11 if [ -z "$CONFIGDIR" ]; then CONFIGDIR=$FEDIR/../../config; fi
12 if [ -z "$XPIROOT" ]; then XPIROOT=$PWD/xpi-tree-$AB_CD; fi
13 if [ -z "$JARROOT" ]; then JARROOT=$PWD/jar-tree-$AB_CD; fi
14 if [ -z "$LOCALEDIR" ]; then LOCALEDIR=$FEDIR/locales; fi
15 # the dir containing the actual localisation files
16 # usually this is in l10n/ repository (parallel to mozilla/)
17 # note that toolkit/defines.inc is expected in parallel to extensions/irc there
18 if [ -z "$L10NDIR" ]; then L10NDIR="$FEDIR/../../../l10n/$AB_CD/extensions/irc"; fi
20 # Display all the settings and paths if we're in debug mode.
21 if [ $DEBUG -ge 1 ]; then
22 echo "\$DEBUG = $DEBUG"
23 echo "\$PERL = $PERL"
24 echo "\$CONFIGDIR = $CONFIGDIR"
25 echo "\$XPIROOT = $XPIROOT"
26 echo "\$JARROOT = $JARROOT"
27 echo "\$FEDIR = $FEDIR"
28 echo "\$LOCALEDIR = $LOCALEDIR"
29 echo "\$AB_CD = $AB_CD"
30 echo "\$L10NDIR = $L10NDIR"
33 ## Simple function to display all the parameters/arguments to itself.
34 function showParams()
36 I=0
37 for P in "$@"; do
38 I=$((I+1))
39 echo PARAM $I: "$P"
40 done
43 ## Call this with lots of parameters to run a command, log errors, and abort
44 ## if it fails. Supports redirection if '>' and '<' are passed as arguments,
45 ## e.g.:
46 ## safeCommand cmd arg1 arg2 '<' input.file '>' output-file
48 ## Note: only a single input and single output redirection is supported.
50 function safeCommand()
52 local -a CMD
53 CMD_COUNT=$((0))
54 INF=""
55 OUTF=""
56 LASTP=""
57 for P in "$@"; do
58 if [ "$LASTP" = "<" ]; then
59 if [ -n "$INF" ]; then
60 echo "ERROR: Multiple input files passed to safeCommand()." >&2
61 exit 2
63 INF="$P"
64 elif [ "$LASTP" = ">" ]; then
65 if [ -n "$OUTF" ]; then
66 echo "ERROR: Multiple output files passed to safeCommand()." >&2
67 exit 2
69 OUTF="$P"
70 elif [ "$P" = ">" -o "$P" = "<" ]; then
71 echo >/dev/null
72 else
73 CMD[$CMD_COUNT]="$P"
74 CMD_COUNT=$((CMD_COUNT+1))
76 LASTP="$P"
77 done
79 if [ $DEBUG -gt 0 ]; then
80 echo
81 showParams "${CMD[@]}"
82 echo 'INPUT :' "$INF"
83 echo 'OUTPUT :' "$OUTF"
86 touch log.stdout log.stderr
87 if [ -z "$INF" -a -z "$OUTF" ]; then
88 "${CMD[@]}" 1>log.stdout 2>log.stderr
89 elif [ -z "$INF" ]; then
90 "${CMD[@]}" 1> "$OUTF" 2>log.stderr
91 elif [ -z "$OUTF" ]; then
92 "${CMD[@]}" < "$INF" 1>log.stdout 2>log.stderr
93 else
94 "${CMD[@]}" < "$INF" 1> "$OUTF" 2>log.stderr
97 EC=$?
98 if [ $DEBUG -gt 0 ]; then
99 echo 'RESULT :' $EC
101 if [ "$EC" != "0" ]; then
102 echo "ERROR ($EC)"
103 cat log.stdout
104 cat log.stderr
105 rm -f log.stdout log.stderr
106 exit 1
108 rm -f log.stdout log.stderr
109 return $EC
113 ## Begin real program ##
116 if [ "$1" = "clean" ]; then
117 echo -n "Cleaning up files"
118 echo -n .
119 rm -rf "$XPIROOT"
120 echo -n .
121 rm -rf "$JARROOT"
122 echo ". done."
124 exit
127 # Check that requested language is in all-locales file (i.e. exists and it
128 # allowed to be used).
129 # FIXME: THIS DOES NOT WORK WITH CYGWIN.
130 grep -sx "$AB_CD" "$LOCALEDIR/all-locales" > /dev/null
131 if [ $? != 0 ]; then
132 echo "ERROR: Language $AB_CD is currently not supported."
133 exit 1
135 if [ $DEBUG -ge 1 ]; then echo "Language = $AB_CD"; fi
138 # Check directory setup.
139 if ! [ -d "$FEDIR" ]; then
140 echo "ERROR: Base ChatZilla directory (FEDIR) not found."
141 exit 1
143 if ! [ -d "$CONFIGDIR" ]; then
144 echo "ERROR: mozilla/config directory (CONFIGDIR) not found."
145 exit 1
147 if ! [ -d "$L10NDIR" ]; then
148 echo "ERROR: Directory with localized files for $AB_CD language (L10NDIR) not found."
149 exit 1
153 # Extract version number.
154 VERSION=`grep "const __cz_version" "$FEDIR/xul/content/static.js" | sed "s|.*\"\([^\"]\{1,\}\)\".*|\1|"`
155 BASE_VERSION=`echo "$VERSION" | sed "s|\([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\).*|\1|"`
157 if [ -z "$VERSION" ]; then
158 echo "ERROR: Unable to get version number."
159 exit 1
162 echo "Beginning build of $AB_CD language pack for ChatZilla $VERSION..."
164 # Set up LangPack XPI name using version and language.
165 XPINAME="chatzilla-$VERSION.$AB_CD.xpi"
167 # Check for an existing XPI file and print a warning.
168 if [ -r "$XPINAME" ]; then
169 echo " WARNING: output XPI will be overwritten."
173 # Check for required directory layouts.
174 echo -n " Checking XPI structure"
175 echo -n .
176 if ! [ -d "$XPIROOT" ]; then mkdir -p $XPIROOT; fi
177 echo -n .
178 if ! [ -d "$XPIROOT/chrome" ]; then mkdir $XPIROOT/chrome; fi
179 echo ". done"
181 echo -n " Checking JAR structure"
182 echo -n .
183 if ! [ -d "$JARROOT" ]; then mkdir -p $JARROOT; fi
184 echo ". done"
187 # Make Firefox updates.
188 echo -n " Updating Firefox Extension files"
189 echo -n .
190 # make sure we have all defines we need when preprocessing the install.rdf file
191 # toolkit/defines.inc contains the definition for the locale name we use in the langpack title
192 safeCommand $PERL "$CONFIGDIR/preprocessor.pl" -DAB_CD=$AB_CD -DCHATZILLA_VERSION=$VERSION -DCHATZILLA_BASE_VERSION=$BASE_VERSION -DINSTALL_EXTENSION_ID=langpack-$AB_CD@chatzilla.mozilla.org -I$L10NDIR/../../toolkit/defines.inc -I$L10NDIR/defines.inc "$LOCALEDIR/generic/install.rdf" '>' "$XPIROOT/install.rdf"
193 echo -n .
194 echo ". done"
197 # Make Mozilla Suite updates.
198 echo -n " Updating Mozilla Extension files"
199 echo -n .
200 # make sure we have all defines we need when preprocessing the install.js file
201 # toolkit/defines.inc contains the definition for the locale name we use in the langpack title
202 safeCommand $PERL "$CONFIGDIR/preprocessor.pl" -DAB_CD=$AB_CD -DCHATZILLA_VERSION=$VERSION -DCHATZILLA_BASE_VERSION=$BASE_VERSION -DINSTALL_EXTENSION_ID=langpack-$AB_CD@chatzilla.mozilla.org -I$L10NDIR/../../toolkit/defines.inc -I$L10NDIR/defines.inc "$LOCALEDIR/generic/install.js" '>' "$XPIROOT/install.js"
203 echo -n .
204 echo ". done"
207 # Create JAR.
208 echo -n " Constructing JAR package"
209 echo -n .
210 OLDPWD=`pwd`
211 cd "$CONFIGDIR"
212 echo -n .
214 safeCommand $PERL preprocessor.pl -DAB_CD="$AB_CD" "$LOCALEDIR/jar.mn" '>' "$LOCALEDIR/jar.mn.pp"
215 echo -n .
216 safeCommand $PERL make-jars.pl -v -z zip -p preprocessor.pl -s "$LOCALEDIR" -d "$JARROOT" -c "$L10NDIR" -- "-DAB_CD=\"$AB_CD\" -DMOZILLA_LOCALE_VERSION=\"\"" '<' "$LOCALEDIR/jar.mn.pp"
217 echo -n .
218 safeCommand rm "$LOCALEDIR/jar.mn.pp"
219 cd "$OLDPWD"
220 echo ". done"
223 # Make XPI.
224 echo -n " Constructing XPI package"
225 echo -n .
226 safeCommand cp -v "$JARROOT/chatzilla.jar" "$XPIROOT/chrome/"
227 echo -n .
228 safeCommand chmod 664 "$XPIROOT/chrome/chatzilla.jar"
229 echo -n .
230 OLDPWD=`pwd`
231 cd "$XPIROOT"
232 safeCommand zip -vr ../$XPINAME . -i "*" -x "log*"
233 cd "$OLDPWD"
234 echo ". done"
237 echo "Build of $AB_CD language pack for ChatZilla $VERSION... ALL DONE"