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

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

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

108
109
110
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
111

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

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

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


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

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


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

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

299
cp $rootdir/[% c('input_files_by_name/firefox') %]/mar-tools-*.zip "$OUTDIR"/
300
[% IF c("var/linux-x86_64") -%]
301
  cp $rootdir/[% c('input_files_by_name/firefox') %]/tor-browser-debug.tar.xz "$OUTDIR"/tor-browser-[% c("var/mar_osname") %]-debug.tar.xz
302
303
[% END -%]
[% IF c("var/linux") -%]
304
  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 %]