build 16 KB

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