-
Notifications
You must be signed in to change notification settings - Fork 2
/
bootstrap.sh
executable file
·89 lines (74 loc) · 2.62 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
cd $(dirname "${BASH_SOURCE}")
BREW_DIR=/opt/homebrew
APP_DIR="/Applications"
DOTFILES_REMOTE="https://github.com/tipplrio/dotfiles.git"
DOTFILES_LOCAL=$(pwd)
DOTFILES_HOME=$HOME
LOCALHOST_VAR="${DOTFILES_LOCAL}/.ansible/host_vars/localhost"
ARG1=$1
ARG2=$2
function bootstrap() {
# Ask for the administrator password upfront.
if [ "$(whoami)" != "root" ]; then
sudo -v
# Keep-alive: update existing `sudo` time stamp until the script has finished.
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
fi
if [ "$ARG1" != '--no-update' -a "$ARG2" != '--no-update' ]; then
echo "Updating OS X. If this requires a restart, run the script again."
sudo softwareupdate -iva
if ! xcode-select -p > /dev/null ; then
echo "Installing Xcode Command Line Tools."
xcode-select --install
while ! xcode-select -p > /dev/null ; do sleep 1; done
sudo xcodebuild -license
fi
fi;
# Check for Homebrew and install if we don't have it.
if [[ $(which brew) != ${BREW_DIR}* ]]; then
if [ $(which brew) ]; then
echo "Uninstalling the existing Homebrew."
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall > uninstall
chmod 755 uninstall
./uninstall --path=$(dirname $(dirname $(which brew))) --force
rm -f uninstall
fi
echo "Installing Homebrew."
sudo mkdir -p ${BREW_DIR}
sudo chown -R $(id -un) ${BREW_DIR}
sudo chgrp -R $(id -gn) ${BREW_DIR}
curl -L https://github.com/Homebrew/homebrew/tarball/master | tar xz --strip 1 -C ${BREW_DIR}
export PATH="${BREW_DIR}/bin:$PATH"
fi
echo "Installing Python and Ansible via Homebrew."
brew install python ansible
rm -rf ${DOTFILES_HOME}/.ansible
ln -s ${DOTFILES_LOCAL}/.ansible ${DOTFILES_HOME}
echo "Configuring the playbook variables."
mkdir -p $(dirname ${LOCALHOST_VAR})
cat <<EOF > ${LOCALHOST_VAR}
---
brew_dir: "${BREW_DIR}"
bin_dir: "${BREW_DIR}/bin"
app_dir: "${APP_DIR}"
dotfiles_remote: "${DOTFILES_REMOTE}"
dotfiles_local: "${DOTFILES_LOCAL}"
dotfiles_home: "${DOTFILES_HOME}"
EOF
echo "Install the required Ansible roles."
cd ${DOTFILES_HOME}/.ansible
ansible-galaxy install -f -r requirements.yml -p roles/
cd ${DOTFILES_LOCAL}
echo 'Now you can run the playbook by executing the script: `./update.sh`'
}
if [ "$ARG1" == '-f' -o "$ARG1" == '--force' -o "$ARG2" == '-f' -o "$ARG2" == '--force' ]; then
bootstrap
else
read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
bootstrap
fi;
fi;
unset ARG1 ARG2 bootstrap