#!/bin/bash
#
# Example-script to show, how to set up a self-signed CA
#
# Usage:
# ./create-certs.sh

VALIDITY=365
PASSWORD=confidential
if [ -a ca-cert ];
then
  echo "The root-certificate for the CA already exists...";
else
  echo "Creating a x509-certificate for the CA...";
  openssl req -new -x509 -subj "/C=DE/ST=NRW/L=MS/O=trion/OU=kafka/CN=Root-CA" -keyout ca-key -out ca-cert -days $VALIDITY -passout pass:$PASSWORD
fi
#

if [ -a truststore.jks ];
then
  echo "The keystore truststore.jks already exists!";
else
  echo "Importing the root-certificate of the CA into truststore.jks..."
  keytool -keystore truststore.jks -storepass $PASSWORD -alias CARoot -import -file ca-cert -noprompt
fi


# Generating certificates for the standalone ZooKeeper, an example CLI-client
# and the two Kafka-Brokers
./gencert.sh zookeeper
./gencert.sh client
./gencert.sh kafka-1
./gencert.sh kafka-2
