#!/bin/bash -x

APP_ENV="${APP_ENV:-dev}"

if [[ ${APP_ENV#*=} == "prod" ]]; then
    service pcscd start
    cert=$(/opt/cprocsp/bin/amd64/csptest -keyset -enum_cont -verifyc -fq  | grep Aktiv | awk -F'00 00' '{print $2}' | tr -d '\\')
    /opt/cprocsp/bin/amd64/certmgr -inst -cont "${cert}" -store uMy
    certmgr -list -store umy
    SHA=$(certmgr -list -store umy | grep SHA | awk -F':' '{print $2}' | tr -d ' ')
fi
# pdfcpro sign /mnt/t/123.pdf -out /mnt/t/123_sign.pdf -cert ${SHA} -text "\n\t\tПодписано ЭП\n\t\t{subject/cn}\n\t\tСертификат {sha1}\n\t\tДействителен от {since} до {until}\n\t\tДата {date}\n\t\t{subject/t}\n\t\t{subject/fullname}\n\t\t" -fontfile /usr/local/share/fonts/Inter-Bold.ttf -fontsize 8 -x 2 -y 2 -w 96 -h 9


exec "$@"
