-
Notifications
You must be signed in to change notification settings - Fork 6
/
bootstrap.sh
64 lines (52 loc) · 1.49 KB
/
bootstrap.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
61
62
63
64
#!/bin/bash
set -e
if [ ! "$HOME" == "$PWD" ]; then
echo "This script is intended to be run from the user's home path: $HOME"
exit 1
fi
# DEFAULTS
BRANCH="master"
ANSIBLE_ARGS=""
# Use -gt 1 to consume two arguments per pass in the loop (e.g. each
# argument has a corresponding value to go with it).
# Use -gt 0 to consume one or more arguments per pass in the loop (e.g.
# some arguments don't have a corresponding value to go with it such
# as in the --default example).
# note: if this is set to -gt 0 the /etc/hosts part is not recognized ( may be a bug )
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-b|--branch)
BRANCH="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
# BOOTSTRAP
# Add apt repositories
if ! grep -q "ansible/ansible" /etc/apt/sources.list /etc/apt/sources.list.d/*; then
sudo apt-add-repository ppa:ansible/ansible
fi
if ! grep -q "git-core/ppa" /etc/apt/sources.list /etc/apt/sources.list.d/*; then
sudo apt-add-repository ppa:git-core/ppa
fi
# Upgrade packages
sudo apt-get update
sudo apt-get --assume-yes upgrade
# Install Ansible & Git
sudo apt-get --assume-yes install ansible
sudo apt-get --assume-yes install git
# Clone dev-env repo if not already present
if [ ! -d ".dev-env" ]; then
git clone https://github.com/pbassiner/dev-env.git .dev-env
fi
# Checkout specified branch
cd .dev-env
git checkout ${BRANCH}
# Run Ansible playbook
ansible-playbook ubuntu.yml -i hosts -vv ${ANSIBLE_ARGS}