-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfixup-examples.sh
More file actions
executable file
·45 lines (43 loc) · 1.29 KB
/
fixup-examples.sh
File metadata and controls
executable file
·45 lines (43 loc) · 1.29 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
#!/bin/bash
set -euo pipefail
: "${ROOT_DIR:=$(pwd)}"
source "$ROOT_DIR"/tests/common.sh
MODE="${1:-}"
: "${FIXUP_GIT_MODE:=false}"
if [[ "$MODE" != "remote" && "$MODE" != "local" ]]; then
echo "Usage: $0 {remote|local}"
exit 1
fi
LOCAL_BASE='"../../"'
REMOTE_BASE='"hpcugent/opennebula/vsc"'
LOCAL_ROUTER_BASE='"../../modules/router"'
REMOTE_ROUTER_BASE='"hpcugent/opennebula/vsc//modules/router"'
VERSION='0.0.3'
find "$ROOT_DIR/examples" \
-type d -name '.terraform' -prune -o \
-type f -name 'main.tf' -print0 |
while IFS= read -r -d '' file; do
if [[ "$MODE" == "remote" ]]; then
sed -i \
-e "s|$LOCAL_BASE|$REMOTE_BASE|g" \
-e "s|$LOCAL_ROUTER_BASE|$REMOTE_ROUTER_BASE|g" \
-e "s|^[[:space:]]*#\s*version.*$| version = \"$VERSION\"|" \
"$file"
tofu fmt -list=false "$file"
info "Updated: $file"
if $FIXUP_GIT_MODE;then
git add "$file"
fi
elif ! grep -q "# version" "$file"; then
sed -i \
-e "s|$REMOTE_BASE|$LOCAL_BASE|g" \
-e "s|$REMOTE_ROUTER_BASE|$LOCAL_ROUTER_BASE|g" \
-e "s|version *=|# version = |g" \
"$file"
tofu fmt -list=false "$file"
info "Updated: $file"
if $FIXUP_GIT_MODE ;then
git add "$file"
fi
fi
done