-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·135 lines (111 loc) · 4.27 KB
/
init.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
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
#! /usr/bin/env bash
set -o posix
set -o nounset
set -o errexit
set -o pipefail
################################################################################
#
# Variables
#
################################################################################
source ./variables.env
#
# Some Colors for logging
#
BOLD="$(tput bold)"
RESET="$(tput sgr0)"
RED="$(tput setaf 160)" # HEX color: #e31414
YELLOW="$(tput setaf 178)" # HEX color: #c9ad0a
BLUE="$(tput setaf 033)" # HEX color: #0a99fc
################################################################################
#
# Helper functions
#
################################################################################
info() { echo -e "${BLUE}> [INFO]${RESET} $*"; }
info_wait() { echo -e -n "${BLUE}> [INFO]${RESET} $* ..."; }
info_done() { echo -e "${BLUE} [${1:-DONE}]${RESET}"; }
warn() { echo -e "${YELLOW}! [WARN] $*${RESET}"; }
error() { echo -e "${RED}X [ERROR] 🚨 $* 🚨${RESET}"; }
error_done() { echo -e "${RED} [$1]${RESET}"; }
errexit() { error "$*"; exit 1; }
install_requirements() {
if command -v pacman; then
info "Installing requirements using pacman ..."
sudo pacman -S sshpass
else
error "Cannot install requirements, cause I don't know your package manager :("
warn "Some roles or hosts may not work ..."
fi
}
get_ansible_playbook() {
if [ ! -d "$ANSIBLE_PLAYBOOK_PATH" ]; then
info "Cloning Ansible playbook skeleton repo to ${BOLD}${ANSIBLE_PLAYBOOK_PATH}${RESET} ..."
git clone "$ANSIBLE_PLAYBOOK_REPO" "$ANSIBLE_PLAYBOOK_PATH"
else
info "Folder for the ${BOLD}Ansible playbook skeleton repo${RESET} already present. ${YELLOW}Skipping!${RESET}"
fi
}
get_ansible_roles() {
if [ ! -d "$ANSIBLE_ROLES_PATH" ]; then
info "Cloning Ansible roles repo to ${BOLD}${ANSIBLE_ROLES_PATH}${RESET} ..."
git clone "$ANSIBLE_ROLES_REPO" "$ANSIBLE_ROLES_PATH"
else
info "Folder for the ${BOLD}Ansible roles repo${RESET} already present. ${YELLOW}Skipping!${RESET}"
fi
}
get_ansible_config() {
if [ ! -d "$ANSIBLE_CONFIG_PATH" ]; then
info "Cloning Ansible config repo to ${BOLD}${ANSIBLE_CONFIG_PATH}${RESET} ..."
git clone "$ANSIBLE_CONFIG_REPO" "$ANSIBLE_CONFIG_PATH"
else
info "Folder for the ${BOLD}Ansible config repo${RESET} already present. ${YELLOW}Skipping!${RESET}"
fi
}
setup_ansible_cfg() {
if [ ! -e "${ANSIBLE_PLAYBOOK_PATH}/ansible.cfg" ]; then
info "Configuring ansible.cfg file ..."
cp "${ANSIBLE_PLAYBOOK_PATH}/ansible.cfg.default" "${ANSIBLE_PLAYBOOK_PATH}/ansible.cfg"
sed --in-place --regexp-extended "s|inventory =.*|inventory = ${ANSIBLE_CONFIG_PATH}/inventory.yml|g" "${ANSIBLE_PLAYBOOK_PATH}/ansible.cfg"
sed --in-place --regexp-extended "s|roles_path =.*|roles_path = ${ANSIBLE_ROLES_PATH}|g" "${ANSIBLE_PLAYBOOK_PATH}/ansible.cfg"
chmod u=r,g=r,o= "${ANSIBLE_PLAYBOOK_PATH}/ansible.cfg"
else
info "The configuration file ${BOLD}${ANSIBLE_PLAYBOOK_PATH}/ansible.cfg${RESET} is already present. ${YELLOW}Skipping!${RESET}"
fi
}
get_public_dotfiles() {
if [ -n "$PUBLIC_DOTFILES_REPO" ]; then
if [ ! -d "$PUBLIC_DOTFILES_PATH" ]; then
info "Cloning public dotfiles repo to ${BOLD}${PUBLIC_DOTFILES_PATH}${RESET} ..."
git clone "$PUBLIC_DOTFILES_REPO" "$PUBLIC_DOTFILES_PATH"
else
info "Folder for the ${BOLD}public dotfiles repo${RESET} already present. ${YELLOW}Skipping!${RESET}"
fi
else
info "No ${BOLD}public dotfiles repo${RESET} set. ${YELLOW}Skipping!${RESET}"
fi
}
get_dockerfiles() {
if [ -n "$DOCKERFILES_REPO" ]; then
if [ ! -d "$DOCKERFILES_PATH" ]; then
info "Cloning Dockerfiles repo to ${BOLD}${DOCKERFILES_PATH}${RESET} ..."
git clone "$DOCKERFILES_REPO" "$DOCKERFILES_PATH"
else
info "Folder for the ${BOLD}Dockerfiles repo${RESET} already present. ${YELLOW}Skipping!${RESET}"
fi
else
info "No ${BOLD}Dockerfiles repo${RESET} set. ${YELLOW}Skipping!${RESET}"
fi
}
################################################################################
#
# ----- MAIN -----
#
################################################################################
install_requirements
get_ansible_playbook
get_ansible_roles
get_ansible_config
get_public_dotfiles
get_dockerfiles
setup_ansible_cfg