#!/bin/bash

set -e
no_generate_config=1
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "$script_dir/functions"
# tbb_version_type is used in wrappers/sign-rcodesign, so we export it
export tbb_version_type

if [ -z "$RCODESIGN_PW" ]; then
    echo "Enter passphrase"
    stty -echo; read RCODESIGN_PW; stty echo
    export RCODESIGN_PW
fi

display_name=$(display_name)
output_file=$(project-name)-macos-${tbb_version}-rcodesign-signed.tar.zst
destdir=~/"$SIGNING_PROJECTNAME-$tbb_version-macos-signed"
mkdir -p $destdir
rm -f "$destdir/$output_file"

sudo -u signing-macos -- /signing/tor-browser-build/tools/signing/wrappers/sign-rcodesign-128 ~/"$SIGNING_PROJECTNAME-$tbb_version"/$(project-name)-macos-${tbb_version}.dmg "$display_name"
cp "/home/signing-macos/last-signed-$display_name.tar.zst" "$destdir/$output_file"
