build 15.7 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
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
15
EXTOVERRIDESPATH=$rootdir/Bundle-Data/PTConfigs/extension-overrides.js
boklm's avatar
boklm committed
16
17

[% IF c("var/osx") %]
18
  TBDIR="$TB_STAGE_DIR/Tor Browser.app"
boklm's avatar
boklm committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32

  DOCSPATH=Contents/Resources/TorBrowser/Docs
  EXTSPATH=Contents/Resources/distribution/extensions
  TORBINPATH=Contents/MacOS/Tor
  TORCONFIGPATH=Contents/Resources/TorBrowser/Tor
  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
  MEEKPROFILEPATH=TorBrowser/Data/Browser/profile.meek-http-helper

36
  mkdir -p "$TBDIR/TorBrowser/Data/Browser/Caches"
boklm's avatar
boklm committed
37
38
[% END %]

39
40
mkdir -p "$TBDIR/$EXTSPATH"
mkdir -p "$TBDIR/$MEEKPROFILEPATH/extensions"
boklm's avatar
boklm committed
41
42
43
44
45

# 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
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
50

51
52
53
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
54
[% IF c("var/snowflake") %]
55
  tar -C "$TBDIR" -xf [% c('input_files_by_name/snowflake') -%]
boklm's avatar
boklm committed
56
[% END -%]
boklm's avatar
boklm committed
57

58
[% IF c("var/fteproxy") -%]
59
  tar -C "$TBDIR" -xf [% c('input_files_by_name/fteproxy') %]
60
61
[% END -%]

62
tar -C "$TBDIR[% IF c("var/osx") %]/Contents/Resources[% END %]" -xf [% c('input_files_by_name/fonts') %]
boklm's avatar
boklm committed
63
64
65
66

[% IF c("var/linux") %]
  cp RelativeLink/* ${TB_STAGE_DIR}/Browser/
  cp RelativeLink/start-tor-browser.desktop ${TB_STAGE_DIR}/
boklm's avatar
boklm committed
67
68
69
70
  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
71
72
73
[% END %]

tar -C ${TB_STAGE_DIR} -xf [% c('input_files_by_name/firefox') %]/tor-browser.tar.gz
74
tar -C "$TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]" -xf [% c('input_files_by_name/tor') %]/tor.tar.gz
boklm's avatar
boklm committed
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

[% 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.
104
105
  mv "$TBDIR/$TORBINPATH/tor" "$TBDIR/$TORBINPATH/tor.real"
  cp Bundle-Data/mac-tor.sh "$TBDIR/$TORCONFIGPATH/tor"
boklm's avatar
boklm committed
106
107
108
109

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

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

114
cat Bundle-Data/PTConfigs/[% bundledata_osname %]/torrc-defaults-appendix >> "$TBDIR/$TORCONFIGPATH/torrc-defaults"
115
[% IF c("var/linux") -%]
116
117
  [% IF ! c("var/snowflake") %]
    grep -v 'default_bridge\.snowflake' Bundle-Data/PTConfigs/bridge_prefs.js \
118
       >> "$EXTOVERRIDESPATH"
119
  [% ELSE %]
120
    cat Bundle-Data/PTConfigs/bridge_prefs.js >> "$EXTOVERRIDESPATH"
121
  [% END %]
122
123
124
[% END -%]
[% IF c("var/windows") -%]
  # We don't have snowflake available on Windows yet
125
126
127
  # 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 %] \
128
      >> "$EXTOVERRIDESPATH"
129
130
131
[% END -%]
[% IF c("var/osx") -%]
  # FTE is temporarily removed due to bug 18495.
132
133
  grep -Ev 'default_bridge\.fte' Bundle-Data/PTConfigs/bridge_prefs.js \
  [% IF ! c("var/snowflake") %]| grep -v 'default_bridge\.snowflake' [% END %] \
134
      >> "$EXTOVERRIDESPATH"
135
[% END -%]
136
cat Bundle-Data/PTConfigs/meek-http-helper-user.js >> "$TBDIR/$MEEKPROFILEPATH/user.js"
boklm's avatar
boklm committed
137
138

[% IF c("var/osx") %]
139
  pushd "$TBDIR"
boklm's avatar
boklm committed
140
141
142
143
144
145
  # 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
146

boklm's avatar
boklm committed
147
[% IF ! c("var/multi_lingual") %]
148
149
  echo 'pref("extensions.torlauncher.prompt_for_locale", false);' >> "$EXTOVERRIDESPATH"
  echo 'pref("intl.locale.matchOS", false);' >> "$EXTOVERRIDESPATH"
boklm's avatar
boklm committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
[% 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 %]


170
pushd "$TBDIR[% IF c("var/osx") %]/Contents/Resources[% END %]/browser/"
boklm's avatar
boklm committed
171
172
173
174
175
# 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 ]
176
177
# Append our built extension-overrides.js to 000-tor-browser.js
cat "$EXTOVERRIDESPATH" >> defaults/preferences/000-tor-browser.js
boklm's avatar
boklm committed
178
179
cp defaults/preferences/000-tor-browser.js $rootdir
[% IF c("var/osx") %]
180
181
182
183
184
185
  # 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
186
187
[% END %]
# Set the locale of the bundle.
188
echo "pref(\"intl.locale.requested\", \"en-US\");" >> defaults/preferences/000-tor-browser.js
boklm's avatar
boklm committed
189
190
191
[% 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
192
# create tbb_version.json file for #25020
193
echo '{"version":"[% c("var/torbrowser_version") %]","architecture":"[% c("var/mar_osname") %]","channel":"[% c("var/channel") %]","locale":"en-US"}' > ../tbb_version.json
boklm's avatar
boklm committed
194
195
popd

196
197
# 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
198
199
200
201
202
203
204
205
[% 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
206
207
208
  [% IF c("var/osx") -%]
    cp $rootdir/bookmarks.html prep_[% lang %]/browser/chrome/[% lang %]/locale/browser/
  [% END -%]
boklm's avatar
boklm committed
209
210
211
212
213
214
215
216
  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") %]
217
    cp [% xpi %] "$TBDIR/$EXTSPATH/langpack-[% lang %]@firefox.mozilla.org.xpi"
boklm's avatar
boklm committed
218
219
220
221
222
223
224
225
  [% 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).
226
  pushd "$TBDIR[% IF c("var/osx") %]/Contents/Resources/[% END %]"
boklm's avatar
boklm committed
227
228
229
230
231
232
233
234
  echo ${PKG_LOCALE} > update.locale
  [% c("var/touch") %] update.locale
  zip -Xm omni.ja update.locale
  popd
[% END %]


[% IF c("var/windows") %]
235
236
237
238
239
240
241
242
  # 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-pefile') %]
  cd $(echo [% c('input_files_by_name/python-pefile') %] | sed s/\.tar\.gz$//)
  python setup.py install --user
  cd ..

boklm's avatar
boklm committed
243
244
245
246
247
248
249
250
251
252
253
254
  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") %]
255
  TBDIR="$distdir/$PKG_DIR/Tor Browser/Browser"
boklm's avatar
boklm committed
256
[% ELSIF c("var/osx") %]
257
  TBDIR="$distdir/$PKG_DIR/Tor Browser.app"
boklm's avatar
boklm committed
258
[% ELSE %]
259
  TBDIR="$distdir/$PKG_DIR/Browser"
boklm's avatar
boklm committed
260
261
262
263
264
265
266
267
[% 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
268
269

[% IF c("var/build_mar") -%]
270
271
272
  # Let's use the bzip2 format for now so that users can update to the first
  # esr60-based Tor Browser.
  export MAR_OLD_FORMAT=1
boklm's avatar
boklm committed
273
274
275
276
277
  # 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
278
279
280
281
282
283
284
285
[% 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
286
        dmg_out => '$OUTDIR/TorBrowser-' _ c("var/torbrowser_version") _ '-osx64_${PKG_LOCALE}.dmg',
boklm's avatar
boklm committed
287
288
    }) %]
[% ELSIF c("var/windows") %]
289
  find "${TB_STAGE_DIR}" -exec [% c("var/touch") %] {} \;
boklm's avatar
boklm committed
290
291
292
293
294
295
296
  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
297
  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
298
299
300
301
  popd
[% END %]
rm -rf $distdir/${PKG_DIR}

302
cp $rootdir/[% c('input_files_by_name/firefox') %]/mar-tools-*.zip "$OUTDIR"/
303
[% IF c("var/linux") -%]
304
305
  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
306
[% END -%]
307

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