-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·59 lines (51 loc) · 1.92 KB
/
update.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
#!/usr/bin/env bash
main() {
setup $@
templates_push
}
setup() {
SCRIPT_PATH=$(readlink -f "${BASH_SOURCE:-$0}")
BASE_DIR=$(dirname "${SCRIPT_PATH}")
TEMPLATES=$(find "${BASE_DIR}" -maxdepth 2 -name "main.tf" | awk -F'/' '{print $(NF-1)}')
TIMESTAMP=$(date '+%Y%m%d%H%M%S')
[ -n "${1}" ] && TEMPLATES=${1}
}
templates_push() {
for template in ${TEMPLATES}; do
banner "Updating ${template}"
if [[ "${CODER_TEMPLATES}" == *"${template}"* ]]; then
coder template push --yes --activate --name "${TIMESTAMP}" --directory "${BASE_DIR}/${template}" ${template}
templates_edit ${template}
templates_archive ${template}
else
echo "Skipping since not in CODER_TEMPLATES environmental variables..."
fi
done
}
templates_edit() {
subbanner "Updating Settings"
args=()
if [[ -f "${BASE_DIR}/${1}/README.md" ]]; then
display_name=$(awk -F': ' '/^display_name: / {print $2}' "${BASE_DIR}/${1}/README.md")
description=$(awk -F': ' '/^description: / {print $2}' "${BASE_DIR}/${1}/README.md")
default_ttl=$(awk -F': ' '/^default_ttl: / {print $2}' "${BASE_DIR}/${1}/README.md")
icon=$(awk -F': ' '/^icon: / {print $2}' "${BASE_DIR}/${1}/README.md")
fi
[[ -n "${display_name}" ]] && args+=("--display-name" "${display_name}")
[[ -n "${description}" ]] && args+=("--description" "${description}")
[[ -n "${default_ttl}" ]] && args+=("--default-ttl" "${default_ttl}")
[[ -n "${icon}" ]] && args+=("--icon" "${icon}")
echo coder template edit "${args[@]}" "${1}"
coder template edit "${args[@]}" "${1}"
unset display_name description default_ttl icon
}
templates_archive() {
coder template versions list --column 'Name,Created At,Active' "${1}" | grep -Eiv "Active\s*$" | awk '{print $1}' | xargs -I '{}' coder template versions archive "${1}" '{}'
}
banner() {
echo "==================== ${1} ===================="
}
subbanner() {
echo "---------- ${1} ----------"
}
main $@