Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 38f185a

Browse files
paulfantomJamesGuthrie
authored andcommitted
*: apply shellcheck suggestions to all shellscripts
1 parent 2bae61c commit 38f185a

File tree

7 files changed

+41
-39
lines changed

7 files changed

+41
-39
lines changed

docker-compose/high-availability/test.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
set -euf -o pipefail
1616

17-
SELF_DIR=$(cd $(dirname ${0}) && pwd)
18-
cd $SELF_DIR
17+
SELF_DIR="$(cd "$(dirname "${0}")" && pwd)"
18+
cd "$SELF_DIR"
1919

2020
echo "running tests"
2121

@@ -39,9 +39,9 @@ leader_name() {
3939
}
4040

4141
is_leader() {
42-
LEADER1=$(leader_name "promscale_deploy_ha-promscale-connector1-1")
43-
LEADER2=$(leader_name "promscale_deploy_ha-promscale-connector2-1")
44-
if [[ "$LEADER1" == $1 && "$LEADER2" == $1 ]]; then
42+
LEADER1="$(leader_name "promscale_deploy_ha-promscale-connector1-1")"
43+
LEADER2="$(leader_name "promscale_deploy_ha-promscale-connector2-1")"
44+
if [[ "$LEADER1" == "$1" ]] && [[ "$LEADER2" == "$1" ]]; then
4545
true
4646
else
4747
false
@@ -73,6 +73,7 @@ wait_for() {
7373
wait_for_leader() {
7474
echo "waiting for $1 to be leader"
7575

76+
# shellcheck disable=SC2034
7677
for i in `seq 10` ; do
7778
if is_leader "$1"; then
7879
echo "$1 is leader"

docker-compose/test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
set -euf -o pipefail
44

5-
SELF_DIR=$(cd $(dirname ${0}) && pwd)
6-
cd $SELF_DIR
5+
SELF_DIR="$(cd "$(dirname "${0}")" && pwd)"
6+
cd "$SELF_DIR"
77

88
echo "running tests"
99

docs/scripts/install-crontab.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#/bin/sh
1+
#!/bin/sh
22
echo "0,30 * * * * /<ABSOLUTE_PATH>/prom-execute-maintenance.sh" | crontab -
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#/bin/sh
2-
export PGPASSWORD=<PASSWORD>
1+
#!/bin/sh
2+
export PGPASSWORD="<PASSWORD>"
33
psql --host localhost --port 5432 --dbname postgres --user postgres -c 'CALL prom_api.execute_maintenance();'

scripts/end_to_end_tests.sh

+14-14
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ case "${unameOut}" in
1111
*) ISMAC=0;;
1212
esac
1313

14-
TIMESCALE_IMAGE=${1:-"timescale/timescaledb:latest-pg14"}
15-
SCRIPT_DIR=$(cd $(dirname ${0}) && pwd)
16-
ROOT_DIR=$(dirname ${SCRIPT_DIR})
14+
TIMESCALE_IMAGE="${1:-"timescale/timescaledb:latest-pg14"}"
15+
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
16+
ROOT_DIR=$(dirname "${SCRIPT_DIR}")
1717
DB_URL="localhost:5432"
1818
CONNECTOR_URL="localhost:9201"
1919
PROM_URL="localhost:9090"
@@ -28,11 +28,12 @@ fi
2828

2929
CONF=$(mktemp)
3030

31-
chmod 777 $CONF
31+
chmod 777 "$CONF"
3232

3333
echo "running tests against ${TIMESCALE_IMAGE}"
3434

35-
echo "scrape_configs:
35+
cat << EOF > "$CONF"
36+
scrape_configs:
3637
- job_name: 'connector'
3738
scrape_interval: 5s
3839
static_configs:
@@ -44,17 +45,18 @@ remote_read:
4445
4546
remote_write:
4647
- url: http://$CONNECTOR_URL_CONTAINER/write
47-
remote_timeout: 1m" > $CONF
48+
remote_timeout: 1m
49+
EOF
4850

4951
cleanup() {
50-
if [[ $PASSED -ne 6 ]]; then
52+
if [[ "$PASSED" -ne 6 ]]; then
5153
docker logs e2e-tsdb || true
5254
fi
53-
rm $CONF || true
55+
rm "$CONF" || true
5456
docker stop e2e-prom || true
5557
docker stop e2e-tsdb || true
5658
if [ -n "$CONN_PID" ]; then
57-
kill $CONN_PID
59+
kill "$CONN_PID"
5860
fi
5961
}
6062

@@ -135,7 +137,7 @@ curl -v \
135137
"${CONNECTOR_URL}/write"
136138

137139

138-
kill $CONN_PID
140+
kill "$CONN_PID"
139141

140142
PROMSCALE_TELEMETRY_LOG_LEVEL=debug \
141143
PROMSCALE_DB_PASSWORD=test \
@@ -158,7 +160,7 @@ curl -f \
158160
--data "custom_metric{custom_label=\"custom_value_2\"} 5" \
159161
"${CONNECTOR_URL}/write" || exit 1
160162

161-
kill $CONN_PID
163+
kill "$CONN_PID"
162164

163165
PROMSCALE_TELEMETRY_LOG_LEVEL=debug \
164166
PROMSCALE_DB_PASSWORD=test \
@@ -188,8 +190,6 @@ compare_connector_and_prom() {
188190
fi
189191
}
190192

191-
END_TIME=$(date +"%s")
192-
193193
DATASET_START_TIME="2020-08-10T10:35:20Z"
194194
DATASET_END_TIME="2020-08-10T11:43:50Z"
195195

@@ -224,7 +224,7 @@ echo "Passed: $PASSED"
224224
echo "Failed: $FAILED"
225225

226226

227-
if [[ $FAILED -eq 0 ]]; then
227+
if [[ "$FAILED" -eq 0 ]]; then
228228
exit 0
229229
else
230230
exit 1

scripts/generate-deploy-script.sh

+12-13
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ if [ -n "$DEBUG" ]; then
44
set -x
55
fi
66

7-
DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)
8-
HELMDIR="${DIR}/../deploy/helm-chart"
7+
# Execute whole script from repository top level
8+
cd "$(git rev-parse --show-toplevel)"
99

10+
OUTPUT_FILE="deploy/static/deploy.yaml"
11+
12+
# Default to promscale helm release name i.e. adds the label values as promscale
13+
RELEASE_NAME=promscale
14+
# Default to to default namespace
15+
NAMESPACE=default
16+
17+
HELMDIR="deploy/helm-chart"
1018
# Default values.yaml file to provide to helm template command.
1119
FILE_ARG="${HELMDIR}/values.yaml"
1220

@@ -21,15 +29,6 @@ set -o errexit
2129
set -o nounset
2230
set -o pipefail
2331

24-
# Default to promscale helm release name i.e. adds the label values as promscale
25-
RELEASE_NAME=promscale
26-
# Default to to default namespace
27-
NAMESPACE=default
28-
29-
helm dependency update ${HELMDIR}
30-
31-
OUTPUT_FILE="${DIR}/../deploy/static/deploy.yaml"
32-
cat << EOF | helm template $RELEASE_NAME ${HELMDIR} --namespace $NAMESPACE --values $FILE_ARG > ${OUTPUT_FILE}
33-
EOF
32+
helm dependency update "${HELMDIR}"
3433

35-
echo "$(cat ${OUTPUT_FILE})" > ${OUTPUT_FILE}
34+
helm template "$RELEASE_NAME" "${HELMDIR}" --namespace "$NAMESPACE" --values "$FILE_ARG" | tee "${OUTPUT_FILE}"

scripts/wait-for.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ echoerr() {
99
}
1010

1111
usage() {
12+
cmdname=${0}
1213
exitcode="$1"
1314
cat << USAGE >&2
1415
Usage:
@@ -21,7 +22,8 @@ USAGE
2122
}
2223

2324
wait_for() {
24-
for i in `seq $TIMEOUT` ; do
25+
# shellcheck disable=SC2034
26+
for i in $(seq $TIMEOUT) ; do
2527
nc -z "$HOST" "$PORT" > /dev/null 2>&1
2628

2729
result=$?
@@ -72,7 +74,7 @@ do
7274
esac
7375
done
7476

75-
if [ "$HOST" = "" -o "$PORT" = "" ]; then
77+
if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then
7678
echoerr "Error: you need to provide a host and port to test."
7779
usage 2
7880
fi

0 commit comments

Comments
 (0)