forked from ant-media/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy_ssl.sh
98 lines (82 loc) · 2.36 KB
/
easy_ssl.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
echo '''{
"Comment": "CREATE/DELETE/UPSERT a record ",
"Changes": [{
"Action": "CREATE",
"ResourceRecordSet": {
"Name":"test.antmedia.cloud",
"Type": "A",
"TTL": 300,
"ResourceRecords": [{ "Value":"1.1.1.1"}]
}}]}''' > aws_a.json
aws_env=$(<.env)
AWS_ACCESS_KEY=`echo $aws_env | awk '{print $1}'`
AWS_SECRET_KEY=`echo $aws_env | awk '{print $2}'`
AWS_JSON="aws_a.json"
#aws
if [ -z `which aws2` ]; then
rm -r aws* > /dev/null 2>&1
echo "Please wait. AWS Client is installing..."
curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" > /dev/null 2>&1
unzip awscliv2.zip > /dev/null 2>&1
sudo ./aws/install &
wait $!
echo "AWS Client installed."
rm -r aws*
fi
#Aws Configuration
aws2 configure set aws_access_key_id $AWS_ACCESS_KEY
aws2 configure set aws_secret_access_key $AWS_SECRET_KEY
aws2 configure set output json
usage() {
echo ""
echo "Usage: "
echo "-k ssh key"
echo "-u username"
echo "-i ip addrress"
echo "-d subdomain name (test01.antmedia.cloud)"
}
if [ "$#" -eq 0 ]; then
usage
fi
while getopts k:u:i:d: option
do
case "${option}"
in
k) k=${OPTARG};;
u) u=${OPTARG};;
i) i=${OPTARG};;
d) d=${OPTARG};;
esac
done
if [[ ! -z $k && ! -z $u && ! -z $i && ! -z $d ]]; then
if [ ! -f $k ]; then
echo "SSH key doesn't exist."
exit 1
elif [ ! -f $AWS_JSON ]; then
echo "AWS Json file doesn't exist."
fi
check=`aws2 route53 list-resource-record-sets --hosted-zone-id Z3BEXQLL4B8OB1 | grep "Name" | awk '{print $2}' | sed ''s/^.//';s/...$//'`
for c in $check; do
if [ "$c" == "$d" ]; then
echo "Subdomain exists"
exit 1
fi
done
#json file
sed -i 's^"Name".*^"Name":'\"$d\",'^' $AWS_JSON
sed -i 's^"Value":.*^"Value":'\"$i\"}]'^' $AWS_JSON
sleep 1
#create dns record
echo "Creating DNS Record"
aws2 route53 change-resource-record-sets --hosted-zone-id Z3BEXQLL4B8OB1 --change-batch file://$AWS_JSON
while [ -z $(dig +short $d @8.8.8.8) ]; do
now=$(date +"%H:%M:%S")
echo "$now > Please wait: dns failure"
sleep 10
done
echo "Dns success"
#ssl install script
echo "Installing SSL Certificate"
ssh -i $k $u@$i "sudo bash /usr/local/antmedia/enable_ssl.sh -d $d"
fi