forked from g7240/pipe-tf-ncr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployAndExecute.sh
51 lines (44 loc) · 1.47 KB
/
deployAndExecute.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
#!/bin/bash
# Read DNS from pipe redirected stdin
DNS=$(grep -oP 'instance_public_dns\s*=\s*"\K[^"]+')
# Verify if DNS is found
if [ -z "$DNS" ]; then
echo "Error: DNS not found in the output"
exit 1
fi
echo "Found DNS: $DNS"
# Copy code to be executed on server
sleep 10
echo "Upload serverSideEC2Code.sh"
scp -o StrictHostKeyChecking=no -i ./../testED25519Key ./../../serverSideEC2Code.sh admin@"$DNS":
# Verify SCP correctness
if [ $? -ne 0 ]; then
echo "Error: failed SCP of ./serverSideEC2Code.sh"
exit 1
fi
# Compress folder to be uploaded in EC2
echo "Compress int_didroom_issuer1"
tar -czf ./../../int_didroom_issuer1.tar.gz ./../../microservices/int_didroom_issuer1
if [ $? -ne 0 ]; then
echo "Error: failed tar.gz"
exit 1
fi
# Copy zip microservices issuer folder to the EC" server
echo "Upload int_didroom_issuer1.tar.gz"
scp -o StrictHostKeyChecking=no -i ./../testED25519Key ./../../int_didroom_issuer1.tar.gz admin@"$DNS":
# Verify SCP comand correctness
if [ $? -ne 0 ]; then
echo "Error: failed SCP of ./int_didroom_issuer1.tar.gz"
exit 1
fi
#remove local zip copy file
echo "Remove local copy of int_didroom_issuer1.tar.gz"
rm ./../../int_didroom_issuer1.tar.gz
# Execute server side the uploaded code
echo "Start script server side via SSH"
ssh -o StrictHostKeyChecking=no -i ./../testED25519Key admin@"$DNS" "bash ./serverSideEC2Code.sh $DNS"
# Verify SSH comand correctness
if [ $? -ne 0 ]; then
echo "Errore: SSH fallito."
exit 1
fi