-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.nodes.sh
executable file
·53 lines (47 loc) · 1.65 KB
/
install.nodes.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
#!/bin/bash
KEYFILE="/Users/phagedorn/.ssh/namics.pem"
REMOTEUSER="ubuntu"
instance_count=1
SSH_PORT=22
secGroup="sg-1a79946d"
ami="ami-09e3dc7d"
keyName="namics"
keyLocation=$KEYFILE
region=EU-WEST-1
debug="test"
if [ "$debug" = "test" ]; then
echo DEBUG MODE
echo DEBUG MODE - we will use preconfigured virtualbox instance
TEST_HOST="localhost"
SSH_PORT="2222"
echo DEBUG MODE - SET HOST AND PORT to $TEST_HOST : $SSH_PORT
else
rm ec2hosts.txt
for (( c=1; c<=instance_count; c++ ))
do
echo Create Instance Number $c ...
instance_id=$(ec2-run-instances --region=$region -k $keyName -g $secGroup -t m1.large $ami | awk '/INSTANCE/{print $2}')
echo $instance_id
sleep 50
name=$(ec2-describe-instances --region=$region $instance_id | awk '/INSTANCE/{print $4}')
echo $name
echo $name >> ec2hosts.txt
done
fi
node=0
if [ "$debug" = "test" ]; then
echo DEBUG MODE - copy install_deb.sh to target server
scp -P $SSH_PORT install_debs.sh $REMOTEUSER@$TEST_HOST:/tmp
echo DEBUG MODE - connect to target server
ssh -n -p $SSH_PORT $REMOTEUSER@$TEST_HOST "bash /tmp/install_debs.sh $node $IPNODE $debug"
else
for host in `cat ec2hosts.txt`
do
let "node+=1"
if [ $node == 1 ]; then
IPNODE=$(ssh -p $SSH_PORT -i $KEYFILE $SSHOPT $REMOTEUSER@$host "/sbin/ifconfig eth0 " | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
fi
scp -P $SSH_PORT $KEYFILE $SSHOPT install_debs.sh $REMOTEUSER@$host:/tmp
ssh -n -i $KEYFILE $SSHOPT $REMOTEUSER@$host bash /tmp/install_debs.sh $node $IPNODE
done
fi