build 15.5 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
  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
46
47
48
49
50
[% IF c("var/windows-x86_64") -%]
  # Workaround for bug 24477
  rm -Rf $MARTOOLS
  unzip -d $rootdir $rootdir/mar-tools-linux32.zip
[% END -%]
boklm's avatar
boklm committed
51
52
53
54
55
56

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
57
58
59
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
60
61
62
[% IF c("var/snowflake") %]
  tar -C $TBDIR -xf [% c('input_files_by_name/snowflake') -%]
[% END -%]
boklm's avatar
boklm committed
63

64
65
66
67
[% IF c("var/fteproxy") -%]
  tar -C $TBDIR -xf [% c('input_files_by_name/fteproxy') %]
[% END -%]

boklm's avatar
boklm committed
68
69
70
71
72
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}/
boklm's avatar
boklm committed
73
74
75
76
  cat > ${TB_STAGE_DIR}/Browser/start-tor-browser << 'RBM_TB_EOF'
[% INCLUDE 'RelativeLink/start-tor-browser' -%]
RBM_TB_EOF
  chmod +x ${TB_STAGE_DIR}/Browser/start-tor-browser
boklm's avatar
boklm committed
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
104
105
106
107
108
109
110
111
112
[% 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

113
114
115
116
  [% IF ! c("var/release") -%]
    SANDBOX_FOLDER="$TB_STAGE_DIR/Sandboxed Tor Browser"
    mv Bundle-Data/mac-sandbox "$SANDBOX_FOLDER"
  [% END -%]
boklm's avatar
boklm committed
117
118
119
120

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

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

boklm's avatar
boklm committed
125
cat Bundle-Data/PTConfigs/[% bundledata_osname %]/torrc-defaults-appendix >> $TBDIR/$TORCONFIGPATH/torrc-defaults
126
[% IF c("var/linux") -%]
127
128
129
130
131
132
  [% IF ! c("var/snowflake") %]
    grep -v 'default_bridge\.snowflake' Bundle-Data/PTConfigs/bridge_prefs.js \
       >> $TBDIR/$EXTOVERRIDESPATH
  [% ELSE %]
    cat Bundle-Data/PTConfigs/bridge_prefs.js >> $TBDIR/$EXTOVERRIDESPATH
  [% END %]
133
134
135
[% END -%]
[% IF c("var/windows") -%]
  # We don't have snowflake available on Windows yet
136
137
138
139
  # We don't have fte available on Windows x86_64 yet
  grep -v 'default_bridge\.snowflake' Bundle-Data/PTConfigs/bridge_prefs.js \
  [% IF c("var/windows-x86_64") %]| grep -v 'default_bridge\.fte' [% END %] \
      >> $TBDIR/$EXTOVERRIDESPATH
140
141
142
[% END -%]
[% IF c("var/osx") -%]
  # FTE is temporarily removed due to bug 18495.
143
144
145
  grep -Ev 'default_bridge\.fte' Bundle-Data/PTConfigs/bridge_prefs.js \
  [% IF ! c("var/snowflake") %]| grep -v 'default_bridge\.snowflake' [% END %] \
      >> $TBDIR/$EXTOVERRIDESPATH
146
[% END -%]
boklm's avatar
boklm committed
147
148
149
150
151
152
153
154
155
156
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
157

boklm's avatar
boklm committed
158
[% IF ! c("var/multi_lingual") %]
boklm's avatar
boklm committed
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
  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") %]
189
190
191
192
193
194
  # Embed our default bookmarks within the en-US locale.
  mkdir -p chrome/en-US/locale/browser
  cp -p $rootdir/bookmarks.html chrome/en-US/locale/browser/
  [% c("var/touch") %] chrome/en-US/locale/browser/bookmarks.html
  zip -Xm omni.ja chrome/en-US/locale/browser/bookmarks.html
  rm -rf chrome
boklm's avatar
boklm committed
195
196
197
198
199
200
[% 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
boklm's avatar
boklm committed
201
202
# create tbb_version.json file for #25020
echo '{"version":"[% c("var/torbrowser_version") %]","architecture":"[% c("var/mar_osname") %]","channel":"[% c("var/channel") %]","locale":"en-US"}' > ../tbb_verson.json
boklm's avatar
boklm committed
203
204
popd

205
206
# Prepare our language packs for using the proper search engines and embed
# our default bookmarks. See bugs 18915 and 21879 for more details.
boklm's avatar
boklm committed
207
208
209
210
211
212
213
214
[% 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
215
216
217
  [% IF c("var/osx") -%]
    cp $rootdir/bookmarks.html prep_[% lang %]/browser/chrome/[% lang %]/locale/browser/
  [% END -%]
boklm's avatar
boklm committed
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
  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") %]
  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
269
270
271
272
273
274
275

[% 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
276
277
278
279
280
281
282
283
[% 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
284
        dmg_out => '$OUTDIR/TorBrowser-' _ c("var/torbrowser_version") _ '-osx64_${PKG_LOCALE}.dmg',
boklm's avatar
boklm committed
285
286
    }) %]
[% ELSIF c("var/windows") %]
287
  find "${TB_STAGE_DIR}" -exec [% c("var/touch") %] {} \;
boklm's avatar
boklm committed
288
289
290
291
292
293
294
  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
295
  mv torbrowser-install.exe $OUTDIR/torbrowser-install[% IF c("var/windows-x86_64") %]-win64[% END %]-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.exe
boklm's avatar
boklm committed
296
297
298
299
  popd
[% END %]
rm -rf $distdir/${PKG_DIR}

300
cp $rootdir/[% c('input_files_by_name/firefox') %]/mar-tools-*.zip "$OUTDIR"/
301
[% IF c("var/linux") -%]
302
303
  cp $rootdir/[% c('input_files_by_name/firefox') %]/tor-browser-debug.tar.xz "$OUTDIR"/tor-browser-[% c("var/mar_osname") %]-debug.tar.xz
  cp $rootdir/[% c('input_files_by_name/tor') %]/tor-debug.tar.xz "$OUTDIR"/tor-[% c("var/mar_osname") %]-debug.tar.xz
304
[% END -%]
305

boklm's avatar
boklm committed
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# 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
boklm's avatar
boklm committed
332
333
      # create tbb_version.json file for #25020
      echo '{"version":"[% c("var/torbrowser_version") %]","architecture":"[% c("var/mar_osname") %]","channel":"[% c("var/channel") %]","locale":"[% lang %]"}' > ../tbb_verson.json
boklm's avatar
boklm committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
      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") %]
boklm's avatar
boklm committed
358
359
360
361
        [% # Rename the Japanese bundle to not confuse users
           IF lang == 'ja-JP-mac';
             SET lang = 'ja';
           END; -%]
boklm's avatar
boklm committed
362
363
        [% c('var/ddmg', {
          dmg_src => tbdir,
boklm's avatar
boklm committed
364
          dmg_out => '$OUTDIR/TorBrowser-' _ c("var/torbrowser_version") _ '-osx64_' _ lang _ '.dmg',
boklm's avatar
boklm committed
365
366
        }) %]
      [% ELSIF c("var/windows") %]
367
        find "[% tbdir %]" -exec [% c("var/touch") %] {} \;
boklm's avatar
boklm committed
368
369
370
371
372
373
374
        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
375
        mv torbrowser-install.exe $OUTDIR/torbrowser-install[% IF c("var/windows-x86_64") %]-win64[% END %]-[% c("var/torbrowser_version") %]_[% lang %].exe
boklm's avatar
boklm committed
376
377
378
379
380
        popd
      [% END %]
      rm -rf [% tbdir %]
  [% END %]
[% END %]