forked from salesforce/helm-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
starter.sh
executable file
·82 lines (72 loc) · 2.05 KB
/
starter.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
#!/bin/bash
# Copyright (c) 2018, salesforce.com, inc.
# All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
set -e
usage() {
cat << EOF
Fetch, list, and delete helm starters from github.
Available Commands:
helm starter fetch GITURL Install a bare Helm starter from Github (e.g git clone)
helm starter list List installed Helm starters
helm starter update NAME Refresh an installed Helm starter
helm starter delete NAME Delete an installed Helm starter
helm starter inspect NAME Print out a starter's readme
--help Display this text
EOF
}
# Create the passthru array
PASSTHRU=()
while [[ $# -gt 0 ]]
do
key="$1"
# Parse arguments
case $key in
--help)
HELP=TRUE
shift # past argument
;;
*) # unknown option
PASSTHRU+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
# Restore PASSTHRU parameters
set -- "${PASSTHRU[@]}"
# Show help if flagged
if [ "$HELP" == "TRUE" ]; then
usage
exit 0
fi
# COMMAND must be either 'fetch', 'list', or 'delete'
COMMAND=${PASSTHRU[0]}
# Create the /starters directory, if needed
mkdir -p ${HELM_DATA_HOME}/starters
if [ "$COMMAND" == "fetch" ]; then
REPO=${PASSTHRU[1]}
cd ${HELM_DATA_HOME}/starters
git clone ${REPO} --quiet
exit 0
elif [ "$COMMAND" == "update" ]; then
STARTER=${PASSTHRU[1]}
cd ${HELM_DATA_HOME}/starters/${STARTER}
git pull origin $(git rev-parse --abbrev-ref HEAD) --quiet
exit 0
elif [ "$COMMAND" == "list" ]; then
ls -A1 ${HELM_DATA_HOME}/starters
exit 0
elif [ "$COMMAND" == "delete" ]; then
STARTER=${PASSTHRU[1]}
rm -rf ${HELM_DATA_HOME}/starters/${STARTER}
exit 0
elif [ "$COMMAND" == "inspect" ]; then
STARTER=${PASSTHRU[1]}
find ${HELM_DATA_HOME}/starters/${STARTER} -type f -iname "*readme*" -exec cat {} \;
exit 0
else
echo "Error: Invalid command."
usage
exit 1
fi