From cd709826c9abd51887b5f496af0b585455b28a7c Mon Sep 17 00:00:00 2001
From: Max Leonard Inden <IndenML@gmail.com>
Date: Mon, 18 Jun 2018 23:00:48 +0200
Subject: [PATCH] format: Introduce shellcheck [1] for shell script analysis

[1] https://github.com/koalaman/shellcheck
---
 Makefile                                    | 5 +----
 README.md                                   | 2 +-
 build.sh                                    | 2 +-
 experimental/custom-metrics-api/gencerts.sh | 9 +++++----
 test.sh                                     | 7 ++++---
 5 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile
index bab98bcb..74ccee14 100644
--- a/Makefile
+++ b/Makefile
@@ -3,8 +3,6 @@ JSONNET_FMT := jsonnet fmt -n 2 --max-blank-lines 2 --string-style s --comment-s
 JB_BINARY:=$(GOPATH)/bin/jb
 EMBEDMD_BINARY:=$(GOPATH)/bin/embedmd
 
-# edit 1
-
 all: generate fmt test
 
 ../../hack/jsonnet-docker-image: ../../scripts/jsonnet/Dockerfile
@@ -26,10 +24,9 @@ generate-in-docker: ../../hack/jsonnet-docker-image
 generate: manifests **.md
 
 **.md: $(EMBEDMD_BINARY) $(shell find examples) build.sh example.jsonnet
-	echo '>>> inside **.md'
 	$(EMBEDMD_BINARY) -w `find . -name "*.md" | grep -v vendor`
 
-manifests: vendor example.jsonnet
+manifests: vendor example.jsonnet build.sh
 	rm -rf manifests
 	./build.sh
 
diff --git a/README.md b/README.md
index 5b2141c8..bf61d9ae 100644
--- a/README.md
+++ b/README.md
@@ -112,7 +112,7 @@ rm -rf manifests
 mkdir manifests
 
                                                # optional, but we would like to generate yaml, not json
-jsonnet -J vendor -m manifests ${1-example.jsonnet} | xargs -I{} sh -c 'cat $1 | gojsontoyaml > $1.yaml; rm -f $1' -- {}
+jsonnet -J vendor -m manifests "${1-example.jsonnet}" | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml; rm -f {}' -- {}
 
 ```
 
diff --git a/build.sh b/build.sh
index 6037c3db..4eaf5ac5 100755
--- a/build.sh
+++ b/build.sh
@@ -9,5 +9,5 @@ rm -rf manifests
 mkdir manifests
 
                                                # optional, but we would like to generate yaml, not json
-jsonnet -J vendor -m manifests ${1-example.jsonnet} | xargs -I{} sh -c 'cat $1 | gojsontoyaml > $1.yaml; rm -f $1' -- {}
+jsonnet -J vendor -m manifests "${1-example.jsonnet}" | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml; rm -f {}' -- {}
 
diff --git a/experimental/custom-metrics-api/gencerts.sh b/experimental/custom-metrics-api/gencerts.sh
index 7cd8af93..b1e16031 100755
--- a/experimental/custom-metrics-api/gencerts.sh
+++ b/experimental/custom-metrics-api/gencerts.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 # Detect if we are on mac or should use GNU base64 options
-case `uname` in
+case $(uname) in
         Darwin)
             b64_opts='-b=0'
             ;; 
@@ -17,7 +17,8 @@ echo '{"signing":{"default":{"expiry":"43800h","usages":["signing","key encipher
 
 export SERVICE_NAME=custom-metrics-apiserver
 export ALT_NAMES='"custom-metrics-apiserver.monitoring","custom-metrics-apiserver.monitoring.svc"'
-echo '{"CN":"'${SERVICE_NAME}'","hosts":['${ALT_NAMES}'],"key":{"algo":"rsa","size":2048}}' | cfssl gencert -ca=metrics-ca.crt -ca-key=metrics-ca.key -config=metrics-ca-config.json - | cfssljson -bare apiserver
+echo "{\"CN\":\"${SERVICE_NAME}\", \"hosts\": [${ALT_NAMES}], \"key\": {\"algo\": \"rsa\",\"size\": 2048}}" | \
+       	cfssl gencert -ca=metrics-ca.crt -ca-key=metrics-ca.key -config=metrics-ca-config.json - | cfssljson -bare apiserver
 
 cat <<-EOF > cm-adapter-serving-certs.yaml
 apiVersion: v1
@@ -25,6 +26,6 @@ kind: Secret
 metadata:
   name: cm-adapter-serving-certs
 data:
-  serving.crt: $(cat apiserver.pem | base64 ${b64_opts})
-  serving.key: $(cat apiserver-key.pem | base64 ${b64_opts})
+  serving.crt: $(base64 ${b64_opts} < apiserver.pem)
+  serving.key: $(base64 ${b64_opts} < apiserver-key.pem)
 EOF
diff --git a/test.sh b/test.sh
index dad4e75f..cfdf584c 100755
--- a/test.sh
+++ b/test.sh
@@ -8,7 +8,8 @@ for i in examples/jsonnet-snippets/*.jsonnet; do
     [ -f "$i" ] || break
     echo "Testing: ${i}"
     echo ""
-    snippet="local kp = $(<${i});
+    fileContent=$(<"$i")
+    snippet="local kp = $fileContent;
 
 $(<examples/jsonnet-build-snippet/build-snippet.jsonnet)"
     echo "${snippet}" > "test.jsonnet"
@@ -25,8 +26,8 @@ for i in examples/*.jsonnet; do
     echo "Testing: ${i}"
     echo ""
     echo "\`\`\`"
-    echo "$(<${i})"
+    cat "${i}"
     echo "\`\`\`"
     echo ""
-    jsonnet -J vendor ${i} > /dev/null
+    jsonnet -J vendor "${i}" > /dev/null
 done
-- 
GitLab