-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
93 lines (76 loc) · 2.59 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
90
91
92
93
#!/bin/bash
set -e
ROOT_DIR="$(dirname "$(readlink --canonicalize-existing "$0")")"
readonly ROOT_DIR
readonly ANSIBLE_CONFIG=./ansible.cfg
readonly BOOTSTRAP_DIR="${HOME}/.local/share/dev-bootstrap"
readonly GIT_BRANCH="${GIT_BRANCH:-master}"
readonly GIT_REMOTE_URL="${GIT_REMOTE_URL:-https://github.com/lucastheisen/dev-bootstrap.git}"
readonly LIB_DIR="${BOOTSTRAP_DIR}/lib"
readonly VENV_DIR="${BOOTSTRAP_DIR}/venv"
function initialize_ansible {
if [[ ! -d "${VENV_DIR}" ]]; then
log v "creating ansible venv"
python3 -m venv "${VENV_DIR}"
fi
. "${VENV_DIR}/bin/activate"
log v "installing python dependencies:\n$(sed 's/^/ /' "${LIB_DIR}/requirements.txt")"
pip install --upgrade pip
pip install -r "${LIB_DIR}/requirements.txt"
log v "installing galaxy collections:\n$(sed 's/^/ /' "${LIB_DIR}/requirements.yml")"
ansible-galaxy collection install --requirements-file "${LIB_DIR}/requirements.yml"
}
function log {
local verbosity=$1
local message=$2
if [[ "${LOG_VERBOSITY:-v}" =~ ^${verbosity} ]]; then
>&2 printf "%s [%3s] %s: %b\n" \
"$(date +%H:%M:%S)" \
"${verbosity}" \
"$(caller 0 | awk '{print $2}')" \
"${message}"
fi
}
function run_ansible {
local cmd=(ansible-playbook update.yml "${ansible_args[@]}")
pushd "${LIB_DIR}" > /dev/null
log v "running: $(printf '%q ' "${cmd[@]}" | sed 's/ $//g')"
export ANSIBLE_CONFIG
"${cmd[@]}"
popd > /dev/null
}
function main {
local ansible_args=("$@")
log v "begin bootstrap for ${GIT_BRANCH}"
mkdir --parents "${BOOTSTRAP_DIR}"
log v "installing bootstrap dependencies"
# these are the dependencies for ansible itself and any galaxy modules
# used by ansible. all other packages should be installed by roles
sudo dnf install --assumeyes \
git \
glibc-langpack-en \
procps-ng \
python3 \
python3-pip
log v "download bootstrap"
if [[ "${GIT_BRANCH}" == "unversioned" ]]; then
log v "local dev-bootstrap in ${ROOT_DIR}"
if [[ "${ROOT_DIR}" != "${LIB_DIR}" ]]; then
log vv "copy ${ROOT_DIR} to ${LIB_DIR}"
rm --recursive --force "${LIB_DIR}"
mkdir --parents "${LIB_DIR}"
tar --create --directory "${ROOT_DIR}" . | tar --extract --directory "${LIB_DIR}"
fi
else
log v "fetch dev-bootstrap at ${GIT_BRANCH}"
rm --recursive --force "${LIB_DIR}"
mkdir --parents "${LIB_DIR}"
curl \
--location \
"https://github.com/lucastheisen/dev-bootstrap/archive/${GIT_BRANCH}.tar.gz" \
| tar --extract --gunzip --directory "${LIB_DIR}" --strip-components 1
fi
initialize_ansible
run_ansible
}
main "$@"