Skip to content

Commit 724093f

Browse files
authored
Merge pull request #1300 from rackerlabs/shellcheck-20250926
fix(shellcheck): Fixes shellcheck issues
2 parents b2a9d56 + 42f6011 commit 724093f

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

scripts/gen-os-secrets.sh

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,82 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

3-
if [ $# -ne 1 ]; then
3+
# Check arguments
4+
if [ "$#" -ne 1 ]; then
45
echo "$(basename "$0") <output-file>" >&2
56
exit 1
67
fi
78

9+
# Enable safer bash settings
810
set -o pipefail
911

10-
if ! type -p yq > /dev/null; then
12+
# Check dependencies
13+
if ! command -v yq >/dev/null; then
1114
echo "You must have yq installed to use this script" >&2
1215
exit 1
1316
fi
1417

15-
if ! type -p kubectl > /dev/null; then
18+
if ! command -v kubectl >/dev/null; then
1619
echo "You must have kubectl installed to use this script" >&2
1720
exit 1
1821
fi
1922

20-
KUSTOMIZE_VERSION=$(kubectl version --client -o yaml | yq .kustomizeVersion)
21-
if ! (echo -e "v5.0.0\n$KUSTOMIZE_VERSION" | sort -V -C); then
22-
echo "kustomize needs to be at version 5.0.0 or newer (comes with kubectl 1.27+)"
23-
exit 1
23+
# Get kustomize version (declare/assign separately)
24+
KUSTOMIZE_VERSION=""
25+
KUSTOMIZE_VERSION=$(kubectl version --client -o yaml | yq '.kustomizeVersion')
26+
if ! (printf '%s\n' "v5.0.0" "$KUSTOMIZE_VERSION" | sort -V -C); then
27+
echo "kustomize needs to be at version 5.0.0 or newer (comes with kubectl 1.27+)"
28+
exit 1
2429
fi
2530

26-
SCRIPTS_DIR="$(dirname "$0")"
31+
# Scripts directory
32+
SCRIPTS_DIR=""
33+
SCRIPTS_DIR=$(dirname "$0")
2734

2835
echo "This script will attempt to look up the existing values this repo used"
2936
echo "or will generate new values. The output below will be related to that."
3037

3138
# memcache secret key
32-
export MEMCACHE_SECRET_KEY=$("${SCRIPTS_DIR}/pwgen.sh" 64)
39+
MEMCACHE_SECRET_KEY=""
40+
MEMCACHE_SECRET_KEY=$("${SCRIPTS_DIR}/pwgen.sh" 64)
41+
export MEMCACHE_SECRET_KEY
3342

3443
# keystone admin
35-
export KEYSTONE_ADMIN_PASSWORD=$(kubectl -n openstack get secret keystone-admin -o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
44+
KEYSTONE_ADMIN_PASSWORD=""
45+
KEYSTONE_ADMIN_PASSWORD=$(kubectl -n openstack get secret keystone-admin \
46+
-o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
47+
export KEYSTONE_ADMIN_PASSWORD
48+
3649
# keystone mariadb
37-
export KEYSTONE_DB_PASSWORD=$(kubectl -n openstack get secret keystone-db-password -o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
50+
KEYSTONE_DB_PASSWORD=""
51+
KEYSTONE_DB_PASSWORD=$(kubectl -n openstack get secret keystone-db-password \
52+
-o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
53+
export KEYSTONE_DB_PASSWORD
54+
3855
# keystone rabbitmq
39-
export KEYSTONE_RABBITMQ_PASSWORD=$(kubectl -n openstack get secret keystone-rabbitmq-password -o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
56+
KEYSTONE_RABBITMQ_PASSWORD=""
57+
KEYSTONE_RABBITMQ_PASSWORD=$(kubectl -n openstack get secret keystone-rabbitmq-password \
58+
-o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
59+
export KEYSTONE_RABBITMQ_PASSWORD
4060

4161
# ironic keystone service account
42-
export IRONIC_KEYSTONE_PASSWORD=$(kubectl -n openstack get secret ironic-keystone-password -o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
62+
IRONIC_KEYSTONE_PASSWORD=""
63+
IRONIC_KEYSTONE_PASSWORD=$(kubectl -n openstack get secret ironic-keystone-password \
64+
-o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
65+
export IRONIC_KEYSTONE_PASSWORD
66+
4367
# ironic mariadb
44-
export IRONIC_DB_PASSWORD=$(kubectl -n openstack get secret ironic-db-password -o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
68+
IRONIC_DB_PASSWORD=""
69+
IRONIC_DB_PASSWORD=$(kubectl -n openstack get secret ironic-db-password \
70+
-o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
71+
export IRONIC_DB_PASSWORD
72+
4573
# ironic rabbitmq
46-
export IRONIC_RABBITMQ_PASSWORD=$(kubectl -n openstack get secret ironic-rabbitmq-password -o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
74+
IRONIC_RABBITMQ_PASSWORD=""
75+
IRONIC_RABBITMQ_PASSWORD=$(kubectl -n openstack get secret ironic-rabbitmq-password \
76+
-o jsonpath='{.data.password}' | base64 -d || "${SCRIPTS_DIR}/pwgen.sh")
77+
export IRONIC_RABBITMQ_PASSWORD
4778

79+
# Generate output
4880
yq '(.. | select(tag == "!!str")) |= envsubst' \
4981
"${SCRIPTS_DIR}/../components/openstack-secrets.tpl.yaml" \
5082
> "$1"

scripts/gitops-deploy.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ usage() {
1010
template() {
1111
local subvars
1212
subvars="\$DNS_ZONE \$UC_DEPLOY_GIT_URL \$DEPLOY_NAME"
13+
# shellcheck disable=SC2002 # Using cat for clarity with envsubst
1314
cat "$1" | envsubst "${subvars}" > "$2"
1415
}
1516

16-
if [ $# -ne 1 ]; then
17+
if [ "$#" -ne 1 ]; then
1718
usage
1819
fi
1920

20-
SCRIPTS_DIR=$(dirname "$0")
21+
SCRIPTS_DIR="$(dirname "$0")"
2122

2223
if [ ! -f "$1" ]; then
2324
echo "Did not get a file with environment variables." >&2
@@ -43,7 +44,7 @@ if [ ! -d "${UC_DEPLOY}" ]; then
4344
usage
4445
fi
4546

46-
if [ "x${DEPLOY_NAME}" = "x" ]; then
47+
if [ -z "${DEPLOY_NAME}" ]; then
4748
echo "DEPLOY_NAME is not set." >&2
4849
usage
4950
fi
@@ -57,14 +58,16 @@ export DEPLOY_NAME
5758

5859
# create helm-configs directory for values.yaml overrides
5960
mkdir -p "${UC_DEPLOY_HELM_CFG}"
60-
for component in dex; do
61+
62+
# shellcheck disable=SC2043
63+
for component in "dex"; do
6164
helmvals="${UC_DEPLOY_HELM_CFG}/${component}.yaml"
6265
if [ -f "${helmvals}" ]; then
6366
echo "You have ${helmvals} already, not overwriting"
6467
continue
6568
fi
66-
if [ -f "${UC_REPO_COMPONENTS}/${component}/values.tpl.yaml" ]; then
67-
template "${UC_REPO_COMPONENTS}/${component}/values.tpl.yaml" "${helmvals}"
69+
if [ -f "${UC_REPO_COMPONENTS}/${component}/values.tpl.yaml" ]; then
70+
template "${UC_REPO_COMPONENTS}/${component}/values.tpl.yaml" "${helmvals}"
6871
else
6972
echo "# add your values.yaml overrides for the helm chart here" > "${helmvals}"
7073
fi

0 commit comments

Comments
 (0)