-
Notifications
You must be signed in to change notification settings - Fork 4
/
remoteInstall.sh
executable file
·56 lines (48 loc) · 1.59 KB
/
remoteInstall.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
#!/bin/bash
# Installs necessary packages, docker image and shut down the instance.
# Load values of
# STOCKHOLM_VANILLA_INSTANCE_ID & FRANKFURT_VANILLA_INSTANCE_ID
[[ -f "VANILLA_IDS.txt" ]] &&
source "VANILLA_IDS.txt" ||
exit 1
main(){
local STOCKHOLM_VANILLA_INSTANCE_IP=`getInstanceIP "eu-north-1" ${STOCKHOLM_VANILLA_INSTANCE_ID}`
[[ -z ${STOCKHOLM_VANILLA_INSTANCE_IP} ]] && exit 1
local FRANKFURT_VANILLA_INSTANCE_IP=`getInstanceIP "eu-central-1" ${FRANKFURT_VANILLA_INSTANCE_ID}`
[[ -z ${FRANKFURT_VANILLA_INSTANCE_IP} ]] && exit 1
echo "Stockholm IP: " ${STOCKHOLM_VANILLA_INSTANCE_IP}
echo "Frankfurt IP: " ${FRANKFURT_VANILLA_INSTANCE_IP}
# TODO: Prevent the action in case there is more than one IP returned.
install "key-stockholm-0.pem" ${STOCKHOLM_VANILLA_INSTANCE_IP} &
install "key-frankfurt-0.pem" ${FRANKFURT_VANILLA_INSTANCE_IP}
wait
}
getInstanceIP(){
aws ec2 describe-instances \
--region ${1} \
--instance-ids ${2} \
--query "Reservations[*].Instances[*].{HeroiamSlava:PublicIpAddress}" \
--filters "Name=instance-state-code,Values=16" \
--o text
}
install(){
scp \
-i ${1} \
-o "IdentitiesOnly yes" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
vpc-installer.sh ubuntu@${2}:/home/ubuntu
ssh \
-i ${1} \
-o "IdentitiesOnly yes" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
ubuntu@${2} chmod +x vpc-installer.sh
ssh \
-i ${1} \
-o "IdentitiesOnly yes" \
-o "StrictHostKeyChecking no" \
-o "UserKnownHostsFile /dev/null" \
ubuntu@${2} ./vpc-installer.sh
}
./checkAWS.sh && main || ./awsCliNa.sh