-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud-lab-vm-setup.sh
58 lines (47 loc) · 1.59 KB
/
cloud-lab-vm-setup.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
#!/bin/bash
# Remove ssh key passphrase to avoid halts due to interactive input
# ssh-keygen -p -f ~/.ssh/your-key
while getopts "q:v:u:" opt; do
case $opt in
q)
NUM_QUICKSTART_VMS="$OPTARG"
;;
v)
NUM_INVITRO_VMS="$OPTARG"
;;
u)
SSH_USER="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Check if the required options are provided
if [ -z "$NUM_QUICKSTART_VMS" ] || [ -z "$NUM_INVITRO_VMS" ] || [ -z "$SSH_USER" ]; then
echo "Usage: $0 -q <Number_of_quickstart_VMs> -v <Number_of_invitro_VMs> -u <Cloudlab_User>"
exit 1
fi
# Set permissions
chmod +x setup-node.sh
chmod +x add-vms.sh
chmod +x setup-ssh-tunnel.sh
# Compress Cloud-init files
zip -r cloud-init-files.zip cloud-init-files
# Compress Cloud-init files
zip -r post-setup-node.zip post-setup-node
# Specify the file containing the list of IP addresses (one per line)
IP_FILE="ip_list.txt" # Replace with your file name
# Check if the IP file exists
if [ ! -f "$IP_FILE" ]; then
echo "IP file '$IP_FILE' not found. Please create the file with one IP address per line."
exit 1
fi
# Loop through each IP address in the file and create a tmux session
while IFS= read -r ip; do
# Create a unique tmux session name based on the IP address
session_name="vm_${ip//./_}"
# Create a new tmux session with a window running the script
tmux new-session -d -s "$session_name" "./setup-node.sh $ip $SSH_USER && ./add-vms.sh -i $ip -v $NUM_INVITRO_VMS -q $NUM_QUICKSTART_VMS -u $SSH_USER && ./setup-ssh-tunnel.sh $ip $SSH_USER"
done < "$IP_FILE"