#!/bin/bash

CAname=CANAME

[[ -z $1 ]] && echo "arg missing" && exit 1

if ! which -a csplit 2>&1 >/dev/null; then
	echo "binary csplit missing" && exit 2
fi

nr=$(grep -c 'END CERTIFICATE' $1)
((nr --))
csplit -k -f $CAname "$1" '/END CERTIFICATE/+1' {$nr}

for i in $CAname*; do openssl x509 -in $i -subject -noout ; done
