#!/bin/bash
[% c("var/set_default_env") -%]
ext_dir=assets/extensions
qa_apk=[% dest_dir %]/[% c('filename') %]/tor-browser-[% c("version") %]-[% c("var/osname") %]-multi-qa.apk
apk=$rootdir/fenix/app-[% c("var/abi") %]-*.apk

tar xavf $rootdir/[% c('input_files_by_name/fenix') %]

# Bundle our extensions. We treat HTTPS-Everywhere and NoScript differently as
# the former should be an internal extension without getting any updates besides
# from Tor Browser releases. NoScript will be copied over to the profile folder
# being a "regular" browser extension.
mkdir -p /var/tmp/build/$ext_dir [% dest_dir _ '/' _ c('filename') %]
cd /var/tmp/build
unzip -d $ext_dir/https-everywhere $rootdir/[% c('input_files_by_name/https-everywhere') %]
mv $rootdir/[% c('input_files_by_name/noscript') %] $ext_dir/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi

[% c('zip', {
        zip_src => [ '$ext_dir' ],
        zip_args => '$apk',
    }) %]

# Sign a QA build. This .apk is not a debug version and doesn't contain a debug
# flag in the manifest.
java -jar /usr/lib/android-sdk/build-tools/debian/apksigner.jar sign --verbose --min-sdk-version [% c("var/android_min_api") %] --ks $rootdir/android-qa.keystore --out $qa_apk --in $apk --ks-key-alias androidqakey --key-pass pass:android --ks-pass pass:android
