build 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. distdir=/var/tmp/dist/[% project %]
  4. export TORBROWSER_VERSION='[% c("version") %]'
  5. mkdir -p $distdir
  6. OUTDIR='[% dest_dir _ "/" _ c("filename") %]'
  7. mkdir -p $OUTDIR
  8. # When we build with MULTI_LINGUAL=1, the browser will be packaged inside a
  9. # directory named tor-browser (instead of tor-browser_en-US). Therefore we
  10. # stage everything under tor-browser-stage to avoid a conflict.
  11. TB_STAGE_DIR=$distdir/tor-browser-stage
  12. [% IF c("var/osx") %]
  13. TBDIR=$TB_STAGE_DIR/TorBrowser.app
  14. DOCSPATH=Contents/Resources/TorBrowser/Docs
  15. EXTSPATH=Contents/Resources/distribution/extensions
  16. TORBINPATH=Contents/MacOS/Tor
  17. TORCONFIGPATH=Contents/Resources/TorBrowser/Tor
  18. EXTOVERRIDESPATH=Contents/Resources/distribution/preferences//extension-overrides.js
  19. MEEKPROFILEPATH=Contents/Resources/TorBrowser/Tor/PluggableTransports/template-profile.meek-http-helper
  20. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/libdmg') %]
  21. export PATH=/var/tmp/dist/libdmg-hfsplus:$PATH
  22. [% ELSE %]
  23. TBDIR=$TB_STAGE_DIR/Browser
  24. DOCSPATH=TorBrowser/Docs
  25. EXTSPATH=TorBrowser/Data/Browser/profile.default/extensions
  26. TORCONFIGPATH=TorBrowser/Data/Tor
  27. EXTOVERRIDESPATH=TorBrowser/Data/Browser/profile.default/preferences/extension-overrides.js
  28. MEEKPROFILEPATH=TorBrowser/Data/Browser/profile.meek-http-helper
  29. mkdir -p $TBDIR/TorBrowser/Data/Browser/Caches
  30. [% END %]
  31. mkdir -p $TBDIR/$EXTSPATH
  32. mkdir -p $TBDIR/$MEEKPROFILEPATH/extensions
  33. # Extract the MAR tools.
  34. unzip -d $rootdir $rootdir/[% c('input_files_by_name/firefox') %]/mar-tools-*.zip
  35. MARTOOLS=$rootdir/mar-tools
  36. [% IF c("var/windows-x86_64") -%]
  37. # Workaround for bug 24477
  38. rm -Rf $MARTOOLS
  39. unzip -d $rootdir $rootdir/mar-tools-linux32.zip
  40. [% END -%]
  41. mv [% c('input_files_by_name/tor-launcher') %] $TBDIR/$EXTSPATH/tor-launcher@torproject.org.xpi
  42. mv [% c('input_files_by_name/torbutton') %] $TBDIR/$EXTSPATH/torbutton@torproject.org.xpi
  43. mv [% c('input_files_by_name/https-everywhere') %] $TBDIR/$EXTSPATH/https-everywhere-eff@eff.org.xpi
  44. mv [% c('input_files_by_name/noscript') %] $TBDIR/$EXTSPATH/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi
  45. tar -C $TBDIR -xf [% c('input_files_by_name/obfs4') %]
  46. tar -C $TBDIR -xf [% c('input_files_by_name/meek') %]
  47. mv $TBDIR/meek-http-helper@bamsoftware.com.xpi $TBDIR/$MEEKPROFILEPATH/extensions/
  48. [% IF c("var/snowflake") %]
  49. tar -C $TBDIR -xf [% c('input_files_by_name/snowflake') -%]
  50. [% END -%]
  51. [% IF c("var/fteproxy") -%]
  52. tar -C $TBDIR -xf [% c('input_files_by_name/fteproxy') %]
  53. [% END -%]
  54. tar -C $TBDIR[% IF c("var/osx") %]/Contents/Resources[% END %] -xf [% c('input_files_by_name/fonts') %]
  55. [% IF c("var/linux") %]
  56. cp RelativeLink/* ${TB_STAGE_DIR}/Browser/
  57. cp RelativeLink/start-tor-browser.desktop ${TB_STAGE_DIR}/
  58. cat > ${TB_STAGE_DIR}/Browser/start-tor-browser << 'RBM_TB_EOF'
  59. [% INCLUDE 'RelativeLink/start-tor-browser' -%]
  60. RBM_TB_EOF
  61. chmod +x ${TB_STAGE_DIR}/Browser/start-tor-browser
  62. [% END %]
  63. tar -C ${TB_STAGE_DIR} -xf [% c('input_files_by_name/firefox') %]/tor-browser.tar.gz
  64. tar -C $TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %] -xf [% c('input_files_by_name/tor') %]/tor.tar.gz
  65. [% IF c("var/linux");
  66. SET bundledata_osname = 'linux';
  67. ELSIF c("var/osx");
  68. SET bundledata_osname = 'mac';
  69. ELSIF c("var/windows");
  70. SET bundledata_osname = 'windows';
  71. END; %]
  72. [% IF c("var/osx") %]
  73. # The Bundle-Data is designed for embedded data, so we need to modify
  74. # the structure when we want the data to be outside the app directory.
  75. # We also create an override.ini file to disable the profile migrator.
  76. SKELETON_TMP=$rootdir/Bundle-Data/mac-skeleton-tmp
  77. SKELETON_TMP_RESOURCES=$SKELETON_TMP/Contents/Resources
  78. mkdir -p $SKELETON_TMP_RESOURCES/browser
  79. echo "[XRE]" > $SKELETON_TMP_RESOURCES/browser/override.ini
  80. echo "EnableProfileMigrator=0" >> $SKELETON_TMP_RESOURCES/browser/override.ini
  81. mkdir -p $SKELETON_TMP_RESOURCES/distribution/preferences
  82. cp -p Bundle-Data/mac/TorBrowser/Data/Browser/profile.default/preferences/extension-overrides.js $SKELETON_TMP_RESOURCES/distribution/preferences
  83. mkdir -p $SKELETON_TMP_RESOURCES/TorBrowser/Tor
  84. cp -p Bundle-Data/mac/TorBrowser/Data/Tor/torrc-defaults $SKELETON_TMP_RESOURCES/TorBrowser/Tor/
  85. # Place a copy of the bookmarks.html file at the top. It will be moved into
  86. # browser/omni.ja later
  87. cp -p Bundle-Data/mac/TorBrowser/Data/Browser/profile.default/bookmarks.html $rootdir
  88. rm -Rf Bundle-Data/mac
  89. mv $SKELETON_TMP Bundle-Data/mac
  90. # Install a "tor" shim that sets the working directory. See #10030.
  91. mv $TBDIR/$TORBINPATH/tor $TBDIR/$TORBINPATH/tor.real
  92. cp Bundle-Data/mac-tor.sh $TBDIR/$TORCONFIGPATH/tor
  93. [% IF ! c("var/release") -%]
  94. SANDBOX_FOLDER="$TB_STAGE_DIR/Sandboxed Tor Browser"
  95. mv Bundle-Data/mac-sandbox "$SANDBOX_FOLDER"
  96. [% END -%]
  97. tar -C Bundle-Data/mac-applications.dmg -c . | tar -C $TB_STAGE_DIR -x
  98. [% END %]
  99. mkdir -p $TBDIR/$DOCSPATH
  100. cp -a Bundle-Data/Docs/* $TBDIR/$DOCSPATH
  101. tar -C Bundle-Data/[% bundledata_osname %] -c . | tar -C $TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %] -x
  102. cat Bundle-Data/PTConfigs/[% bundledata_osname %]/torrc-defaults-appendix >> $TBDIR/$TORCONFIGPATH/torrc-defaults
  103. [% IF c("var/linux") -%]
  104. [% IF ! c("var/snowflake") %]
  105. grep -v 'default_bridge\.snowflake' Bundle-Data/PTConfigs/bridge_prefs.js \
  106. >> $TBDIR/$EXTOVERRIDESPATH
  107. [% ELSE %]
  108. cat Bundle-Data/PTConfigs/bridge_prefs.js >> $TBDIR/$EXTOVERRIDESPATH
  109. [% END %]
  110. [% END -%]
  111. [% IF c("var/windows") -%]
  112. # We don't have snowflake available on Windows yet
  113. # We don't have fte available on Windows x86_64 yet
  114. grep -v 'default_bridge\.snowflake' Bundle-Data/PTConfigs/bridge_prefs.js \
  115. [% IF c("var/windows-x86_64") %]| grep -v 'default_bridge\.fte' [% END %] \
  116. >> $TBDIR/$EXTOVERRIDESPATH
  117. [% END -%]
  118. [% IF c("var/osx") -%]
  119. # FTE is temporarily removed due to bug 18495.
  120. grep -Ev 'default_bridge\.fte' Bundle-Data/PTConfigs/bridge_prefs.js \
  121. [% IF ! c("var/snowflake") %]| grep -v 'default_bridge\.snowflake' [% END %] \
  122. >> $TBDIR/$EXTOVERRIDESPATH
  123. [% END -%]
  124. cat Bundle-Data/PTConfigs/meek-http-helper-user.js >> $TBDIR/$MEEKPROFILEPATH/user.js
  125. [% IF c("var/osx") %]
  126. pushd $TBDIR
  127. # Create the meek-template-sha256sum.txt file by generating a list
  128. # of hashes (one for each file within the meek-http-helper profile) and
  129. # and then generating one final hash from the contents of the list.
  130. sha256sum `find $MEEKPROFILEPATH -type f | sort` | sha256sum | sed -e 's/ *-$//' > $MEEKPROFILEPATH/meek-template-sha256sum.txt
  131. popd
  132. [% END %]
  133. [% IF ! c("var/multi_lingual") %]
  134. echo 'pref("extensions.torlauncher.prompt_for_locale", false);' >> $TBDIR/$EXTOVERRIDESPATH
  135. echo 'pref("intl.locale.matchOS", false);' >> $TBDIR/$EXTOVERRIDESPATH
  136. [% END %]
  137. [% IF c("var/linux") %]
  138. chmod 700 ${TB_STAGE_DIR}/Browser/TorBrowser/Data/Browser
  139. chmod 700 ${TB_STAGE_DIR}/Browser/TorBrowser/Data/Tor
  140. [% END %]
  141. [% IF c("var/multi_lingual") %]
  142. # If we are building a multi-lingual package, use "ALL" in the package name
  143. # and as the locale for update purposes. We do not include "ALL" in the name
  144. # of the directory that is inside the package (in other words, users will
  145. # not see tor-browser_ALL after they install Tor Browser).
  146. PKG_LOCALE="ALL"
  147. PKG_DIR="tor-browser"
  148. [% ELSE %]
  149. PKG_LOCALE="en-US"
  150. PKG_DIR="tor-browser_${PKG_LOCALE}"
  151. [% END %]
  152. pushd $TBDIR[% IF c("var/osx") %]/Contents/Resources[% END %]/browser/
  153. # For the proper search engines in our language packs
  154. unzip omni.ja chrome/en-US/locale/browser/searchplugins* || [ $? -lt 3 ]
  155. mv chrome/en-US/locale/browser/searchplugins $rootdir
  156. rm -rf chrome/en-US
  157. unzip omni.ja defaults/preferences/000-tor-browser.js || [ $? -lt 3 ]
  158. cp defaults/preferences/000-tor-browser.js $rootdir
  159. [% IF c("var/osx") %]
  160. # Embed our default bookmarks within the en-US locale.
  161. mkdir -p chrome/en-US/locale/browser
  162. cp -p $rootdir/bookmarks.html chrome/en-US/locale/browser/
  163. [% c("var/touch") %] chrome/en-US/locale/browser/bookmarks.html
  164. zip -Xm omni.ja chrome/en-US/locale/browser/bookmarks.html
  165. rm -rf chrome
  166. [% END %]
  167. # Set the locale of the bundle.
  168. echo "pref(\"general.useragent.locale\", \"en-US\");" >> defaults/preferences/000-tor-browser.js
  169. [% c("var/touch") %] defaults/preferences/000-tor-browser.js
  170. zip -Xm omni.ja defaults/preferences/000-tor-browser.js
  171. rm -rf defaults
  172. # create tbb_version.json file for #25020
  173. echo '{"version":"[% c("var/torbrowser_version") %]","architecture":"[% c("var/mar_osname") %]","channel":"[% c("var/channel") %]","locale":"en-US"}' > ../tbb_version.json
  174. popd
  175. # Prepare our language packs for using the proper search engines and embed
  176. # our default bookmarks. See bugs 18915 and 21879 for more details.
  177. [% FOREACH lang = c('var/locales') %]
  178. [% SET lang = tmpl(lang);
  179. SET xpi = '$rootdir/' _ c('input_files_by_name/firefox-langpacks') _ '/' _ lang _ '.xpi';
  180. %]
  181. unzip -d prep_[% lang %] [% xpi %]
  182. search_plugins_path=prep_[% lang %]/browser/chrome/[% lang %]/locale/browser
  183. rm -rf $search_plugins_path/searchplugins
  184. cp -rf $rootdir/searchplugins $search_plugins_path
  185. [% IF c("var/osx") -%]
  186. cp $rootdir/bookmarks.html prep_[% lang %]/browser/chrome/[% lang %]/locale/browser/
  187. [% END -%]
  188. rm [% xpi %]
  189. cd prep_[% lang %]
  190. [% c('zip', {
  191. zip_src => [ '.' ],
  192. zip_args => xpi,
  193. }) %]
  194. # If we are building a multi-lingual package, add all of the language packs.
  195. [% IF c("var/multi_lingual") %]
  196. cp [% xpi %] $TBDIR/$EXTSPATH/langpack-[% lang %]@firefox.mozilla.org.xpi
  197. [% END %]
  198. cd ..
  199. rm -rf prep_[% lang %]
  200. [% END %]
  201. [% IF c("var/multi_lingual") %]
  202. # Set the update.locale (it is used to replace %LOCALE% within
  203. # app.update.url).
  204. pushd $TBDIR[% IF c("var/osx") %]/Contents/Resources/[% END %]
  205. echo ${PKG_LOCALE} > update.locale
  206. [% c("var/touch") %] update.locale
  207. zip -Xm omni.ja update.locale
  208. popd
  209. [% END %]
  210. [% IF c("var/windows") %]
  211. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/nsis') %]
  212. export PATH="/var/tmp/dist/nsis/bin:$PATH"
  213. tar -C $distdir -xf $rootdir/[% c('input_files_by_name/tbb-windows-installer') %]
  214. mv ${TB_STAGE_DIR} $distdir/tbb-windows-installer/"Tor Browser"
  215. mv $distdir/tbb-windows-installer ${TB_STAGE_DIR}
  216. [% END %]
  217. cp -a ${TB_STAGE_DIR} $distdir/$PKG_DIR
  218. [% IF c("var/windows") %]
  219. TBDIR=$distdir/$PKG_DIR/"Tor Browser"/Browser
  220. [% ELSIF c("var/osx") %]
  221. TBDIR=$distdir/$PKG_DIR/TorBrowser.app
  222. [% ELSE %]
  223. TBDIR=$distdir/$PKG_DIR/Browser
  224. [% END %]
  225. pushd "$TBDIR[% IF c("var/osx") %]/Contents/Resources/[% END %]"
  226. rm -f precomplete
  227. python $MARTOOLS/createprecomplete.py
  228. popd
  229. cd $distdir
  230. [% IF c("var/build_mar") -%]
  231. # Create full MAR file and compressed package.
  232. MAR_FILE=tor-browser-[% c("var/mar_osname") %]-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.mar
  233. MAR=$MARTOOLS/mar MBSDIFF=$MARTOOLS/mbsdiff $MARTOOLS/make_full_update.sh -q $OUTDIR/$MAR_FILE "$TBDIR"
  234. [% END -%]
  235. [% IF c("var/linux") %]
  236. [% c('tar', {
  237. tar_src => [ '$PKG_DIR' ],
  238. tar_args => '-cJf $OUTDIR/tor-browser-' _ c("var/mar_osname") _ '-' _ c("var/torbrowser_version") _ '_${PKG_LOCALE}.tar.xz',
  239. }) %]
  240. [% ELSIF c("var/osx") %]
  241. [% c('var/ddmg', {
  242. dmg_src => '"$PKG_DIR"',
  243. dmg_out => '$OUTDIR/TorBrowser-' _ c("var/torbrowser_version") _ '-osx64_${PKG_LOCALE}.dmg',
  244. }) %]
  245. [% ELSIF c("var/windows") %]
  246. find "${TB_STAGE_DIR}" -exec [% c("var/touch") %] {} \;
  247. pushd "${TB_STAGE_DIR}"
  248. makensis torbrowser.nsi
  249. # Working around NSIS braindamage
  250. mv torbrowser-install.exe torbrowser-install-tmp.exe
  251. python $rootdir/pe_checksum_fix.py
  252. mv torbrowser-install-tmp2.exe torbrowser-install.exe
  253. rm torbrowser-install-tmp.exe
  254. mv torbrowser-install.exe $OUTDIR/torbrowser-install[% IF c("var/windows-x86_64") %]-win64[% END %]-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.exe
  255. popd
  256. [% END %]
  257. rm -rf $distdir/${PKG_DIR}
  258. cp $rootdir/[% c('input_files_by_name/firefox') %]/mar-tools-*.zip "$OUTDIR"/
  259. [% IF c("var/linux") -%]
  260. cp $rootdir/[% c('input_files_by_name/firefox') %]/tor-browser-debug.tar.xz "$OUTDIR"/tor-browser-[% c("var/mar_osname") %]-debug.tar.xz
  261. cp $rootdir/[% c('input_files_by_name/tor') %]/tor-debug.tar.xz "$OUTDIR"/tor-[% c("var/mar_osname") %]-debug.tar.xz
  262. [% END -%]
  263. # If we did not create a multi-lingual package above, create a package for
  264. # each locale.
  265. [% IF ! c("var/multi_lingual") %]
  266. [% FOREACH lang = c('var/locales') %]
  267. [% SET lang = tmpl(lang);
  268. SET xpi = '$rootdir/' _ c('input_files_by_name/firefox-langpacks') _ '/' _ lang _ '.xpi';
  269. SET tbdir = '$distdir/tor-browser_' _ lang;
  270. IF c("var/osx");
  271. SET browserdir = tbdir _ '/TorBrowser.app';
  272. ELSIF c("var/windows");
  273. SET browserdir = tbdir _ '/Tor Browser/Browser';
  274. ELSE;
  275. SET browserdir = tbdir _ '/Browser';
  276. END;
  277. %]
  278. cp -a ${TB_STAGE_DIR} [% tbdir %]
  279. cp [% xpi %] "[% browserdir %]/$EXTSPATH/langpack-[% lang %]@firefox.mozilla.org.xpi"
  280. pushd "[% browserdir %]/[% IF c("var/osx") %]Contents/Resources/[% END %]browser/"
  281. mkdir -p defaults/preferences
  282. cp $rootdir/000-tor-browser.js defaults/preferences/
  283. # Set the locale of the bundle.
  284. echo "pref(\"general.useragent.locale\", \"[% lang %]\");" >> defaults/preferences/000-tor-browser.js
  285. [% c("var/touch") %] defaults/preferences/000-tor-browser.js
  286. zip -Xm omni.ja defaults/preferences/000-tor-browser.js
  287. rm -rf defaults
  288. # create tbb_version.json file for #25020
  289. echo '{"version":"[% c("var/torbrowser_version") %]","architecture":"[% c("var/mar_osname") %]","channel":"[% c("var/channel") %]","locale":"[% lang %]"}' > ../tbb_version.json
  290. popd
  291. # Set the update.locale (it is used to replace %LOCALE% within
  292. # app.update.url), remove the en-US spellchecking dictionary, and
  293. # recreate precomplete file (needs to be accurate for full MAR updates).
  294. pushd "[% browserdir %]/[% IF c("var/osx") %]Contents/Resources/[% END %]"
  295. echo "[% lang %]" > update.locale
  296. [% c("var/touch") %] update.locale
  297. zip -Xm omni.ja update.locale
  298. rm -rf dictionaries
  299. rm -f precomplete
  300. python $MARTOOLS/createprecomplete.py
  301. popd
  302. # Create full MAR file and compressed package for this locale.
  303. MAR_FILE=tor-browser-[% c("var/mar_osname") %]-[% c("var/torbrowser_version") %]_[% lang %].mar
  304. MAR=$MARTOOLS/mar MBSDIFF=$MARTOOLS/mbsdiff $MARTOOLS/make_full_update.sh -q $OUTDIR/$MAR_FILE "[% browserdir %]"
  305. [% IF c("var/linux") %]
  306. [% SET tardir = 'tor-browser_' _ lang;
  307. c('tar', {
  308. tar_src => [ tardir ],
  309. tar_args => '-cJf $OUTDIR/tor-browser-' _ c("var/mar_osname") _ '-' _ c("var/torbrowser_version") _ '_' _ lang _ '.tar.xz',
  310. }) %]
  311. [% ELSIF c("var/osx") %]
  312. [% # Rename the Japanese bundle to not confuse users
  313. IF lang == 'ja-JP-mac';
  314. SET lang = 'ja';
  315. END; -%]
  316. [% c('var/ddmg', {
  317. dmg_src => tbdir,
  318. dmg_out => '$OUTDIR/TorBrowser-' _ c("var/torbrowser_version") _ '-osx64_' _ lang _ '.dmg',
  319. }) %]
  320. [% ELSIF c("var/windows") %]
  321. find "[% tbdir %]" -exec [% c("var/touch") %] {} \;
  322. pushd "[% tbdir %]"
  323. makensis torbrowser.nsi
  324. # Working around NSIS braindamage
  325. mv torbrowser-install.exe torbrowser-install-tmp.exe
  326. python $rootdir/pe_checksum_fix.py
  327. mv torbrowser-install-tmp2.exe torbrowser-install.exe
  328. rm torbrowser-install-tmp.exe
  329. mv torbrowser-install.exe $OUTDIR/torbrowser-install[% IF c("var/windows-x86_64") %]-win64[% END %]-[% c("var/torbrowser_version") %]_[% lang %].exe
  330. popd
  331. [% END %]
  332. rm -rf [% tbdir %]
  333. [% END %]
  334. [% END %]