1
- PASS_LEN=${PASS_LEN:- xxx}
2
- SCRIPT_NAME=$( basename " $0 " )
3
- ARGS=" $* "
1
+ PASS_LEN=" ${PASS_LEN:- xxx} "
4
2
SEAL_CMD=" /usr/bin/env kubeseal --controller-namespace sealed-secrets -o yaml --allow-empty-data --scope xxx"
5
3
TMP_FILE=/tmp/sealedsecret.yaml
6
4
7
5
while getopts " h?pi:" opt; do
8
- case " $opt " in
6
+ case " ${ opt} " in
9
7
h|\? )
10
8
echo ' +------------------------------------HELP------------------------------------+'
11
9
echo ' | This script can generate a SealedSecret from a given Secret. |'
@@ -18,52 +16,52 @@ while getopts "h?pi:" opt; do
18
16
;;
19
17
p)
20
18
# shellcheck disable=SC2181
21
- password=$( export LC_CTYPE=C; false ; while [ $? -ne 0 ]; do tr -dc A-Za-z0-9 < /dev/urandom | \
22
- head -c " $PASS_LEN " ; done)
19
+ password=$( export LC_CTYPE=C; false ; while [ " ${?} " -ne 0 ]; do \
20
+ tr -dc A-Za-z0-9 < /dev/urandom | head -c " ${ PASS_LEN} " ; done)
23
21
;;
24
- i) input_file=$ OPTARG
22
+ i) input_file=" ${ OPTARG} "
25
23
;;
26
24
esac
27
25
done
28
26
29
27
shift $(( OPTIND- 1 ))
30
28
[ " ${1:- } " = " --" ] && shift
31
29
32
- if [ -n " $1 " ]; then
33
- echo " Unknown argument: $1 " >&2
30
+ if [ -n " ${1} " ]; then
31
+ echo " Unknown argument: ${1} " >&2
34
32
exit 2
35
33
fi
36
34
37
- if [ -z " $input_file " ]; then
35
+ if [ -z " ${ input_file} " ]; then
38
36
echo " Required argument is missing: -i <file containing a Kubernetes Secret>." >&2
39
37
exit 2
40
38
fi
41
39
42
- if [ ! -f " $input_file " ]; then
43
- echo " File not found: $input_file ." >&2
40
+ if [ ! -f " ${ input_file} " ]; then
41
+ echo " File not found: ${ input_file} ." >&2
44
42
exit 1
45
43
fi
46
44
47
- input=$( yq ' del(.metadata.namespace)' " $input_file " | sed ' / null$/d' )
48
- echo " $input " | $SEAL_CMD > $ TMP_FILE
49
- name=$( yq ' .metadata.name' " $input_file " )
45
+ input=$( yq ' del(.metadata.namespace)' " ${ input_file} " | sed ' / null$/d' )
46
+ echo " ${ input} " | ${ SEAL_CMD} > " ${ TMP_FILE} "
47
+ name=$( yq ' .metadata.name' " ${ input_file} " )
50
48
51
- if [ -n " $password " ]; then
52
- echo -n " $password " | kubectl create secret generic " $name " \
49
+ if [ -n " ${ password} " ]; then
50
+ echo -n " ${ password} " | kubectl create secret generic " ${ name} " \
53
51
--dry-run=client --from-file=password=/dev/stdin -o yaml | \
54
- $SEAL_CMD --merge-into $ TMP_FILE
52
+ ${ SEAL_CMD} --merge-into " ${ TMP_FILE} "
55
53
fi
56
54
57
- result=$( sed ' / null$/d' $ TMP_FILE)
58
- rm -f $ TMP_FILE
55
+ result=$( sed ' / null$/d' " ${ TMP_FILE} " )
56
+ rm -f " ${ TMP_FILE} "
59
57
60
58
echo " # Input:"
61
59
echo " # ---"
62
60
# shellcheck disable=SC2001
63
- echo " $input " | sed ' s/^/# /g'
61
+ echo " ${ input} " | sed ' s/^/# /g'
64
62
echo
65
63
66
64
echo " # Result:"
67
65
echo ---
68
- echo " $result " | yq ' del(.spec.template)'
66
+ echo " ${ result} " | yq ' del(.spec.template)'
69
67
echo
0 commit comments