summaryrefslogtreecommitdiffstats
path: root/split-ca-bundle.sh
blob: d0f39a85a6a6a333563380a9a07c8b4c8f6f87f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh

mkcert() {
	local name="$1"
	local line
	rm -f "$name"
	while read line; do
		printf "%s\n" "$line" >> "$name"
		if [ "$line" = "-----END CERTIFICATE-----" ]; then
			break;
		fi
	done
}

prev=
while read line; do
	case "$line" in
	=*=)
		fname="$(printf "%s" "$prev" | tr '/ (),' '__==_').crt"
		while read cline; do
			printf "%s\n" "$cline"
			if [ "$cline" = "-----END CERTIFICATE-----" ]; then
				break;
			fi
		done > "$fname"
		;;
	esac
	prev="$line"
done