-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.bash
executable file
·80 lines (59 loc) · 2.26 KB
/
bootstrap.bash
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
#!/usr/bin/env bash
# On a fresh system, this script assumes the existence of Python and Git.
# 1. It creates a virtualenv in a temporary directory and installs Ansible
# within it.
# 2. It then clones the dotfiles repo if not present already.
# 3. Running ansible-playbook is a separate command to give flexibility in
# terms of arguments and avoid obscuring it inside the script.
# NOTE: we can't use ansible-pull because we can't pass options
# that require interaction to ansible-pull (e.g. --ask-vault-pass
# or even --ask-become-pass) despite misleading docs.
# *********** What to run on a new system ***********
# ===== First run =====
# curl -sSfL https://raw.githubusercontent.com/MurtadhaInit/dotfiles/main/bootstrap.bash | bash && $HOME/ansible-temp/ansible-setup/bin/ansible-playbook ~/.dotfiles/local.yml --ask-become-pass --ask-vault-pass --skip-tags all_apps
# ===== Subsequent runs =====
# $HOME/ansible-temp/ansible-setup/bin/ansible-playbook ~/.dotfiles/local.yml --ask-become-pass --ask-vault-pass --skip-tags all_apps
# If Python, pipx, and ansible (through pipx) were successfully
# installed, replace the above with just ansible-playbook and
# delete ~/ansible-temp
# Sign in with Apple ID and remove --skip-tags all_apps to do a full install
# ***************************************************
# check if a command exists
function exists() {
command -v "$1" >/dev/null 2>&1
# This is equivalent to:
# command -v $1 1>/dev/null 2>/dev/null
}
if ! exists python3; then
echo "Python needs to be installed"
exit
fi
if [ ! -d "$HOME/ansible-temp" ]; then
mkdir "$HOME/ansible-temp"
fi
cd "$HOME/ansible-temp" || exit
if ! exists pip3; then
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --user
fi
python3 -m pip install --upgrade pip
if ! pip3 show virtualenv 1>/dev/null 2>&1; then
pip3 install virtualenv
fi
if ! pip3 show setuptools 1>/dev/null 2>&1; then
pip3 install setuptools
fi
python3 -m virtualenv ansible-setup
source ansible-setup/bin/activate
pip install ansible
deactivate
if exists git; then
if [ ! -d "$HOME/.dotfiles" ]; then
git clone --recursive https://github.com/MurtadhaInit/dotfiles.git "$HOME/.dotfiles"
fi
else
echo "Git needs to be installed"
exit
fi
# when done...
# rm -rf ansible-temp