-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_payload.sh
57 lines (45 loc) · 2.11 KB
/
send_payload.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
#!/bin/bash
DIRECTORY_TO_TRANSFER="./payload"
ARCHIVE_NAME="payload.tar.gz"
# Set default SSH key location
DEFAULT_SSH_KEY="~/.ssh/id_rsa"
# Allow user to override the SSH key location
SSH_KEY=${SSH_KEY:-$DEFAULT_SSH_KEY}
# Fetch the IP addresses from Pulumi stack outputs
pulumi stack output -j > ./payload/ips.json
STACK_OUTPUT=$(pulumi stack output -j)
echo $STACK_OUTPUT
DROPLET_IPS=$(echo "$STACK_OUTPUT" | jq -r '.[]')
cp ./scripts/init_install.sh ./payload/init_install.sh
cp ./scripts/txsim.sh ./payload/txsim.sh
cp ./scripts/vars.sh ./payload/vars.sh
cp ./scripts/upload_traces.sh ./payload/upload_traces.sh
cp ./scripts/shutdown_txsim.sh ./payload/shutdown_txsim.sh
cp ./data/congest-remote-key-gbq.json ./payload/congest-remote-key-gbq.json
# copy the env vars into a temp file that is included in the payload to each validator
echo "export CHAIN_ID=\"$CHAIN_ID\"" >> ./payload/vars.sh
echo "export AWS_DEFAULT_REGION=\"$AWS_DEFAULT_REGION\"" >> ./payload/vars.sh
echo "export AWS_ACCESS_KEY_ID=\"$AWS_ACCESS_KEY_ID\"" >> ./payload/vars.sh
echo "export AWS_SECRET_ACCESS_KEY=\"$AWS_SECRET_ACCESS_KEY\"" >> ./payload/vars.sh
echo "export S3_BUCKET_NAME=\"$S3_BUCKET_NAME\"" >> ./payload/vars.sh
sleep 30
# Compress the directory
echo "Compressing the directory $DIRECTORY_TO_TRANSFER..."
tar -czf "$ARCHIVE_NAME" -C "$(dirname "$DIRECTORY_TO_TRANSFER")" "$(basename "$DIRECTORY_TO_TRANSFER")"
# Function to transfer and uncompress files on the remote server
transfer_and_uncompress() {
local IP=$1
echo "Transferring files to $IP -----------------------"
scp -i "$SSH_KEY" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$ARCHIVE_NAME" "root@$IP:/root/"
# Uncompress the directory on the remote node
echo "Uncompressing the directory on $IP..."
ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "root@$IP" "tar -xzf /root/$ARCHIVE_NAME -C /root/"
}
# Loop through the IPs and run the transfer and uncompress in parallel
for IP in $DROPLET_IPS; do
transfer_and_uncompress "$IP" &
done
# Wait for all background processes to finish
wait
# Cleanup local archive
rm "$ARCHIVE_NAME"