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
15
16
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") %]
17
  TBDIR="$TB_STAGE_DIR/Tor Browser.app"
boklm's avatar
boklm committed
18
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
  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
  EXTOVERRIDESPATH=TorBrowser/Data/Browser/profile.default/preferences/extension-overrides.js
  MEEKPROFILEPATH=TorBrowser/Data/Browser/profile.meek-http-helper

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

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

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

47
48
49
50
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
51

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

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

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

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

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

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

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

111
112
113
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
114

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

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

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


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

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


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

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

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

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