#!/bin/bash
set -e

no_generate_config=1
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "$script_dir/functions"

cd ~/"$SIGNING_PROJECTNAME-$tbb_version"

test -n "$GPG_PASS" || read -sp "Enter gpg passphrase: " GPG_PASS
currentdir=$(pwd)
for i in `find . -name "*.dmg" -o -name "*.exe" -o -name "*.tar.xz" \
  -o -name "*.txt" -o -name "*.zip" -o -name "*.tar.gz" -o -name "*.apk" \
  -o -name "*.deb" -o -name "*.rpm" | sort`
do
  if test -f "$i.asc"
  then
    echo "Removing $i.asc"
    rm -f "$i.asc"
  fi
  echo "Signing $i"
  i="$currentdir/$i"
  tmpsig=$(mktemp)
  echo "$GPG_PASS" | sudo -u signing-gpg -- "$wrappers_dir/sign-gpg" "$i" > "$tmpsig"
  mv -f "$tmpsig" "${i}.asc"
  chmod 644 "${i}.asc"
done
