-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformat-san.sh
More file actions
executable file
路36 lines (28 loc) 路 976 Bytes
/
Copy pathformat-san.sh
File metadata and controls
executable file
路36 lines (28 loc) 路 976 Bytes
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
31
32
33
34
35
36
#!/usr/bin/env sh
: ${SAN=""}
formatted_san=""
while
# read the first dns or ip from SAN input
# split input by comma, colon and space
IFS=";, " read -r dnsOrIp SAN <<INPUT
$SAN
INPUT
# check for empty string (eg. SAN="some.tld;;;another.tld")
if [ "${dnsOrIp}n" != "n" ] ; then
# check if $dnsOrIp matches
isIp=$(echo $dnsOrIp | grep -E '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}\b')
if [ "${formatted_san}n" != "n" ] ; then
formatted_san="${formatted_san},"
fi
if [ "${isIp}n" != "n" ] ; then
# add to san definition as IP record
formatted_san="${formatted_san}IP:${dnsOrIp}"
else
# add to san definition as DNS record
formatted_san="${formatted_san}DNS:${dnsOrIp}"
fi
fi
# continue as long as there are more sans
[ "${SAN}n" != "n" ]
do :; done
echo $formatted_san