-
Notifications
You must be signed in to change notification settings - Fork 0
/
awsCert
executable file
·56 lines (46 loc) · 2.04 KB
/
awsCert
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
#check for dependencies
if ! command -v fzf &>/dev/null
then
echo "installing fzf"
brew install fzf
fi
if ! command -v rg &>/dev/null
then
echo "installing ripgrep"
brew install ripgrep
fi
read -p "Insert a New site name: " FQDN
echo $FQDN
STARNAME=$(aws acm list-certificates | rg Domain | awk -F : '{ print $2 }' | sed 's/"//g' | fzf --prompt="Add to which domain? " | sed 's/*//g')
SITENAME=$(aws acm list-certificates | rg Domain | awk -F : '{ print $2 }' | sed 's/"//g' | fzf --prompt="For the regex: ")
CERTARN=$(aws acm list-certificates | rg -B1 $STARNAME | rg arn | sed -n 1p | awk '{ print $2 }' | sed 's/"//g;s/,//g')
aws acm describe-certificate --certificate-arn ${CERTARN} > ~/certs.json
jq '.Certificate.DomainValidationOptions[] | [.DomainName, .ResourceRecord.Name, .ResourceRecord.Value]' ~/certs.json | \
sed 's/\[//g;s/\]//g;s/"//g;s/,//' > ~/subDoms
SUBDOMAIN=$(jq '.Certificate.DomainValidationOptions[] | [.DomainName]' ~/certs.json | sed 's/\[//g;s/\]//g;s/"//g;s/,//;/^$/d' > ~/subDoms)
SUBDOMOUT=$(cat ~/subDoms)
RNAME=$(jq '.Certificate.DomainValidationOptions[] | [.DomainName, .ResourceRecord.Name]' ~/certs.json | \
sed 's/\[//g;s/\]//g;s/"//g;s/,//;/^$/d' > ~/rname)
cat ~/rname
RVALUE=$(jq '.Certificate.DomainValidationOptions[] | [.DomainName, .ResourceRecord.Value]' ~/certs.json | \
sed 's/\[//g;s/\]//g;s/"//g;s/,//;/^$/d' > ~/rvalue)
cat ~/rvalue
aws acm request-certificate \
--domain-name ${SITENAME} \
--validation-method DNS
--subject-alternative-names ${SUBDOMOUT} $FQDN > ~/newArn
if [ "$?" -eq 0 ]; then
echo "Cert updated with ${FQDN}, check https://us-east-1.console.aws.amazon.com/acm/home?region=us-east-1#/certificates/list-certificates
for details on your new certificate."
exit 0
else
echo "CERT DID NOT UPDATE.
AWS ACM command failed: Check the ~/subDoms file,
or ensure that you have a fully-qualified-domain-name"
exit 1
fi
rm ~/rvalue
rm ~/rname
rm ~/subDoms
rm ~/certs.json