#!/bin/bash

## vars
PROGDIR=/usr/share/java/jsignpdf
JAVA_OPTS="$JAVA_OPTS \
--add-exports jdk.crypto.cryptoki/sun.security.pkcs11=ALL-UNNAMED \
--add-exports jdk.crypto.cryptoki/sun.security.pkcs11.wrapper=ALL-UNNAMED \
--add-exports java.base/sun.security.action=ALL-UNNAMED \
--add-exports java.base/sun.security.rsa=ALL-UNNAMED \
--add-opens java.base/java.security=ALL-UNNAMED \
--add-opens java.base/sun.security.util=ALL-UNNAMED"

## dirty hack to get it both: relative paths and conf.properties
ln --symbolic "$PROGDIR"/conf
if [ $? -eq 0 ]; then
trap "{ unlink ./conf; }" EXIT
fi

## exec jar with or without splash
if [ $# -eq 0 ]; then
  "$JAVA_HOME/bin/java" $JAVA_OPTS -splash:"$PROGDIR"/splash.png -jar "$PROGDIR"/JSignPdf.jar
else
  "$JAVA_HOME/bin/java" $JAVA_OPTS -jar "$PROGDIR"/JSignPdf.jar "$@"
fi
