#!/bin/bash
#Some defines
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'

if [ "$EUID" -ne 0 ]; then
	echo -e "${RED}ERROR: Please run as root with sudo${NC}" >&2
	exit 1
fi

echo -e "${GREEN}Enter the name of the root signing certifcate without any suffix e.g. root${NC}"
read ROOT
echo -e "${GREEN}Enter the name of the requested sign request without any suffix e.g. mycert${NC}"
read CLIENT
echo -e "${GREEN}Enter the validity period in days${NC}"
read DAYS
echo "Singing with CA"
openssl ca -batch -config openssl.cnf -extensions ca_sign_ca -notext -days ${DAYS} -keyfile ${ROOT}.key -cert ${ROOT}.crt -in ${CLIENT}.csr -out ${CLIENT}.crt
openssl x509 -noout -text -in ${CLIENT}.crt
echo "Done"

