build 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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/macos") %]
  18. TBDIR="$TB_STAGE_DIR/[% c("var/Project_Name") %].app"
  19. [% IF c("var/macos_universal") %]
  20. TBDIR_AARCH64="$TB_STAGE_DIR/[% c("var/Project_Name") %]-aarch64.app"
  21. TBDIRS=("$TBDIR" "$TBDIR_AARCH64")
  22. [% ELSE -%]
  23. TBDIRS=("$TBDIR")
  24. [% END -%]
  25. DOCSPATH=Contents/Resources/[% c('var/ProjectName') %]/Docs
  26. EXTSPATH=Contents/Resources/distribution/extensions
  27. TORBINPATH=Contents/MacOS/Tor
  28. TORCONFIGPATH=Contents/Resources/TorBrowser/Tor
  29. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/libdmg') %]
  30. export PATH=/var/tmp/dist/libdmg-hfsplus:$PATH
  31. [% ELSE %]
  32. TBDIR=$TB_STAGE_DIR/Browser
  33. TBDIRS=("$TBDIR")
  34. DOCSPATH=[% c('var/ProjectName') %]/Docs
  35. EXTSPATH=[% c('var/ProjectName') %]/Data/Browser/profile.default/extensions
  36. TORBINPATH=TorBrowser/Tor
  37. TORCONFIGPATH=TorBrowser/Data/Tor
  38. mkdir -p "$TBDIR/[% c('var/ProjectName') %]/Data/Browser/Caches"
  39. [% END %]
  40. for tbdir in "${TBDIRS[@]}"
  41. do
  42. mkdir -p "$tbdir/$EXTSPATH"
  43. done
  44. # Extract the MAR tools.
  45. unzip -d $rootdir $rootdir/[% c('input_files_by_name/firefox') %]/mar-tools-*.zip
  46. MARTOOLS=$rootdir/mar-tools
  47. mv [% c('input_files_by_name/noscript') %] "$TBDIR/$EXTSPATH/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi"
  48. [% IF c("var/tor-browser") -%]
  49. function mv_tbdir {
  50. declare args=($@)
  51. local dest="${args[-1]}"
  52. unset args[-1]
  53. mv ${args[@]} "$TBDIR/$dest"
  54. [% IF c("var/macos_universal") -%]
  55. for src in ${args[@]}
  56. do
  57. mv "aarch64/$src" "$TBDIR_AARCH64/$dest"
  58. done
  59. [% END -%]
  60. }
  61. tar -xvf [% c('input_files_by_name/tor-expert-bundle') %]
  62. [% IF c("var/macos_universal") -%]
  63. mkdir aarch64
  64. tar -C aarch64 -xf [% c('input_files_by_name/tor-expert-bundle-aarch64') %]
  65. [% END -%]
  66. # geoip(6) and anything else that belongs in the data dir from the expert bundle
  67. mkdir -p "$TBDIR/$TORCONFIGPATH" [% IF c("var/macos_universal") %]"$TBDIR_AARCH64/$TORCONFIGPATH"[% END %]
  68. mv_tbdir data/{geoip,geoip6} "$TORCONFIGPATH"
  69. # Bridge lists will be consumed later in `bridges_conf`
  70. mv tor/pluggable_transports/bridges_list.*.txt $rootdir
  71. [% IF c("var/macos_universal") %]
  72. rm -f aarch64/tor/pluggable_transports/bridges_list.*.txt
  73. [% END -%]
  74. # Snowflake's README is the only documentation shipped in tor-expert-bundle
  75. mkdir -p "$TBDIR/$DOCSPATH/snowflake" [% IF c("var/macos_universal") %]"$TBDIR_AARCH64/$DOCSPATH/snowflake"[% END %]
  76. mv_tbdir tor/pluggable_transports/README.SNOWFLAKE.md "$DOCSPATH/snowflake/README.md"
  77. # Move the PTs to where TB expects them
  78. mkdir -p "$TBDIR/$TORBINPATH" [% IF c("var/macos_universal") %]"$TBDIR_AARCH64/$TORBINPATH"[% END %]
  79. mv_tbdir tor/pluggable_transports "$TORBINPATH/PluggableTransports"
  80. # Move tor and dependencies to where TB expects them
  81. mv_tbdir tor/* "$TORBINPATH"
  82. # on linux, libstdc++ lives in it's own directory
  83. [% IF c("var/linux") %]
  84. find $TBDIR/$TORBINPATH
  85. mkdir -p "$TBDIR/$TORBINPATH/libstdc++"
  86. mv "$TBDIR/$TORBINPATH"/libstdc++.so.* "$TBDIR/$TORBINPATH/libstdc++"
  87. [% END %]
  88. # the expert bundle includes tor-gencert, which isn't needed for browser releases
  89. [% IF c("var/windows") %]
  90. rm "$TBDIR/$TORBINPATH/tor-gencert.exe"
  91. [% END %]
  92. [% END -%]
  93. for tbdir in "${TBDIRS[@]}"
  94. do
  95. [% IF c("var/macos") -%]
  96. tbdir="$tbdir/Contents/Resources"
  97. [% END -%]
  98. tar -C "$tbdir" -xf [% c('input_files_by_name/fonts') %]
  99. done
  100. [% IF c("var/linux") %]
  101. cat > ${TB_STAGE_DIR}/start-[% c("var/project-name") %].desktop << 'RBM_TB_EOF'
  102. [% INCLUDE 'RelativeLink/start-browser.desktop' -%]
  103. RBM_TB_EOF
  104. cat > ${TB_STAGE_DIR}/Browser/start-[% c("var/project-name") %] << 'RBM_TB_EOF'
  105. [% INCLUDE 'RelativeLink/start-browser' -%]
  106. RBM_TB_EOF
  107. cat > ${TB_STAGE_DIR}/Browser/execdesktop << 'RBM_TB_EOF'
  108. [% INCLUDE 'RelativeLink/execdesktop' -%]
  109. RBM_TB_EOF
  110. chmod +x ${TB_STAGE_DIR}/start-[% c("var/project-name") %].desktop \
  111. ${TB_STAGE_DIR}/Browser/start-[% c("var/project-name") %] \
  112. ${TB_STAGE_DIR}/Browser/execdesktop
  113. cp ${TB_STAGE_DIR}/start-[% c("var/project-name") %].desktop \
  114. ${TB_STAGE_DIR}/Browser
  115. [% IF c("var/namecoin") %]
  116. pushd ${TB_STAGE_DIR}/Browser/
  117. patch -p1 < $rootdir/namecoin.patch
  118. popd
  119. [% END %]
  120. # Make sure we get the desired scrollbar behavior with Gtk3, see bug 27546.
  121. GTK_SETTINGS_DIR=${TB_STAGE_DIR}/Browser/.config/gtk-3.0
  122. mkdir -p $GTK_SETTINGS_DIR
  123. cp $rootdir/gtk3-settings.ini $GTK_SETTINGS_DIR/settings.ini
  124. [% END %]
  125. tar -C ${TB_STAGE_DIR} -xf [% c('input_files_by_name/firefox') %]/browser.tar.gz
  126. [% IF c("var/macos_universal") -%]
  127. # Use symlink in tmp dir to extract "Tor Browser.app" to "Tor Browser-aarch64.app"
  128. ff_aarch64=$(mktemp -d)
  129. ln -s "$TBDIR_AARCH64" "$ff_aarch64/[% c("var/Project_Name") %].app"
  130. tar -C $ff_aarch64 -xf [% c('input_files_by_name/firefox-aarch64') %]/browser.tar.gz
  131. [% END %]
  132. [% IF c("var/tor-browser") -%]
  133. # Include the Tor Browser manual
  134. TMP_MANUAL_PATH=$rootdir/tmp_manual/
  135. mkdir $TMP_MANUAL_PATH
  136. pushd $TMP_MANUAL_PATH
  137. tar -xf $rootdir/[% c('input_files_by_name/manual') %]
  138. find . -exec [% c("touch") %] {} \;
  139. for tbdir in "${TBDIRS[@]}"
  140. do
  141. find chrome/ | sort | zip -X -@ "$tbdir[% IF c('var/macos') %]/Contents/Resources[% END %]/browser/omni.ja"
  142. done
  143. popd
  144. rm -rf $TMP_MANUAL_PATH
  145. [% END -%]
  146. [% IF c("var/namecoin") %]
  147. # Extract Electrum-NMC
  148. tar -C "$TBDIR/TorBrowser" -xf [% c('input_files_by_name/electrum-nmc') %]
  149. # Extract ncprop279
  150. mkdir "$TBDIR/TorBrowser/ncprop279"
  151. tar -C "$TBDIR/TorBrowser/ncprop279" -xf [% c('input_files_by_name/ncprop279') %]
  152. # Extract StemNS
  153. tar -C "$TBDIR/TorBrowser" -xf [% c('input_files_by_name/stemns') %]
  154. [% END %]
  155. [% IF c("var/linux");
  156. SET bundledata_osname = 'linux';
  157. ELSIF c("var/macos");
  158. SET bundledata_osname = 'mac';
  159. ELSIF c("var/windows");
  160. SET bundledata_osname = 'windows';
  161. END; %]
  162. [% IF c("var/macos") %]
  163. # The Bundle-Data is designed for embedded data, so we need to modify
  164. # the structure when we want the data to be outside the app directory.
  165. # We also create an override.ini file to disable the profile migrator.
  166. SKELETON_TMP=$rootdir/Bundle-Data/mac-skeleton-tmp
  167. SKELETON_TMP_RESOURCES=$SKELETON_TMP/Contents/Resources
  168. mkdir -p $SKELETON_TMP_RESOURCES/browser
  169. echo "[XRE]" > $SKELETON_TMP_RESOURCES/browser/override.ini
  170. echo "EnableProfileMigrator=0" >> $SKELETON_TMP_RESOURCES/browser/override.ini
  171. [% IF c("var/tor-browser") -%]
  172. mkdir -p $SKELETON_TMP_RESOURCES/TorBrowser/Tor
  173. cp -p Bundle-Data/mac/TorBrowser/Data/Tor/torrc-defaults $SKELETON_TMP_RESOURCES/TorBrowser/Tor/
  174. [% END -%]
  175. rm -Rf Bundle-Data/mac
  176. mv $SKELETON_TMP Bundle-Data/mac
  177. [% IF c("var/tor-browser") -%]
  178. # Install a "tor" shim that sets the working directory. See #10030.
  179. for tbdir in "${TBDIRS[@]}"
  180. do
  181. mv "$tbdir/$TORBINPATH/tor" "$tbdir/$TORBINPATH/tor.real"
  182. cp Bundle-Data/mac-tor.sh "$tbdir/$TORCONFIGPATH/tor"
  183. done
  184. [% END -%]
  185. tar -C Bundle-Data/mac-applications.dmg -c . | tar -C $TB_STAGE_DIR -x
  186. [% END %]
  187. for tbdir in "${TBDIRS[@]}"
  188. do
  189. mkdir -p "$tbdir/$DOCSPATH"
  190. cp -a Bundle-Data/Docs/* "$tbdir/$DOCSPATH"
  191. tar -C Bundle-Data/[% bundledata_osname %] \
  192. [% IF ! c("var/namecoin") %]--exclude=*Electrum-NMC* --exclude=*ncprop279*[% END %] \
  193. -c . | tar -C "$tbdir[% IF ! c("var/macos") %]/[% c('var/ProjectName') %][% END %]" -x
  194. done
  195. [% IF c("var/tor-browser") -%]
  196. for tbdir in "${TBDIRS[@]}"
  197. do
  198. cat Bundle-Data/PTConfigs/[% bundledata_osname %]/torrc-defaults-appendix >> "$tbdir/$TORCONFIGPATH/torrc-defaults"
  199. done
  200. cat Bundle-Data/PTConfigs/bridge_prefs.js >> "$GENERATEDPREFSPATH"
  201. function bridges_conf {
  202. local pt="$1"
  203. local i=1
  204. while read -r line
  205. do
  206. echo "pref(\"extensions.torlauncher.default_bridge.$pt.$i\", \"$line\");" >> "$GENERATEDPREFSPATH"
  207. i=$((i + 1))
  208. done < "$rootdir/bridges_list.$pt.txt"
  209. }
  210. bridges_conf obfs4
  211. bridges_conf meek-azure
  212. bridges_conf snowflake
  213. [% END -%]
  214. [% IF c("var/linux") %]
  215. chmod 700 ${TB_STAGE_DIR}/Browser/[% c('var/ProjectName') %]/Data/Browser
  216. [% IF c("var/tor-browser") -%]
  217. chmod 700 ${TB_STAGE_DIR}/Browser/TorBrowser/Data/Tor
  218. [% END -%]
  219. [% END %]
  220. # With multi-lingual builds, we use "ALL" in the package name as the locale for
  221. # update purposes. But we do not include "ALL" in the name of the directory that
  222. # is inside the package (in other words, users will not see tor-browser_ALL
  223. # after they install Tor Browser).
  224. PKG_LOCALE="ALL"
  225. PKG_DIR='[% c("var/project-name") %]'
  226. for tbdir in "${TBDIRS[@]}"
  227. do
  228. tbdir="$tbdir[% IF c('var/macos') %]/Contents/Resources[% END %]/browser/"
  229. pushd "$tbdir"
  230. unzip omni.ja defaults/preferences/[% c("var/prefs_file") %] || [ $? -lt 3 ]
  231. # Append our built extension-overrides.js to the preferences file
  232. cat "$GENERATEDPREFSPATH" >> defaults/preferences/[% c("var/prefs_file") %]
  233. cp defaults/preferences/[% c("var/prefs_file") %] $rootdir
  234. [% c("touch") %] defaults/preferences/[% c("var/prefs_file") %]
  235. zip -Xm omni.ja defaults/preferences/[% c("var/prefs_file") %]
  236. rm -rf defaults
  237. # create tbb_version.json file for #25020
  238. echo '{"version":"[% c("var/torbrowser_version") %]","architecture":"[% c("var/mar_osname") %]","channel":"[% c("var/channel") %]","locale":"en-US"}' > ../tbb_version.json
  239. popd
  240. done
  241. [% IF c("var/windows") %]
  242. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/nsis') %]
  243. export PATH="/var/tmp/dist/nsis/bin:$PATH"
  244. mv $rootdir/windows-installer $distdir/windows-installer
  245. mv ${TB_STAGE_DIR} $distdir/windows-installer/"[% c('var/Project_Name') %]"
  246. mv $distdir/windows-installer ${TB_STAGE_DIR}
  247. [% END %]
  248. [% IF c("var/macos_universal") -%]
  249. # unify.py requires lipo, so we need to add cctools in the PATH
  250. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/macosx-toolchain') %]
  251. export PATH="/var/tmp/dist/macosx-toolchain/cctools/bin:$PATH"
  252. firefox_src=/var/tmp/dist/firefox-src
  253. mkdir -p $firefox_src
  254. tar -C $firefox_src -xf $rootdir/[% c('input_files_by_name/src-firefox') %]
  255. firefox_src=$(echo $firefox_src/firefox-*)
  256. # Temporarily move noscript outside of $TBDIR to avoid error when running unify.py:
  257. # File "/var/tmp/dist/firefox-src/firefox-69721baf14f0/python/mozbuild/mozpack/mozjar.py", line 452, in _getreader
  258. # raise JarReaderError(
  259. # mozpack.mozjar.JarReaderError: Central directory and file header mismatch. Corrupted archive?
  260. #
  261. # See https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/issues/40439#note_2838724
  262. mv "$TBDIR/$EXTSPATH/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi" $rootdir/ns.xpi
  263. MOZ_AUTOMATION=1 $firefox_src/mach python $firefox_src/toolkit/mozapps/installer/unify.py "$TBDIR" "$TBDIR_AARCH64"
  264. mkdir -p "$TBDIR/$EXTSPATH"
  265. mv $rootdir/ns.xpi "$TBDIR/$EXTSPATH/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi"
  266. rm -Rf "$TBDIR_AARCH64"
  267. [% END -%]
  268. [% IF c("var/windows") %]
  269. TBDIR="$distdir/$PKG_DIR/[% c("var/Project_Name") %]/Browser"
  270. [% ELSIF c("var/macos") %]
  271. TBDIR="$distdir/$PKG_DIR/[% c("var/Project_Name") %].app"
  272. [% ELSE %]
  273. TBDIR="$distdir/$PKG_DIR/Browser"
  274. [% END %]
  275. cat > "$scripts_dir/create-$PKG_DIR" << SCRIPT_EOF
  276. #!/bin/bash
  277. set -e
  278. cp -a ${TB_STAGE_DIR} $distdir/$PKG_DIR
  279. pushd "$TBDIR[% IF c("var/macos") %]/Contents/Resources/[% END %]"
  280. rm -f precomplete
  281. python $MARTOOLS/createprecomplete.py
  282. popd
  283. cd $distdir
  284. [% IF c("var/build_mar") -%]
  285. # Create full MAR file and compressed package.
  286. [% SET mar_file = c("var/project-name") _ '-' _ c("var/mar_osname") _ '-' _ c("var/torbrowser_version") _ '_${PKG_LOCALE}.mar' %]
  287. MAR=$MARTOOLS/mar \
  288. MOZ_PRODUCT_VERSION=[% c("var/torbrowser_version") %] \
  289. MAR_CHANNEL_ID=torbrowser-torproject-[% c("var/channel") %] \
  290. $MARTOOLS/make_full_update.sh -q $OUTDIR/[% mar_file %] "$TBDIR"
  291. [% END -%]
  292. [% IF c("var/linux") %]
  293. [% c('tar', {
  294. tar_src => [ '$PKG_DIR' ],
  295. tar_args => '-cJf $OUTDIR/' _ c("var/project-name") _ '-' _ c("var/mar_osname") _ '-' _ c("var/torbrowser_version") _ '_${PKG_LOCALE}.tar.xz',
  296. }) %]
  297. [% ELSIF c("var/macos") %]
  298. [% c('var/ddmg', {
  299. dmg_src => '"$PKG_DIR"',
  300. dmg_out => '$OUTDIR/' _ c('var/ProjectName') _ '-' _ c("var/torbrowser_version") _ '-' _ c("var/mar_osname") _ '_${PKG_LOCALE}.dmg',
  301. }) %]
  302. [% ELSIF c("var/windows") %]
  303. find "$PKG_DIR" -exec [% c("touch") %] {} \;
  304. pushd "$PKG_DIR"
  305. makensis [% c("var/projectname") %].nsi
  306. # Working around NSIS braindamage
  307. mv [% c("var/projectname") %]-install.exe browser-install-tmp.exe
  308. python3 $rootdir/pe_checksum_fix.py
  309. mv browser-install-tmp2.exe [% c("var/projectname") %]-install.exe
  310. rm browser-install-tmp.exe
  311. mv [% c("var/projectname") %]-install.exe $OUTDIR/[% c("var/projectname") %]-install[% IF c("var/windows-x86_64") %]-win64[% END %]-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.exe
  312. popd
  313. [% END %]
  314. rm -rf $distdir/${PKG_DIR}
  315. SCRIPT_EOF
  316. cp $rootdir/[% c('input_files_by_name/firefox') %]/mar-tools-*.zip "$OUTDIR"/
  317. [% IF c("var/linux-x86_64") -%]
  318. [% IF c("var/tor-browser") -%]
  319. cp $rootdir/[% c('input_files_by_name/firefox') %]/browser-debug.tar.xz "$OUTDIR"/[% c("var/project-name") %]-[% c("var/mar_osname") %]-debug.tar.xz
  320. [% END -%]
  321. [% IF !c("var/asan") -%]
  322. cp $rootdir/[% c('input_files_by_name/firefox') %]/geckodriver-linux64.tar.xz "$OUTDIR"/
  323. [% END -%]
  324. [% END -%]
  325. [%IF c("var/tor-browser") -%]
  326. tor_expert_bundle_src="[% c("input_files_by_name/tor-expert-bundle") %]"
  327. # strip off trailing "$buildid.tar.gz"
  328. tor_expert_bundle_dest=${tor_expert_bundle_src:0:-14}.tar.gz
  329. cp $rootdir/[% c("input_files_by_name/tor-expert-bundle") %] "$OUTDIR"/$tor_expert_bundle_dest
  330. [% IF c("var/macos_universal") %]
  331. tor_expert_bundle_src="[% c('input_files_by_name/tor-expert-bundle-aarch64') %]"
  332. # strip off trailing "$buildid.tar.gz"
  333. tor_expert_bundle_dest=${tor_expert_bundle_src:0:-14}.tar.gz
  334. cp $rootdir/[% c('input_files_by_name/tor-expert-bundle-aarch64') %] "$OUTDIR"/$tor_expert_bundle_dest
  335. [% END -%]
  336. [% END -%]
  337. [% IF c("var/build_infos_json") -%]
  338. cp $rootdir/[% c('input_files_by_name/firefox') %]/build-infos.json "$OUTDIR"/build-infos-[% c("var/mar_osname") %].json
  339. [% END -%]
  340. chmod 775 $rootdir/run_scripts "$scripts_dir"/*
  341. $rootdir/run_scripts [% c("num_procs") %] "$scripts_dir"