Skip to content

Commit

Permalink
Address shellcheck warnings (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Sep 16, 2024
1 parent 4fba373 commit be87492
Show file tree
Hide file tree
Showing 56 changed files with 209 additions and 154 deletions.
4 changes: 2 additions & 2 deletions .evergreen/atlas/atlas-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ create_deployment ()

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in ${VARLIST[*]}; do
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

Expand Down Expand Up @@ -54,7 +54,7 @@ check_deployment ()

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in ${VARLIST[*]}; do
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

Expand Down
6 changes: 4 additions & 2 deletions .evergreen/atlas/setup-atlas-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fi

# Backwards compatibility: map old names to new names.
if [ -n "${LAMBDA_STACK_NAME:-}" ]; then
# shellcheck disable=SC2034
CLUSTER_PREFIX=$LAMBDA_STACK_NAME
fi
if [ -n "${DRIVERS_ATLAS_LAMBDA_USER:-}" ]; then
Expand All @@ -57,7 +58,7 @@ CLUSTER_PREFIX

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in ${VARLIST[*]}; do
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

Expand All @@ -71,7 +72,7 @@ done
export VERSION="${MONGODB_VERSION:-6.0}"

# Set the create cluster configuration.
export DEPLOYMENT_DATA=$(cat <<EOF
DEPLOYMENT_DATA=$(cat <<EOF
{
"autoScaling" : {
"autoIndexingEnabled" : false,
Expand Down Expand Up @@ -116,6 +117,7 @@ export DEPLOYMENT_DATA=$(cat <<EOF
}
EOF
)
export DEPLOYMENT_DATA

export ATLAS_PUBLIC_API_KEY=$DRIVERS_ATLAS_PUBLIC_API_KEY
export ATLAS_PRIVATE_API_KEY=$DRIVERS_ATLAS_PRIVATE_API_KEY
Expand Down
3 changes: 3 additions & 0 deletions .evergreen/atlas/setup-variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ set -eu

# The base Atlas API url. We use the API directly as the CLI does not yet
# support testing cluster outages.
# shellcheck disable=SC2034
DEFAULT_URL="https://cloud.mongodb.com/api/atlas/v1.0"
# shellcheck disable=SC2034
ATLAS_BASE_URL="${DRIVERS_ATLAS_BASE_URL:-$DEFAULT_URL}"

# Create a unique atlas project name.
suffix=$(node -e "process.stdout.write(require('crypto').randomBytes(32).toString('hex').slice(0,16))")
# shellcheck disable=SC2034
CLUSTER_NAME="${CLUSTER_PREFIX}-${suffix}"
2 changes: 1 addition & 1 deletion .evergreen/atlas/teardown-atlas-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fi

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in ${VARLIST[*]}; do
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

Expand Down
2 changes: 1 addition & 1 deletion .evergreen/auth_aws/lib/ecs_hosted_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -ex

# The environment variable is always set during interactive logins
# But for non-interactive logs, ~/.bashrc does not appear to be read on Ubuntu but it works on Fedora
[[ -z "${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}" ]] && export $(strings /proc/1/environ | grep AWS_CONTAINER_CREDENTIALS_RELATIVE_URI)
[[ -z "${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}" ]] && export "$(strings /proc/1/environ | grep AWS_CONTAINER_CREDENTIALS_RELATIVE_URI)"

env

Expand Down
1 change: 1 addition & 0 deletions .evergreen/auth_oidc/azure/create-and-setup-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pushd ..
. ./activate-authoidcvenv.sh
popd
python ./handle_secrets.py
# shellcheck source=env.sh
source $AZUREOIDC_ENVPATH

# Create VM.
Expand Down
1 change: 1 addition & 0 deletions .evergreen/auth_oidc/azure/run-driver-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export AZUREKMS_PRIVATEKEYPATH=$SCRIPT_DIR/keyfile

# Set up the remote driver checkout.
DRIVER_TARFILE_BASE=$(basename ${AZUREOIDC_DRIVERS_TAR_FILE})
# shellcheck disable=SC2088
AZUREKMS_SRC=${AZUREOIDC_DRIVERS_TAR_FILE} \
AZUREKMS_DST="~/" \
$SCRIPT_DIR/../../csfle/azurekms/copy-file.sh
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/auth_oidc/azure_func/invoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if [ -z "$MONGODB_URI" ]; then
fi

CODE=$(az functionapp function keys list -g $AZUREOIDC_FUNC_RESOURCE_GROUP -n $FUNC_APP_NAME --function-name $FUNC_NAME | jq -r '.default')
URL=https://$FUNC_APP_NAME.azurewebsites.net/api/$FUNC_NAME?code=$CODE
URL="https://$FUNC_APP_NAME.azurewebsites.net/api/$FUNC_NAME?code=$CODE"
DATA="{\"MONGODB_URI\": \"$MONGODB_URI\" }"
curl -i \
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/auth_oidc/azure_func/run-driver-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ MONGODB_URI

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in ${VARLIST[*]}; do
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

Expand Down
6 changes: 4 additions & 2 deletions .evergreen/auth_oidc/azure_func/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DEPLOYMENT_NAME="$RANDOM-DRIVERGCP"
echo "export CLUSTER_NAME=$DEPLOYMENT_NAME" >> "secrets-export.sh"

# Set the create cluster configuration.
export DEPLOYMENT_DATA=$(cat <<EOF
DEPLOYMENT_DATA=$(cat <<EOF
{
"autoScaling" : {
"autoIndexingEnabled" : false,
Expand Down Expand Up @@ -80,6 +80,7 @@ export DEPLOYMENT_DATA=$(cat <<EOF
}
EOF
)
export DEPLOYMENT_DATA

export ATLAS_PUBLIC_API_KEY=$OIDC_ATLAS_PUBLIC_API_KEY
export ATLAS_PRIVATE_API_KEY=$OIDC_ATLAS_PRIVATE_API_KEY
Expand All @@ -102,7 +103,8 @@ fi

########################
# Wait for the Atlas Cluster
export MONGODB_URI=$(check_deployment)
MONGODB_URI=$(check_deployment)
export MONGODB_URI
echo "export MONGODB_URI=$MONGODB_URI" >> ./secrets-export.sh

popd
20 changes: 12 additions & 8 deletions .evergreen/auth_oidc/gcp/setup-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ set -o errexit # Exit on first command error.
SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
. $SCRIPT_DIR/../../handle-paths.sh

if [ -z "$GCPKMS_GCLOUD" -o -z "$GCPKMS_PROJECT" -o -z "$GCPKMS_ZONE" -o -z "$GCPKMS_INSTANCENAME" ]; then
echo "Please set the following required environment variables"
echo " GCPKMS_GCLOUD to the path of the gcloud binary"
echo " GCPKMS_PROJECT to the GCP project"
echo " GCPKMS_ZONE to the GCP zone"
echo " GCPKMS_INSTANCENAME to the GCE instance name"
exit 1
fi
VARLIST=(
GCPKMS_GCLOUD
GCPKMS_PROJECT
GCPKMS_ZONE
GCPKMS_INSTANCENAME
)

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

echo "Copying setup-gce-instance.sh to GCE instance ($GCPKMS_INSTANCENAME) ... begin"
# Copy files to test. Use "-p" to preserve execute mode.
Expand Down
3 changes: 2 additions & 1 deletion .evergreen/auth_oidc/gcp/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DEPLOYMENT_NAME="$RANDOM-DRIVERGCP"
echo "export CLUSTER_NAME=$DEPLOYMENT_NAME" >> "$DRIVERS_TOOLS/.evergreen/atlas/secrets-export.sh"

# Set the create cluster configuration.
export DEPLOYMENT_DATA=$(cat <<EOF
DEPLOYMENT_DATA=$(cat <<EOF
{
"autoScaling" : {
"autoIndexingEnabled" : false,
Expand Down Expand Up @@ -67,6 +67,7 @@ export DEPLOYMENT_DATA=$(cat <<EOF
}
EOF
)
export DEPLOYMENT_DATA

export ATLAS_PUBLIC_API_KEY=$OIDC_ATLAS_PUBLIC_API_KEY
export ATLAS_PRIVATE_API_KEY=$OIDC_ATLAS_PRIVATE_API_KEY
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/auth_oidc/k8s/remote-scripts/run-self-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pip install -U -q pip pymongo
echo "Installing dependencies ... end"

# Run the Python Driver Self Test
SCRIPT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
SCRIPT_DIR=$(realpath "$(dirname ${BASH_SOURCE[0]})")
pushd $SCRIPT_DIR
source secrets-export.sh
python test.py
2 changes: 1 addition & 1 deletion .evergreen/auth_oidc/k8s/remote-scripts/start-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

# Start an OIDC-enabled server.
SCRIPT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
SCRIPT_DIR=$(realpath "$(dirname ${BASH_SOURCE[0]})")
cd $SCRIPT_DIR
source secrets-export.sh

Expand Down
6 changes: 6 additions & 0 deletions .evergreen/auth_oidc/k8s/run-driver-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ K8S_DRIVERS_TAR_FILE
K8S_TEST_CMD
)

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

source secrets-export.sh
source $K8S_VARIANT_DIR/secrets-export.sh

Expand Down
3 changes: 2 additions & 1 deletion .evergreen/auth_oidc/k8s/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ DEPLOYMENT_NAME="$RANDOM-DRIVER-K8S"
echo "export CLUSTER_NAME=$DEPLOYMENT_NAME" >> "$DRIVERS_TOOLS/.evergreen/atlas/secrets-export.sh"

# Set the create cluster configuration.
export DEPLOYMENT_DATA=$(cat <<EOF
DEPLOYMENT_DATA=$(cat <<EOF
{
"autoScaling" : {
"autoIndexingEnabled" : false,
Expand Down Expand Up @@ -82,6 +82,7 @@ export DEPLOYMENT_DATA=$(cat <<EOF
}
EOF
)
export DEPLOYMENT_DATA

export ATLAS_PUBLIC_API_KEY=$OIDC_ATLAS_PUBLIC_API_KEY
export ATLAS_PRIVATE_API_KEY=$OIDC_ATLAS_PRIVATE_API_KEY
Expand Down
5 changes: 3 additions & 2 deletions .evergreen/auth_oidc/oidc_get_tokens.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
. $SCRIPT_DIR/../handle-paths.sh

if [ -z "${OIDC_TOKEN_DIR:-}" ]; then
export OIDC_TOKEN_DIR=/tmp/tokens
OIDC_TOKEN_DIR=/tmp/tokens
fi
if [ "Windows_NT" = "${OS:-}" ]; then
export OIDC_TOKEN_DIR=$(cygpath -m $OIDC_TOKEN_DIR)
OIDC_TOKEN_DIR=$(cygpath -m $OIDC_TOKEN_DIR)
fi
export OIDC_TOKEN_DIR
mkdir -p $OIDC_TOKEN_DIR

pushd $SCRIPT_DIR
Expand Down
3 changes: 2 additions & 1 deletion .evergreen/auth_oidc/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ else
echo "export CLUSTER_NAME=$DEPLOYMENT_NAME" >> "secrets-export.sh"

# Set the create cluster configuration.
export DEPLOYMENT_DATA=$(cat <<EOF
DEPLOYMENT_DATA=$(cat <<EOF
{
"autoScaling" : {
"autoIndexingEnabled" : false,
Expand Down Expand Up @@ -86,6 +86,7 @@ else
}
EOF
)
export DEPLOYMENT_DATA

export ATLAS_PUBLIC_API_KEY=$OIDC_ATLAS_PUBLIC_API_KEY
export ATLAS_PRIVATE_API_KEY=$OIDC_ATLAS_PRIVATE_API_KEY
Expand Down
3 changes: 2 additions & 1 deletion .evergreen/aws_lambda/run-deployed-lambda-aws-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ SECRETS_FILE=$SCRIPT_DIR/../atlas/secrets-export.sh

if [ -f $SECRETS_FILE ]; then
echo "Sourcing secrets"
# shellcheck source=../atlas/secrets-export.sh
source $SECRETS_FILE
fi

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in ${VARLIST[*]}; do
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

Expand Down
1 change: 1 addition & 0 deletions .evergreen/compile-unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ case "$OS" in
# Make linux builds a tad faster by parallelise the build
cpus=$(grep -c '^processor' /proc/cpuinfo)
MAKEFLAGS="-j${cpus}"
echo $MAKEFLAGS $TAR
;;

sunos)
Expand Down
3 changes: 2 additions & 1 deletion .evergreen/compile-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ case "$CC" in
;;
esac

export PATH=$PATH:`pwd`/tests:`pwd`/Debug:`pwd`/src/libbson/Debug
PATH=$PATH:`pwd`/tests:`pwd`/Debug:`pwd`/src/libbson/Debug
export PATH
CMAKE="/cygdrive/c/cmake/bin/cmake"
INSTALL_DIR="C:/install-dir"

Expand Down
4 changes: 2 additions & 2 deletions .evergreen/csfle/await-servers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pushd $SCRIPT_DIR
# Wait until the pids file has been created.
echo "Waiting for servers to start..."
await_pidfile() {
for i in $(seq 300); do
for _ in $(seq 300); do
if [ -f ./kmip_pids.pid ]; then
return 0
fi
Expand All @@ -25,7 +25,7 @@ echo "Waiting for servers to start...done"
# Ensure servers are running.
await_server() {
echo "Waiting on $1 server on port $2"
for i in $(seq 10); do
for _ in $(seq 10); do
# Exit code 7: "Failed to connect to host".
if curl -s "localhost:$2"; test $? -ne 7; then
echo "Waiting on $1 server on port $2...done"
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/csfle/azurekms/create-and-setup-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ AZUREKMS_SCOPE

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in ${VARLIST[*]}; do
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

Expand Down
2 changes: 1 addition & 1 deletion .evergreen/csfle/azurekms/create-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ az vm create \
--assign-identity $AZUREKMS_IDENTITY \
>/dev/null

if [ $(uname -s) = "Darwin" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
SHUTDOWN_TIME=$(date -u -v+1H +"%H%M")
else
SHUTDOWN_TIME=$(date -u -d "$(date) + 1 hours" +"%H%M")
Expand Down
20 changes: 11 additions & 9 deletions .evergreen/csfle/azurekms/login.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ set -o errexit
set -o pipefail
set -o nounset

if [ -z "$AZUREKMS_CLIENTID" -o \
-z "$AZUREKMS_SECRET" -o \
-z "$AZUREKMS_TENANTID" ]; then
echo "Please set the following required environment variables"
echo " AZUREKMS_CLIENTID"
echo " AZUREKMS_SECRET"
echo " AZUREKMS_TENANTID"
exit 1
fi
VARLIST=(
AZUREKMS_CLIENTID
AZUREKMS_SECRET
AZUREKMS_TENANTID
)

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

# Check for Azure Command-Line Interface (`az`) version 2.25.0 or newer.
if ! command -v az &> /dev/null; then
Expand Down
23 changes: 12 additions & 11 deletions .evergreen/csfle/azurekms/run-command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ set -o errexit
set -o pipefail
set -o nounset

if [ -z "$AZUREKMS_RESOURCEGROUP" -o \
-z "$AZUREKMS_VMNAME" -o \
-z "$AZUREKMS_PRIVATEKEYPATH" -o \
-z "$AZUREKMS_CMD" ]; then
echo "Please set the following required environment variables"
echo " AZUREKMS_RESOURCEGROUP"
echo " AZUREKMS_VMNAME"
echo " AZUREKMS_PRIVATEKEYPATH"
echo " AZUREKMS_CMD"
exit 1
fi
VARLIST=(
AZUREKMS_RESOURCEGROUP
AZUREKMS_VMNAME
AZUREKMS_PRIVATEKEYPATH
AZUREKMS_CMD
)

# Ensure that all variables required to run the test are set, otherwise throw
# an error.
for VARNAME in "${VARLIST[@]}"; do
[[ -z "${!VARNAME:-}" ]] && echo "ERROR: $VARNAME not set" && exit 1;
done

echo "Running '$AZUREKMS_CMD' on Azure Virtual Machine ... begin"
IP=$(az vm show --show-details --resource-group $AZUREKMS_RESOURCEGROUP --name $AZUREKMS_VMNAME --query publicIps -o tsv)
Expand Down
Loading

0 comments on commit be87492

Please sign in to comment.