cd /work-dir;
mkdir tls;
wget -c $TLS_CA_CERTIFICATE_URL;
if [ "$TLS_CA_CERTIFICATE_FILE_TYPE" = "archive" ]; then tar -zxf $TLS_CA_CERTIFICATE_FILE_NAME -C tls --strip-components 1; else cp $TLS_CA_CERTIFICATE_FILE_NAME tls/ca-cert.pem; fi;
rm -rf $$TLS_CA_CERTIFICATE_FILE_NAME;
mkdir signature;
wget -c $SIGNATURE_CA_CERTIFICATE_URL;
if [ "$SIGNATURE_CA_CERTIFICATE_FILE_TYPE" = "archive" ]; then tar -zxf $SIGNATURE_CA_CERTIFICATE_FILE_NAME -C signature --strip-components 1; else cp $SIGNATURE_CA_CERTIFICATE_FILE_NAME signature/ca-cert.pem; fi;
rm -rf $SIGNATURE_CA_CERTIFICATE_FILE_NAME;
export FABRIC_CA_CLIENT_TLS_CERTFILES=/work-dir/signature/ca-cert.pem;
fabric-ca-client enroll -d -u https://$SIGNATURE_PEER_USER_NAME:$SIGNATURE_PEER_USER_PASSWORD@$SIGNATURE_CA_ADDRESS;
export FABRIC_CA_CLIENT_MSPDIR=tls-msp;
export FABRIC_CA_CLIENT_TLS_CERTFILES=/work-dir/tls/ca-cert.pem;
fabric-ca-client enroll -d -u https://$TLS_PEER_USER_NAME:$TLS_PEER_USER_PASSWORD@$TLS_CA_ADDRESS --enrollment.profile tls --csr.hosts $PEER_NAME;
cd /work-dir/hyperledger/org1/peer1/tls-msp/keystore && mv * key.pem;
cd /work-dir/hyperledger/org1/peer1/tls-msp/tlscacerts && mv * tls.pem;
export FABRIC_CA_CLIENT_HOME=/work-dir/hyperledger/org1/admin;
export FABRIC_CA_CLIENT_TLS_CERTFILES=/work-dir/signature/ca-cert.pem;
export FABRIC_CA_CLIENT_MSPDIR=msp;
fabric-ca-client enroll -d -u https://$SIGNATURE_USER_USER_NAME:$SIGNATURE_USER_USER_PASSWORD@$SIGNATURE_CA_ADDRESS;
mkdir -p /work-dir/hyperledger/org1/peer1/msp/admincerts;
cp /work-dir/hyperledger/org1/admin/msp/signcerts/cert.pem /work-dir/hyperledger/org1/peer1/msp/admincerts/org1-admin-cert.pem;
