-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.sh
executable file
·60 lines (45 loc) · 1.69 KB
/
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
59
60
#!/bin/bash
#This script uploads everything required for `chef-solo` to run
set -e
if test -z "$3"
then
echo "I need
1) IP address of a machine to provision
2) Path to a Vagrant VM folder (a folder containing a Vagrantfile) that you want me to extract Chef recipes from
3) Path to a SSH private key for this machine"
exit 1
fi
#Run the Ruby script that reads Vagrantfile to make dna.json and cookbook tarball
echo "Making cookbooks tarball and dna.json"
ruby `dirname $0`/ec2_package.rb $2
#Try to match and extract a port provided to the script
ADDR=$1
IP=${ADDR%:*}
PORT=${ADDR#*:}
if [ "$IP" == "$PORT" ] ; then
PORT=22
fi
USERNAME=ubuntu
COOKBOOK_TARBALL=$2/cookbooks.tgz
DNA=$2/dna.json
EC2_SSH_PRIVATE_KEY=$3
#make sure this matches the CHEF_FILE_CACHE_PATH in `bootstrap.sh`
CHEF_FILE_CACHE_PATH=/tmp/cheftime
#Upload everything to the home directory (need to use sudo to copy over to $CHEF_FILE_CACHE_PATH and run chef)
echo "Uploading cookbooks tarball and dna.json"
scp -i $EC2_SSH_PRIVATE_KEY -r -P $PORT \
$COOKBOOK_TARBALL \
$DNA \
$USERNAME@$IP:.
echo "Running chef-solo"
#check to see if the bootstrap script has completed running
eval "ssh -q -t -p \"$PORT\" -l \"$USERNAME\" -i \"$EC2_SSH_PRIVATE_KEY\" $USERNAME@$IP \"sudo -i which chef-solo > /dev/null \""
if [ "$?" -ne "0" ] ; then
echo "chef-solo not found on remote machine; it is probably still bootstrapping, give it a minute."
exit
fi
#Okay, run it.
eval "ssh -t -p \"$PORT\" -l \"$USERNAME\" -i \"$EC2_SSH_PRIVATE_KEY\" $USERNAME@$IP \"sudo -i sh -c 'cd $CHEF_FILE_CACHE_PATH && \
cp -r /home/$USERNAME/cookbooks.tgz . && \
cp -r /home/$USERNAME/dna.json . && \
chef-solo -c solo.rb -j dna.json -r cookbooks.tgz'\""