-
Notifications
You must be signed in to change notification settings - Fork 0
/
hatcher.bash
executable file
·97 lines (88 loc) · 2.1 KB
/
hatcher.bash
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
#!/usr/bin/env bash
set -e
# [[ -L ../common ]] || ( echo "no symbolic link ../common exist" && exit 111 )
function initializer(){
readonly -A PLACEHOLDERS=(
[regular_chartname]=`echo $2 | gsed -r 's/(-|_)(\w)/\U\2/g'`
[hatcher]=${1^^}
[starter]=${1}
[startername]=${1^}
[port_name]=app
)
cat << EOF > .gitignore
/charts/
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
EOF
cd ..
helm create -p ${STARTERNAME} ${CHARTNAME}
cd -
cat << EOF >> Chart.yaml
dependencies:
- name: common
repository: oci://registry-1.docker.io/bitnamicharts
# repository: file://../common
# tags:
# - bitnami-common
version: 2.x.x
EOF
for pkey in ${!PLACEHOLDERS[@]};do
find . \( \( -type d -name ".git" -prune \) -o -type f \) -not -name ".git" -exec \
gsed -i'' -e "s#<PLACEHOLDER_${pkey^^}>#${PLACEHOLDERS[${pkey}]}#g" {} \;
done
}
usage() {
cat << EOF
initialize helm charts from starter charts within a git repository.
Available Commands:
helm hatcher init STARTERNAME Initialize chart from starter chart STARTERNAME within a git repository.
--help Display this text
EOF
}
# Create the passthru array
PASSTHRU=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--help)
HELP=TRUE
shift
;;
*)
PASSTHRU+=("$1")
shift
;;
esac
done
# Restore PASSTHRU parameters
set -- "${PASSTHRU[@]}"
# Show help if flagged
if [[ "$HELP" == "TRUE" ]]; then
usage
exit 0
fi
# COMMAND must be either 'init', 'init', or 'init'
COMMAND=${PASSTHRU[0]}
case "$COMMAND" in
"init")
STARTERNAME=${PASSTHRU[1]}
CHARTNAME=`basename $(pwd)`
git branch -a || exit 11
[[ 0 -eq `git branch -a | wc -l` ]] || exit 17
# git switch --create master
initializer ${STARTERNAME} ${CHARTNAME}
helm dependency build
git add .
git commit -m "initialize chart"
exit 0
;;
*)
echo "Error: Invalid command."
usage
exit 1
;;
esac