-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
81 lines (74 loc) · 2.74 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
#!/usr/bin/env bash
# Prevent the script from running unless it is sourced
(return 0 2>/dev/null) || { echo "This script should be sourced, not executed directly"; exit 1; }
GREEN="\e[32m"
RED="\e[31m"
YELLOW="\e[1;33m"
CR="\e[0m"
# ---------------------------------------------
# ~/.local/bin
# ---------------------------------------------
if [[ ":${PATH}:" != *":${HOME}/.local/bin:"* ]]; then
echo "adding ${HOME}/.local/bin to PATH"
export PATH=~/.local/bin:$PATH
else
echo "✓ ${HOME}/.local/bin already in path"
fi
# ---------------------------------------------
# Install stuff
# ---------------------------------------------
echo -e "\n\n------------------------------------------------------------------------"
echo "Installing git, python3-pip, and ansible (may require sudo password)"
echo "------------------------------------------------------------------------"
sudo apt update
sudo apt install -y python3-apt gpg python3-pip
pip install -U --user ansible
pip install -U --user jmespath
# ---------------------------------------------
# Clone neel-m.gcm Repo
# ---------------------------------------------
echo -e "\n\n------------------------------------------------------------------------"
echo "Clone (or check existing) neel-m.gcm repo -> ~/.neel-m.gcm"
echo "------------------------------------------------------------------------"
gcm_dest=.neel-m.gcm
if [ -d "${HOME}/$gcm_dest" ]; then
pushd "${HOME}/$gcm_dest" > /dev/null
git status > /dev/null
rc=$?
if [ "$rc" == 0 ]; then
echo -e "${GREEN}✓${CR} ${gcm_dest} exists and is a git repo. Syncing."
git pull
popd > /dev/null
else
popd > /dev/null
echo -e "${RED} ${HOME}/${gcm_dest} exists but is not a git repo? Fix please."
exit 1
fi
else
cd ~
git clone https://github.com/neel-m/neel-m.gcm.git $gcm_dest
rc=$?
if [ "$rc" != 0 ]; then
echo -e "${RED}ERROR: could not clone the gcm repo${CR}"
exit 1
fi
fi
# ---------------------------------------------
# Run Playbook
# ---------------------------------------------
echo -e "\n\n------------------------------------------------------------------------"
echo "Ready to run ansible and complete the configuration of your env."
echo "This will take a few minutes."
echo -e "\n\n${GREEN}Ansible will ask you for your sudo password${CR}"
echo -e "${GREEN}with the prompt ${YELLOW}'BECOME password:'${CR}"
echo "------------------------------------------------------------------------"
pushd "$HOME/$gcm_dest/ansible" > /dev/null
ansible-playbook gcm_book.yaml
rc=$?
popd > /dev/null
if [ "$rc" == "0" ]; then
echo -e "${GREEN}Your environment is now ready.${CR}"
source ~/.bashrc
else
echo -e "${RED}Something didn't work with ansible.${CR}"
fi