#!/bin/bash
set -e

. mkp4a.common

pass1=""
pass2=""
keyalias="python"
keystore="${PWD}/bin/keystore"
if [ $1 ]; then
  pass1=$1
  pass2=$1
else
  echo "usage: ./mkp4a.release <keystore-password> [<keyalias-password>] [<keyalias>] [<keystore-path>]"
  echo "        (use ./mkkeystore to create one in default location)"
  exit
fi
if [ $2 ]; then
  pass2=$2
fi
if [ $3 ]; then
  keyalias=$3
fi
if [ $4 ]; then
  keystore=$4
fi

export P4A_RELEASE_KEYSTORE="$keystore"
export P4A_RELEASE_KEYSTORE_PASSWD="$pass1"
export P4A_RELEASE_KEYALIAS_PASSWD="$pass2"
export P4A_RELEASE_KEYALIAS="$keyalias"

python3 -m pythonforandroid.toolchain apk \
  ${p4a_options} \
  --release \
  --sign

# keystore options (instead environment vars):
#
# keystore:        --keystore <file>
# key alias        --signkey   <keyalias>
# keystore passwd  --keystorepw  <pass1>
# key passwd       --signkeypw   <pass2>
