build 13.2 KB
Newer Older
boklm's avatar
boklm committed
1
#!/bin/bash
2
[% c("var/set_default_env") -%]
boklm's avatar
boklm committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
distdir=/var/tmp/dist/[% project %]
export TORBROWSER_VERSION='[% c("version") %]'

mkdir -p $distdir

OUTDIR='[% dest_dir _ "/" _ c("filename") %]'
mkdir -p $OUTDIR

# When we build with MULTI_LINGUAL=1, the browser will be packaged inside a
# directory named tor-browser (instead of tor-browser_en-US). Therefore we
# stage everything under tor-browser-stage to avoid a conflict.
TB_STAGE_DIR=$distdir/tor-browser-stage

[% IF c("var/osx") %]
  TBDIR=$TB_STAGE_DIR/TorBrowser.app

  DOCSPATH=Contents/Resources/TorBrowser/Docs
  EXTSPATH=Contents/Resources/distribution/extensions
  TORBINPATH=Contents/MacOS/Tor
  TORCONFIGPATH=Contents/Resources/TorBrowser/Tor
  EXTOVERRIDESPATH=Contents/Resources/distribution/preferences//extension-overrides.js
  MEEKPROFILEPATH=Contents/Resources/TorBrowser/Tor/PluggableTransports/template-profile.meek-http-helper

  tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/libdmg') %]
  export PATH=/var/tmp/dist/libdmg-hfsplus:$PATH
[% ELSE %]
  TBDIR=$TB_STAGE_DIR/Browser

  DOCSPATH=TorBrowser/Docs
  EXTSPATH=TorBrowser/Data/Browser/profile.default/extensions
33
  TORCONFIGPATH=TorBrowser/Data/Tor
boklm's avatar
boklm committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  EXTOVERRIDESPATH=TorBrowser/Data/Browser/profile.default/preferences/extension-overrides.js
  MEEKPROFILEPATH=TorBrowser/Data/Browser/profile.meek-http-helper

  mkdir -p $TBDIR/TorBrowser/Data/Browser/Caches
[% END %]

mkdir -p $TBDIR/$EXTSPATH
mkdir -p $TBDIR/$MEEKPROFILEPATH/extensions

# Extract the MAR tools.
unzip -d $rootdir $rootdir/[% c('input_files_by_name/firefox') %]/mar-tools-*.zip
MARTOOLS=$rootdir/mar-tools

mv [% c('input_files_by_name/tor-launcher') %] $TBDIR/$EXTSPATH/tor-launcher@torproject.org.xpi
mv [% c('input_files_by_name/torbutton') %] $TBDIR/$EXTSPATH/torbutton@torproject.org.xpi
mv [% c('input_files_by_name/https-everywhere') %] $TBDIR/$EXTSPATH/https-everywhere-eff@eff.org.xpi
mv [% c('input_files_by_name/noscript') %] $TBDIR/$EXTSPATH/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi

boklm's avatar
boklm committed
52
53
54
tar -C $TBDIR -xf [% c('input_files_by_name/obfs4') %]
tar -C $TBDIR -xf [% c('input_files_by_name/meek') %]
mv $TBDIR/meek-http-helper@bamsoftware.com.xpi $TBDIR/$MEEKPROFILEPATH/extensions/
boklm's avatar
boklm committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

tar -C $TBDIR[% IF c("var/osx") %]/Contents/Resources[% END %] -xf [% c('input_files_by_name/fonts') %]

[% IF c("var/linux") %]
  cp RelativeLink/* ${TB_STAGE_DIR}/Browser/
  cp RelativeLink/start-tor-browser.desktop ${TB_STAGE_DIR}/
[% END %]

tar -C ${TB_STAGE_DIR} -xf [% c('input_files_by_name/firefox') %]/tor-browser.tar.gz
tar -C $TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %] -xf [% c('input_files_by_name/tor') %]/tor.tar.gz

[% IF c("var/linux");
     SET bundledata_osname = 'linux';
   ELSIF c("var/osx");
     SET bundledata_osname = 'mac';
   ELSIF c("var/windows");
     SET bundledata_osname = 'windows';
   END; %]

[% IF c("var/osx") %]
  # The Bundle-Data is designed for embedded data, so we need to modify
  # the structure when we want the data to be outside the app directory.
  # We also create an override.ini file to disable the profile migrator.
  SKELETON_TMP=$rootdir/Bundle-Data/mac-skeleton-tmp
  SKELETON_TMP_RESOURCES=$SKELETON_TMP/Contents/Resources
  mkdir -p $SKELETON_TMP_RESOURCES/browser
  echo "[XRE]" > $SKELETON_TMP_RESOURCES/browser/override.ini
  echo "EnableProfileMigrator=0" >> $SKELETON_TMP_RESOURCES/browser/override.ini
  mkdir -p $SKELETON_TMP_RESOURCES/distribution/preferences
  cp -p Bundle-Data/mac/TorBrowser/Data/Browser/profile.default/preferences/extension-overrides.js $SKELETON_TMP_RESOURCES/distribution/preferences
  mkdir -p $SKELETON_TMP_RESOURCES/TorBrowser/Tor
  cp -p Bundle-Data/mac/TorBrowser/Data/Tor/torrc-defaults $SKELETON_TMP_RESOURCES/TorBrowser/Tor/
  # Place a copy of the bookmarks.html file at the top. It will be moved into
  # browser/omni.ja later
  cp -p Bundle-Data/mac/TorBrowser/Data/Browser/profile.default/bookmarks.html $rootdir
  rm -Rf Bundle-Data/mac
  mv $SKELETON_TMP Bundle-Data/mac


  # Install a "tor" shim that sets the working directory. See #10030.
  mv $TBDIR/$TORBINPATH/tor $TBDIR/$TORBINPATH/tor.real
  cp Bundle-Data/mac-tor.sh $TBDIR/$TORCONFIGPATH/tor

  SANDBOX_FOLDER="$TB_STAGE_DIR/Sandboxed Tor Browser"
  mv Bundle-Data/mac-sandbox "$SANDBOX_FOLDER"

  tar -C Bundle-Data/mac-applications.dmg -c . | tar -C $TB_STAGE_DIR -x
[% END %]

boklm's avatar
boklm committed
104
105
mkdir -p $TBDIR/$DOCSPATH
cp -a Bundle-Data/Docs/* $TBDIR/$DOCSPATH
boklm's avatar
boklm committed
106
107
tar -C Bundle-Data/[% bundledata_osname %] -c . | tar -C $TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %] -x

boklm's avatar
boklm committed
108
109
110
111
112
113
114
115
116
117
118
119
cat Bundle-Data/PTConfigs/[% bundledata_osname %]/torrc-defaults-appendix >> $TBDIR/$TORCONFIGPATH/torrc-defaults
cat Bundle-Data/PTConfigs/bridge_prefs.js >> $TBDIR/$EXTOVERRIDESPATH
cat Bundle-Data/PTConfigs/meek-http-helper-user.js >> $TBDIR/$MEEKPROFILEPATH/user.js

[% IF c("var/osx") %]
  pushd $TBDIR
  # Create the meek-template-sha256sum.txt file by generating a list
  # of hashes (one for each file within the meek-http-helper profile) and
  # and then generating one final hash from the contents of the list.
  sha256sum `find $MEEKPROFILEPATH -type f | sort` | sha256sum | sed -e 's/ *-$//' > $MEEKPROFILEPATH/meek-template-sha256sum.txt
  popd
[% END %]
boklm's avatar
boklm committed
120

boklm's avatar
boklm committed
121
[% IF ! c("var/multi_lingual") %]
boklm's avatar
boklm committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
  echo 'pref("extensions.torlauncher.prompt_for_locale", false);' >> $TBDIR/$EXTOVERRIDESPATH
  echo 'pref("intl.locale.matchOS", false);' >> $TBDIR/$EXTOVERRIDESPATH
[% END %]

[% IF c("var/linux") %]
  chmod 700 ${TB_STAGE_DIR}/Browser/TorBrowser/Data/Browser
  chmod 700 ${TB_STAGE_DIR}/Browser/TorBrowser/Data/Tor
[% END %]

[% IF c("var/multi_lingual") %]
  # If we are building a multi-lingual package, use "ALL" in the package name
  # and as the locale for update purposes. We do not include "ALL" in the name
  # of the directory that is inside the package (in other words, users will
  # not see tor-browser_ALL after they install Tor Browser).
  PKG_LOCALE="ALL"
  PKG_DIR="tor-browser"
[% ELSE %]
  PKG_LOCALE="en-US"
  PKG_DIR="tor-browser_${PKG_LOCALE}"
[% END %]


pushd $TBDIR[% IF c("var/osx") %]/Contents/Resources[% END %]/browser/
# For the proper search engines in our language packs
unzip omni.ja chrome/en-US/locale/browser/searchplugins* || [ $? -lt 3 ]
mv chrome/en-US/locale/browser/searchplugins $rootdir
rm -rf chrome/en-US
unzip omni.ja defaults/preferences/000-tor-browser.js || [ $? -lt 3 ]
cp defaults/preferences/000-tor-browser.js $rootdir
[% IF c("var/osx") %]
  # Embed our default bookmarks.
  mkdir -p defaults/profile/
  cp -p $rootdir/bookmarks.html defaults/profile/
  [% c("var/touch") %] defaults/profile/bookmarks.html
  zip -Xm omni.ja defaults/profile/bookmarks.html
[% END %]
# Set the locale of the bundle.
echo "pref(\"general.useragent.locale\", \"en-US\");" >> defaults/preferences/000-tor-browser.js
[% c("var/touch") %] defaults/preferences/000-tor-browser.js
zip -Xm omni.ja defaults/preferences/000-tor-browser.js
rm -rf defaults
popd

# Prepare our language packs for using the proper search engines. See bug
# 18915 for more details.
[% FOREACH lang = c('var/locales') %]
[% SET lang = tmpl(lang);
   SET xpi = '$rootdir/' _ c('input_files_by_name/firefox-langpacks') _ '/' _ lang _ '.xpi';
   %]
  unzip -d prep_[% lang %] [% xpi %]
  search_plugins_path=prep_[% lang %]/browser/chrome/[% lang %]/locale/browser
  rm -rf $search_plugins_path/searchplugins
  cp -rf $rootdir/searchplugins $search_plugins_path
  rm [% xpi %]
  cd prep_[% lang %]
  [% c('zip', {
          zip_src => [ '.' ],
          zip_args => xpi,
      }) %]
  # If we are building a multi-lingual package, add all of the language packs.
  [% IF c("var/multi_lingual") %]
    cp [% xpi %] $TBDIR/$EXTSPATH/langpack-[% lang %]@firefox.mozilla.org.xpi
  [% END %]
  cd ..
  rm -rf prep_[% lang %]
[% END %]

[% IF c("var/multi_lingual") %]
  # Set the update.locale (it is used to replace %LOCALE% within
  # app.update.url).
  pushd $TBDIR[% IF c("var/osx") %]/Contents/Resources/[% END %]
  echo ${PKG_LOCALE} > update.locale
  [% c("var/touch") %] update.locale
  zip -Xm omni.ja update.locale
  popd
[% END %]


[% IF c("var/windows") %]
  # We need to install a recent version of python-pefile so that it works
  # in a x86_64 container:
  # https://github.com/TheTorProject/tor-messenger-build/pull/10
  tar xf $rootdir/[% c('input_files_by_name/python-future') %]
  cd $(echo [% c('input_files_by_name/python-future') %] | sed s/\.tar\.gz$//)
  python setup.py install --user
  cd ..

  tar xf $rootdir/[% c('input_files_by_name/python-pefile') %]
  cd $(echo [% c('input_files_by_name/python-pefile') %] | sed s/\.tar\.gz$//)
  python setup.py install --user
  cd ..

  tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/nsis') %]
  export PATH="/var/tmp/dist/nsis/bin:$PATH"

  tar -C $distdir -xf $rootdir/[% c('input_files_by_name/tbb-windows-installer') %]

  mv ${TB_STAGE_DIR} $distdir/tbb-windows-installer/"Tor Browser"
  mv $distdir/tbb-windows-installer ${TB_STAGE_DIR}
[% END %]

cp -a ${TB_STAGE_DIR} $distdir/$PKG_DIR

[% IF c("var/windows") %]
  TBDIR=$distdir/$PKG_DIR/"Tor Browser"/Browser
[% ELSIF c("var/osx") %]
  TBDIR=$distdir/$PKG_DIR/TorBrowser.app
[% ELSE %]
  TBDIR=$distdir/$PKG_DIR/Browser
[% END %]

pushd "$TBDIR[% IF c("var/osx") %]/Contents/Resources/[% END %]"
rm -f precomplete
python $MARTOOLS/createprecomplete.py
popd

cd $distdir
boklm's avatar
boklm committed
239
240
241
242
243
244
245

[% IF c("var/build_mar") -%]
  # Create full MAR file and compressed package.
  MAR_FILE=tor-browser-[% c("var/mar_osname") %]-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.mar
  MAR=$MARTOOLS/mar MBSDIFF=$MARTOOLS/mbsdiff $MARTOOLS/make_full_update.sh -q $OUTDIR/$MAR_FILE "$TBDIR"
[% END -%]

boklm's avatar
boklm committed
246
247
248
249
250
251
252
253
[% IF c("var/linux") %]
  [% c('tar', {
        tar_src => [ '$PKG_DIR' ],
        tar_args => '-cJf $OUTDIR/tor-browser-' _ c("var/mar_osname") _ '-' _ c("var/torbrowser_version") _ '_${PKG_LOCALE}.tar.xz',
    }) %]
[% ELSIF c("var/osx") %]
  [% c('var/ddmg', {
        dmg_src => '"$PKG_DIR"',
boklm's avatar
boklm committed
254
        dmg_out => '$OUTDIR/TorBrowser-' _ c("var/torbrowser_version") _ '-osx64_${PKG_LOCALE}.dmg',
boklm's avatar
boklm committed
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
    }) %]
[% ELSIF c("var/windows") %]
  pushd "${TB_STAGE_DIR}"
  makensis torbrowser.nsi
  # Working around NSIS braindamage
  mv torbrowser-install.exe torbrowser-install-tmp.exe
  python $rootdir/pe_checksum_fix.py
  mv torbrowser-install-tmp2.exe torbrowser-install.exe
  rm torbrowser-install-tmp.exe
  mv torbrowser-install.exe $OUTDIR/torbrowser-install-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.exe
  popd
[% END %]
rm -rf $distdir/${PKG_DIR}

# If we did not create a multi-lingual package above, create a package for
# each locale.
[% IF ! c("var/multi_lingual") %]
  [% FOREACH lang = c('var/locales') %]
    [% SET lang = tmpl(lang);
       SET xpi = '$rootdir/' _ c('input_files_by_name/firefox-langpacks') _ '/' _ lang _ '.xpi';
       SET tbdir = '$distdir/tor-browser_' _ lang;
       IF c("var/osx");
         SET browserdir = tbdir _ '/TorBrowser.app';
       ELSIF c("var/windows");
         SET browserdir = tbdir _ '/Tor Browser/Browser';
       ELSE;
         SET browserdir = tbdir _ '/Browser';
       END;
    %]
      cp -a ${TB_STAGE_DIR} [% tbdir %]
      cp [% xpi %] "[% browserdir %]/$EXTSPATH/langpack-[% lang %]@firefox.mozilla.org.xpi"

      pushd "[% browserdir %]/[% IF c("var/osx") %]Contents/Resources/[% END %]browser/"
      mkdir -p defaults/preferences
      cp $rootdir/000-tor-browser.js defaults/preferences/
      # Set the locale of the bundle.
      echo "pref(\"general.useragent.locale\", \"[% lang %]\");" >> defaults/preferences/000-tor-browser.js
      [% c("var/touch") %] defaults/preferences/000-tor-browser.js
      zip -Xm omni.ja defaults/preferences/000-tor-browser.js
      rm -rf defaults
      popd

      # Set the update.locale (it is used to replace %LOCALE% within
      # app.update.url), remove the en-US spellchecking dictionary, and
      # recreate precomplete file (needs to be accurate for full MAR updates).
      pushd "[% browserdir %]/[% IF c("var/osx") %]Contents/Resources/[% END %]"
      echo "[% lang %]" > update.locale
      [% c("var/touch") %] update.locale
      zip -Xm omni.ja update.locale
      rm -rf dictionaries
      rm -f precomplete
      python $MARTOOLS/createprecomplete.py
      popd

      # Create full MAR file and compressed package for this locale.
      MAR_FILE=tor-browser-[% c("var/mar_osname") %]-[% c("var/torbrowser_version") %]_[% lang %].mar
      MAR=$MARTOOLS/mar MBSDIFF=$MARTOOLS/mbsdiff $MARTOOLS/make_full_update.sh -q $OUTDIR/$MAR_FILE "[% browserdir %]"
      [% IF c("var/linux") %]
        [% SET tardir = 'tor-browser_' _ lang;
          c('tar', {
                tar_src => [ tardir ],
                tar_args => '-cJf $OUTDIR/tor-browser-' _ c("var/mar_osname") _ '-' _ c("var/torbrowser_version") _ '_' _ lang _ '.tar.xz',
            }) %]
      [% ELSIF c("var/osx") %]
        [% c('var/ddmg', {
          dmg_src => tbdir,
boklm's avatar
boklm committed
321
          dmg_out => '$OUTDIR/TorBrowser-' _ c("var/torbrowser_version") _ '-osx64_' _ lang _ '.dmg',
boklm's avatar
boklm committed
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
        }) %]
      [% ELSIF c("var/windows") %]
        pushd "[% tbdir %]"
        makensis torbrowser.nsi
        # Working around NSIS braindamage
        mv torbrowser-install.exe torbrowser-install-tmp.exe
        python $rootdir/pe_checksum_fix.py
        mv torbrowser-install-tmp2.exe torbrowser-install.exe
        rm torbrowser-install-tmp.exe
        mv torbrowser-install.exe $OUTDIR/torbrowser-install-[% c("var/torbrowser_version") %]_[% lang %].exe
        popd
      [% END %]
      rm -rf [% tbdir %]
  [% END %]
[% END %]