-
Notifications
You must be signed in to change notification settings - Fork 0
/
wizard.sh
executable file
·32 lines (26 loc) · 1.06 KB
/
wizard.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
#!/usr/bin/env bash
# Unofficial bash strict mode: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
GIT_ROOT=$(git rev-parse --show-toplevel)
MOD_NAME="$(git remote -v | grep origin | awk '{printf $2}' | sed -nr 's~.*/terraform-aws-([^\.]+)\.git~\1~p')"
MOD_SHORTNAME="$(echo "$MOD_NAME" | sed -nr 's~(.*)-module~\1~p' | tr -d '[:space:]')"
MOD_TITLE="${MOD_NAME//-/ }"
declare -A REPLACEMENT_KEYS=(
["MOD_NAME"]="$MOD_NAME"
["MOD_TITLE"]="$MOD_TITLE"
["MOD_SHORTNAME"]="$MOD_SHORTNAME"
)
pushd "$GIT_ROOT" >/dev/null
BOILERPLATE_FILES=$(fd -tf -E wizard.sh -c never .)
for BOILERPLATE_FILE in $BOILERPLATE_FILES; do
for REPLACEMENT_KEY in "${!REPLACEMENT_KEYS[@]}"; do
if command -v sd >/dev/null; then
sd "$REPLACEMENT_KEY" "${REPLACEMENT_KEYS[$REPLACEMENT_KEY]}" "$BOILERPLATE_FILE"
else
tmp="$(mktemp)"
sed "s/$REPLACEMENT_KEY/${REPLACEMENT_KEYS[$REPLACEMENT_KEY]}/g" "$BOILERPLATE_FILE" >"$tmp"
mv "$tmp" "$BOILERPLATE_FILE"
fi
done
done