-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·162 lines (143 loc) · 3.66 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·162 lines (143 loc) · 3.66 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env bash
set -euo pipefail
source .env
RESTORE=$(echo -en '\033[0m')
RED=$(echo -en '\033[00;31m')
GREEN=$(echo -en '\033[00;32m')
YELLOW=$(echo -en '\033[00;33m')
BLUE=$(echo -en '\033[00;34m')
MAGENTA=$(echo -en '\033[00;35m')
PURPLE=$(echo -en '\033[00;35m')
CYAN=$(echo -en '\033[00;36m')
LIGHTGRAY=$(echo -en '\033[00;37m')
LRED=$(echo -en '\033[01;31m')
LGREEN=$(echo -en '\033[01;32m')
LYELLOW=$(echo -en '\033[01;33m')
LBLUE=$(echo -en '\033[01;34m')
LMAGENTA=$(echo -en '\033[01;35m')
LPURPLE=$(echo -en '\033[01;35m')
LCYAN=$(echo -en '\033[01;36m')
WHITE=$(echo -en '\033[01;37m')
check_platform() {
case "${OSTYPE}" in
"darwin"*)
check_brew
;;
"linux-gnu")
check_distro
# rundazsh
;;
*)
echo "Unsupported platform type ${OSTYPE}"
;;
esac
}
check_brew() {
if [[ -f /opt/homebrew/bin/brew ]]; then
echo "Brew found."
else
echo "Brew not found. Installing..."
/bin/bash -c \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
check_brew
fi
check_ansible_mac
}
check_ansible_mac() {
if [[ -f /opt/homebrew/bin/ansible ]]; then
echo "Ansible found. Installing collections and running playbook..."
install_collections
else
echo "Ansible not found. Installing..."
brew update
brew upgrade
brew install ansible
check_ansible_mac
fi
}
check_distro() {
DISTRO="$(awk -F '=' '{print $2}' /etc/os-release | head -n 1 | sed 's/"//g')"
case "${DISTRO}" in
"Rocky Linux"*)
check_ansible_rocky
;;
"Fedora Linux"*)
check_ansible_fedora
;;
"Ubuntu"*)
check_ansible_debian
;;
"Arch Linux"*)
check_brew
;;
"Debian"*)
check_ansible_debian
;;
"Raspbian"*)
check_ansible_debian
;;
*)
echo "Unsupported distro $DISTRO"
;;
esac
}
check_ansible_debian() {
if [[ -f /usr/bin/ansible ]]; then
echo "Ansible found. Installing collections and running playbook..."
install_collections
else
echo "Ansible not found. Installing..."
sudo apt update
sudo apt upgrade -y
sudo apt install ansible -y
check_ansible_debian
fi
}
check_ansible_fedora() {
if [[ -f /usr/bin/ansible ]]; then
echo "Ansible found. Installing collections and running playbook..."
install_collections
else
echo "Ansible not found. Installing..."
yum install -y dnf-plugins-core
dnf install -y ansible
check_ansible_fedora
fi
}
check_ansible_rocky() {
if [[ -f /usr/bin/ansible ]]; then
echo "Ansible found. Installing collections and running playbook..."
install_collections
else
echo "Ansible not found. Installing..."
yum install -y dnf-plugins-core
dnf config-manager --set-enabled crb
dnf install -y epel-release
dnf install -y ansible
check_ansible_rocky
fi
}
install_collections() {
ansible-galaxy install -r "${PWD:-/home/ubuntu}/requirements.yaml"
ansible-galaxy collection install -r "${PWD:-/home/ubuntu}/requirements.yaml"
#TODO: make ask become pass a flag bc of kubernetes unintended installs
ansible-playbook -i "${PWD:-/home/ubuntu}/local_inventory.yaml" \
"${PWD:-/home/ubuntu}/bootstrap.yaml" --ask-become-pass
}
rundazsh() {
chsh -s /bin/zsh
zsh
}
main() {
printf "${YELLOW}Now bootstrapping the highly opinionated Zoë Environment...${RESTORE}\n"
printf "${BLUE}Detected ${OSTYPE} environment.${RESTORE}\n"
echo ${RED}weeee${YELLOW}eeeee${GREEN}eeeee${BLUE}eeeee${PURPLE}eeeee${RESTORE}
start="$(date +%s)"
check_platform
stop="$(date +%s)"
runtime="$((stop - start))"
echo "${GREEN}Bootstrap was successful and took ${YELLOW}${runtime} ${GREEN}seconds to run.${RESTORE}"
printf "\n"
neofetch
}
main