Refactor helper script to create a Capsule user (#454)

* chore(hack/create-user.sh): let pick bash interpreter from path

bash interpreter binary could be put at different paths than /bin/bash.

Signed-off-by: maxgio92 <massimiliano.giovagnoli.1992@gmail.com>

* refactor(hack/create-user.sh): add helper function to apply dry

add helper function to check commands existence.

Signed-off-by: maxgio92 <massimiliano.giovagnoli.1992@gmail.com>
This commit is contained in:
maxgio
2021-10-22 20:55:52 +02:00
committed by GitHub
parent 0784dc7177
commit e0d5e6feb2

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# This script uses Kubernetes CertificateSigningRequest (CSR) to generate a
# certificate signed by the Kubernetes CA itself.
@@ -10,23 +10,18 @@
# Exit immediately if a command exits with a non-zero status.
set -e
# Check if OpenSSL is installed
if [[ ! -x "$(command -v openssl)" ]]; then
echo "Error: openssl not found"
exit 1
fi
function check_command() {
local command=$1
# Check if kubectl is installed
if [[ ! -x "$(command -v kubectl)" ]]; then
echo "Error: kubectl not found"
exit 1
fi
if ! command -v $command &> /dev/null; then
echo "Error: ${command} not found"
exit 1
fi
}
# Check if jq is installed
if [[ ! -x "$(command -v jq)" ]]; then
echo "Error: jq not found"
exit 1
fi
check_command openssl
check_command kubectl
check_command jq
USER=$1
TENANT=$2