build 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/libdmg') %]
  24. export PATH=/var/tmp/dist/libdmg-hfsplus:$PATH
  25. [% ELSE %]
  26. TBDIR=$TB_STAGE_DIR/Browser
  27. DOCSPATH=TorBrowser/Docs
  28. EXTSPATH=TorBrowser/Data/Browser/profile.default/extensions
  29. TORCONFIGPATH=TorBrowser/Data/Tor
  30. mkdir -p "$TBDIR/TorBrowser/Data/Browser/Caches"
  31. [% END %]
  32. mkdir -p "$TBDIR/$EXTSPATH"
  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. mv [% c('input_files_by_name/https-everywhere') %] "$TBDIR/$EXTSPATH/https-everywhere-eff@eff.org.xpi"
  37. mv [% c('input_files_by_name/noscript') %] "$TBDIR/$EXTSPATH/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi"
  38. tar -C "$TBDIR" -xf [% c('input_files_by_name/obfs4') %]
  39. [% IF c("var/snowflake") %]
  40. tar -C "$TBDIR" -xf [% c('input_files_by_name/snowflake') -%]
  41. [% END -%]
  42. tar -C "$TBDIR[% IF c("var/osx") %]/Contents/Resources[% END %]" -xf [% c('input_files_by_name/fonts') %]
  43. [% IF c("var/linux") %]
  44. cp RelativeLink/* ${TB_STAGE_DIR}/Browser/
  45. cp RelativeLink/start-tor-browser.desktop ${TB_STAGE_DIR}/
  46. cat > ${TB_STAGE_DIR}/Browser/start-tor-browser << 'RBM_TB_EOF'
  47. [% INCLUDE 'RelativeLink/start-tor-browser' -%]
  48. RBM_TB_EOF
  49. [% IF c("var/namecoin") %]
  50. pushd ${TB_STAGE_DIR}/Browser/
  51. patch -p1 < $rootdir/namecoin.patch
  52. popd
  53. [% END %]
  54. chmod +x ${TB_STAGE_DIR}/Browser/start-tor-browser
  55. # Make sure we get the desired scrollbar behavior with Gtk3, see bug 27546.
  56. GTK_SETTINGS_DIR=${TB_STAGE_DIR}/Browser/.config/gtk-3.0
  57. mkdir -p $GTK_SETTINGS_DIR
  58. cp $rootdir/gtk3-settings.ini $GTK_SETTINGS_DIR/settings.ini
  59. [% END %]
  60. tar -C ${TB_STAGE_DIR} -xf [% c('input_files_by_name/firefox') %]/tor-browser.tar.gz
  61. tar -C "$TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]" -xf [% c('input_files_by_name/tor') %]/tor.tar.gz
  62. [% IF c("var/namecoin") %]
  63. # Extract Electrum-NMC
  64. tar -C "$TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]" -xf [% c('input_files_by_name/electrum-nmc') %]
  65. # Strip off the version number from the Electrum-NMC directory name
  66. mv $TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]/Electrum-NMC* $TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]/Electrum-NMC
  67. # Extract ncprop279
  68. mkdir "$TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]/ncprop279"
  69. tar -C "$TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]/ncprop279" -xf [% c('input_files_by_name/ncprop279') %]
  70. # Extract StemNS
  71. tar -C "$TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]" -xf [% c('input_files_by_name/stemns') %]
  72. [% END %]
  73. [% IF c("var/linux");
  74. SET bundledata_osname = 'linux';
  75. ELSIF c("var/osx");
  76. SET bundledata_osname = 'mac';
  77. ELSIF c("var/windows");
  78. SET bundledata_osname = 'windows';
  79. END; %]
  80. [% IF c("var/osx") %]
  81. # The Bundle-Data is designed for embedded data, so we need to modify
  82. # the structure when we want the data to be outside the app directory.
  83. # We also create an override.ini file to disable the profile migrator.
  84. SKELETON_TMP=$rootdir/Bundle-Data/mac-skeleton-tmp
  85. SKELETON_TMP_RESOURCES=$SKELETON_TMP/Contents/Resources
  86. mkdir -p $SKELETON_TMP_RESOURCES/browser
  87. echo "[XRE]" > $SKELETON_TMP_RESOURCES/browser/override.ini
  88. echo "EnableProfileMigrator=0" >> $SKELETON_TMP_RESOURCES/browser/override.ini
  89. mkdir -p $SKELETON_TMP_RESOURCES/TorBrowser/Tor
  90. cp -p Bundle-Data/mac/TorBrowser/Data/Tor/torrc-defaults $SKELETON_TMP_RESOURCES/TorBrowser/Tor/
  91. # Place a copy of the bookmarks.html file at the top. It will be moved into
  92. # browser/omni.ja later
  93. cp -p Bundle-Data/mac/TorBrowser/Data/Browser/profile.default/bookmarks.html $rootdir
  94. rm -Rf Bundle-Data/mac
  95. mv $SKELETON_TMP Bundle-Data/mac
  96. # Install a "tor" shim that sets the working directory. See #10030.
  97. mv "$TBDIR/$TORBINPATH/tor" "$TBDIR/$TORBINPATH/tor.real"
  98. cp Bundle-Data/mac-tor.sh "$TBDIR/$TORCONFIGPATH/tor"
  99. tar -C Bundle-Data/mac-applications.dmg -c . | tar -C $TB_STAGE_DIR -x
  100. [% END %]
  101. mkdir -p "$TBDIR/$DOCSPATH"
  102. cp -a Bundle-Data/Docs/* "$TBDIR/$DOCSPATH"
  103. [% IF c("var/namecoin") %]
  104. EXCLUDE_ELECTRUM=""
  105. EXCLUDE_NCPROP279=""
  106. [% ELSE %]
  107. EXCLUDE_ELECTRUM="--exclude=*Electrum-NMC*"
  108. EXCLUDE_NCPROP279="--exclude=*ncprop279*"
  109. [% END %]
  110. tar -C Bundle-Data/[% bundledata_osname %] "${EXCLUDE_ELECTRUM}" "${EXCLUDE_NCPROP279}" -c . | tar -C "$TBDIR[% IF ! c("var/osx") %]/TorBrowser[% END %]" -x
  111. cat Bundle-Data/PTConfigs/[% bundledata_osname %]/torrc-defaults-appendix >> "$TBDIR/$TORCONFIGPATH/torrc-defaults"
  112. [% IF ! c("var/snowflake") %]
  113. grep -v 'default_bridge\.snowflake' Bundle-Data/PTConfigs/bridge_prefs.js \
  114. >> "$GENERATEDPREFSPATH"
  115. [% ELSE %]
  116. cat Bundle-Data/PTConfigs/bridge_prefs.js >> "$GENERATEDPREFSPATH"
  117. [% END %]
  118. [% IF ! c("var/multi_lingual") %]
  119. echo 'pref("extensions.torlauncher.prompt_for_locale", false);' >> "$GENERATEDPREFSPATH"
  120. [% END %]
  121. [% IF c("var/linux") %]
  122. chmod 700 ${TB_STAGE_DIR}/Browser/TorBrowser/Data/Browser
  123. chmod 700 ${TB_STAGE_DIR}/Browser/TorBrowser/Data/Tor
  124. [% END %]
  125. [% IF c("var/multi_lingual") %]
  126. # If we are building a multi-lingual package, use "ALL" in the package name
  127. # and as the locale for update purposes. We do not include "ALL" in the name
  128. # of the directory that is inside the package (in other words, users will
  129. # not see tor-browser_ALL after they install Tor Browser).
  130. PKG_LOCALE="ALL"
  131. PKG_DIR="tor-browser"
  132. [% ELSE %]
  133. PKG_LOCALE="en-US"
  134. PKG_DIR="tor-browser_${PKG_LOCALE}"
  135. [% END %]
  136. pushd "$TBDIR[% IF c("var/osx") %]/Contents/Resources[% END %]/browser/"
  137. unzip omni.ja defaults/preferences/000-tor-browser.js || [ $? -lt 3 ]
  138. # Append our built extension-overrides.js to 000-tor-browser.js
  139. cat "$GENERATEDPREFSPATH" >> defaults/preferences/000-tor-browser.js
  140. cp defaults/preferences/000-tor-browser.js $rootdir
  141. [% IF c("var/osx") %]
  142. # Embed our default bookmarks within the en-US locale.
  143. mkdir -p chrome/en-US/locale/browser
  144. cp -p $rootdir/bookmarks.html chrome/en-US/locale/browser/
  145. [% c("var/touch") %] chrome/en-US/locale/browser/bookmarks.html
  146. zip -Xm omni.ja chrome/en-US/locale/browser/bookmarks.html
  147. rm -rf chrome
  148. [% END %]
  149. # Set the locale of the bundle.
  150. echo "pref(\"intl.locale.requested\", \"en-US\");" >> defaults/preferences/000-tor-browser.js
  151. [% c("var/touch") %] defaults/preferences/000-tor-browser.js
  152. zip -Xm omni.ja defaults/preferences/000-tor-browser.js
  153. rm -rf defaults
  154. # create tbb_version.json file for #25020
  155. echo '{"version":"[% c("var/torbrowser_version") %]","architecture":"[% c("var/mar_osname") %]","channel":"[% c("var/channel") %]","locale":"en-US"}' > ../tbb_version.json
  156. popd
  157. [% IF c("var/osx") || c("var/multi_lingual") -%]
  158. # Prepare our language packs to embed our default bookmarks.
  159. # See bug 21879 for more details.
  160. [% SET locales = c("var/testbuild") ? [] : c("var/locales") -%]
  161. [% FOREACH lang = locales %]
  162. [% SET lang = tmpl(lang);
  163. SET xpi = '$rootdir/' _ c('input_files_by_name/firefox-langpacks') _ '/' _ lang _ '.xpi';
  164. %]
  165. [% IF c("var/osx") -%]
  166. unzip -d prep_[% lang %] [% xpi %]
  167. cp $rootdir/bookmarks.html prep_[% lang %]/browser/chrome/[% lang %]/locale/browser/
  168. rm [% xpi %]
  169. cd prep_[% lang %]
  170. [% c('zip', {
  171. zip_src => [ '.' ],
  172. zip_args => xpi,
  173. }) %]
  174. [% END -%]
  175. # If we are building a multi-lingual package, add all of the language packs.
  176. [% IF c("var/multi_lingual") %]
  177. cp [% xpi %] "$TBDIR/$EXTSPATH/langpack-[% lang %]@firefox.mozilla.org.xpi"
  178. [% END %]
  179. cd ..
  180. rm -rf prep_[% lang %]
  181. [% END %]
  182. [% END %]
  183. [% IF c("var/multi_lingual") %]
  184. # Set the update.locale (it is used to replace %LOCALE% within
  185. # app.update.url).
  186. pushd "$TBDIR[% IF c("var/osx") %]/Contents/Resources/[% END %]"
  187. echo ${PKG_LOCALE} > update.locale
  188. [% c("var/touch") %] update.locale
  189. zip -Xm omni.ja update.locale
  190. popd
  191. [% END %]
  192. [% IF c("var/windows") %]
  193. # We need to install a recent version of python-pefile so that it works
  194. # in a x86_64 container:
  195. # https://github.com/TheTorProject/tor-messenger-build/pull/10
  196. tar xf $rootdir/[% c('input_files_by_name/python-pefile') %]
  197. cd $(echo [% c('input_files_by_name/python-pefile') %] | sed s/\.tar\.gz$//)
  198. python setup.py install --user
  199. cd ..
  200. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/nsis') %]
  201. export PATH="/var/tmp/dist/nsis/bin:$PATH"
  202. tar -C $distdir -xf $rootdir/[% c('input_files_by_name/tbb-windows-installer') %]
  203. mv ${TB_STAGE_DIR} $distdir/tbb-windows-installer/"Tor Browser"
  204. mv $distdir/tbb-windows-installer ${TB_STAGE_DIR}
  205. [% END %]
  206. [% IF c("var/windows") %]
  207. TBDIR="$distdir/$PKG_DIR/Tor Browser/Browser"
  208. [% ELSIF c("var/osx") %]
  209. TBDIR="$distdir/$PKG_DIR/Tor Browser.app"
  210. [% ELSE %]
  211. TBDIR="$distdir/$PKG_DIR/Browser"
  212. [% END %]
  213. cat > "$scripts_dir/create-$PKG_DIR" << SCRIPT_EOF
  214. #!/bin/bash
  215. set -e
  216. cp -a ${TB_STAGE_DIR} $distdir/$PKG_DIR
  217. pushd "$TBDIR[% IF c("var/osx") %]/Contents/Resources/[% END %]"
  218. rm -f precomplete
  219. python $MARTOOLS/createprecomplete.py
  220. popd
  221. cd $distdir
  222. [% IF c("var/build_mar") -%]
  223. # Create full MAR file and compressed package.
  224. [% SET mar_file = 'tor-browser-' _ c("var/mar_osname") _ '-' _ c("var/torbrowser_version") _ '_${PKG_LOCALE}.mar' %]
  225. MAR=$MARTOOLS/mar MBSDIFF=$MARTOOLS/mbsdiff $MARTOOLS/make_full_update.sh -q $OUTDIR/[% mar_file %] "$TBDIR"
  226. [% END -%]
  227. [% IF c("var/linux") %]
  228. [% c('tar', {
  229. tar_src => [ '$PKG_DIR' ],
  230. tar_args => '-cJf $OUTDIR/tor-browser-' _ c("var/mar_osname") _ '-' _ c("var/torbrowser_version") _ '_${PKG_LOCALE}.tar.xz',
  231. }) %]
  232. [% ELSIF c("var/osx") %]
  233. [% c('var/ddmg', {
  234. dmg_src => '"$PKG_DIR"',
  235. dmg_out => '$OUTDIR/TorBrowser-' _ c("var/torbrowser_version") _ '-osx64_${PKG_LOCALE}.dmg',
  236. }) %]
  237. [% ELSIF c("var/windows") %]
  238. find "$PKG_DIR" -exec [% c("var/touch") %] {} \;
  239. pushd "$PKG_DIR"
  240. makensis torbrowser.nsi
  241. # Working around NSIS braindamage
  242. mv torbrowser-install.exe torbrowser-install-tmp.exe
  243. python $rootdir/pe_checksum_fix.py
  244. mv torbrowser-install-tmp2.exe torbrowser-install.exe
  245. rm torbrowser-install-tmp.exe
  246. mv torbrowser-install.exe $OUTDIR/torbrowser-install[% IF c("var/windows-x86_64") %]-win64[% END %]-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.exe
  247. popd
  248. [% END %]
  249. rm -rf $distdir/${PKG_DIR}
  250. SCRIPT_EOF
  251. cp $rootdir/[% c('input_files_by_name/firefox') %]/mar-tools-*.zip "$OUTDIR"/
  252. [% IF c("var/linux-x86_64") -%]
  253. cp $rootdir/[% c('input_files_by_name/firefox') %]/tor-browser-debug.tar.xz "$OUTDIR"/tor-browser-[% c("var/mar_osname") %]-debug.tar.xz
  254. [% END -%]
  255. [% IF c("var/linux") -%]
  256. cp $rootdir/[% c('input_files_by_name/tor') %]/tor-debug.tar.xz "$OUTDIR"/tor-[% c("var/mar_osname") %]-debug.tar.xz
  257. [% END -%]
  258. # If we did not create a multi-lingual package above, create a package for
  259. # each locale.
  260. [% IF ! c("var/multi_lingual") %]
  261. [% SET locales = c("var/testbuild") ? [] : c("var/locales") -%]
  262. [% FOREACH lang = locales %]
  263. [% SET lang = tmpl(lang);
  264. SET xpi = '$rootdir/' _ c('input_files_by_name/firefox-langpacks') _ '/' _ lang _ '.xpi';
  265. SET tbdir = '$distdir/tor-browser_' _ lang;
  266. SET mar_file = 'tor-browser-' _ c("var/mar_osname") _ '-' _ c("var/torbrowser_version") _ '_' _ lang _ '.mar';
  267. IF c("var/osx");
  268. SET browserdir = tbdir _ '/Tor Browser.app';
  269. ELSIF c("var/windows");
  270. SET browserdir = tbdir _ '/Tor Browser/Browser';
  271. ELSE;
  272. SET browserdir = tbdir _ '/Browser';
  273. END;
  274. %]
  275. cat > "$scripts_dir/create-tor-browser_[% lang %]" << SCRIPT_EOF
  276. #!/bin/bash
  277. set -e
  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(\"intl.locale.requested\", \"[% 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. cd $distdir
  303. # Create full MAR file and compressed package for this locale.
  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. SCRIPT_EOF
  334. [% END %]
  335. [% END %]
  336. chmod 775 $rootdir/run_scripts "$scripts_dir"/*
  337. $rootdir/run_scripts [% c("buildconf/num_procs") %] "$scripts_dir"