Skip to content

Commit dd4674c

Browse files
committed
Follow ShellCheck's style guide for Bash scripts
Recent versions of ShellCheck recommend using "[[" in Bash scripts. Recent versions of ShellCheck recommend using "|| true" to indicate when errors can be ignored. I like the built-in ":" for this purpose. See: https://github.com/koalaman/shellcheck/wiki/SC2292 See: https://github.com/koalaman/shellcheck/wiki/SC2312 See: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#colon
1 parent 319875e commit dd4674c

File tree

11 files changed

+107
-107
lines changed

11 files changed

+107
-107
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
jobs:
1212
go-test:
13-
runs-on: ubuntu-20.04
13+
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
1616
- uses: actions/setup-go@v5
@@ -22,7 +22,7 @@ jobs:
2222
run: go mod tidy && git diff --exit-code -- go.mod
2323

2424
kubernetes-api:
25-
runs-on: ubuntu-20.04
25+
runs-on: ubuntu-latest
2626
needs: [go-test]
2727
strategy:
2828
fail-fast: false
@@ -49,7 +49,7 @@ jobs:
4949

5050
kubernetes-k3d:
5151
if: "${{ github.repository == 'CrunchyData/postgres-operator' }}"
52-
runs-on: ubuntu-20.04
52+
runs-on: ubuntu-latest
5353
needs: [go-test]
5454
strategy:
5555
fail-fast: false

internal/controller/postgrescluster/instance_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -708,21 +708,21 @@ func TestAddPGBackRestToInstancePodSpec(t *testing.T) {
708708
- --
709709
- |-
710710
monitor() {
711-
exec {fd}<> <(:)
711+
exec {fd}<> <(:||:)
712712
until read -r -t 5 -u "${fd}"; do
713713
if
714-
[ "${filename}" -nt "/proc/self/fd/${fd}" ] &&
714+
[[ "${filename}" -nt "/proc/self/fd/${fd}" ]] &&
715715
pkill -HUP --exact --parent=0 pgbackrest
716716
then
717-
exec {fd}>&- && exec {fd}<> <(:)
717+
exec {fd}>&- && exec {fd}<> <(:||:)
718718
stat --dereference --format='Loaded configuration dated %y' "${filename}"
719719
elif
720-
{ [ "${directory}" -nt "/proc/self/fd/${fd}" ] ||
721-
[ "${authority}" -nt "/proc/self/fd/${fd}" ]
720+
{ [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] ||
721+
[[ "${authority}" -nt "/proc/self/fd/${fd}" ]]
722722
} &&
723723
pkill -HUP --exact --parent=0 pgbackrest
724724
then
725-
exec {fd}>&- && exec {fd}<> <(:)
725+
exec {fd}>&- && exec {fd}<> <(:||:)
726726
stat --format='Loaded certificates dated %y' "${directory}"
727727
fi
728728
done
@@ -820,21 +820,21 @@ func TestAddPGBackRestToInstancePodSpec(t *testing.T) {
820820
- --
821821
- |-
822822
monitor() {
823-
exec {fd}<> <(:)
823+
exec {fd}<> <(:||:)
824824
until read -r -t 5 -u "${fd}"; do
825825
if
826-
[ "${filename}" -nt "/proc/self/fd/${fd}" ] &&
826+
[[ "${filename}" -nt "/proc/self/fd/${fd}" ]] &&
827827
pkill -HUP --exact --parent=0 pgbackrest
828828
then
829-
exec {fd}>&- && exec {fd}<> <(:)
829+
exec {fd}>&- && exec {fd}<> <(:||:)
830830
stat --dereference --format='Loaded configuration dated %y' "${filename}"
831831
elif
832-
{ [ "${directory}" -nt "/proc/self/fd/${fd}" ] ||
833-
[ "${authority}" -nt "/proc/self/fd/${fd}" ]
832+
{ [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] ||
833+
[[ "${authority}" -nt "/proc/self/fd/${fd}" ]]
834834
} &&
835835
pkill -HUP --exact --parent=0 pgbackrest
836836
then
837-
exec {fd}>&- && exec {fd}<> <(:)
837+
exec {fd}>&- && exec {fd}<> <(:||:)
838838
stat --format='Loaded certificates dated %y' "${directory}"
839839
fi
840840
done

internal/controller/standalone_pgadmin/pod.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,16 @@ loadServerCommand
345345
// descriptor gets closed and reopened to use the builtin `[ -nt` to check mtimes.
346346
// - https://unix.stackexchange.com/a/407383
347347
var reloadScript = `
348-
exec {fd}<> <(:)
349-
while read -r -t 5 -u "${fd}" || true; do
350-
if [ "${cluster_file}" -nt "/proc/self/fd/${fd}" ] && loadServerCommand
348+
exec {fd}<> <(:||:)
349+
while read -r -t 5 -u "${fd}" ||:; do
350+
if [[ "${cluster_file}" -nt "/proc/self/fd/${fd}" ]] && loadServerCommand
351351
then
352-
exec {fd}>&- && exec {fd}<> <(:)
352+
exec {fd}>&- && exec {fd}<> <(:||:)
353353
stat --format='Loaded shared servers dated %y' "${cluster_file}"
354354
fi
355-
if [ ! -d /proc/$(cat $PGADMIN4_PIDFILE) ]
355+
if [[ ! -d /proc/$(cat $PGADMIN4_PIDFILE) ]]
356356
then
357-
if [ $APP_RELEASE -eq 7 ]; then
357+
if [[ $APP_RELEASE -eq 7 ]]; then
358358
` + startCommandV7 + `
359359
else
360360
` + startCommandV8 + `

internal/controller/standalone_pgadmin/pod_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ containers:
8080
}
8181
loadServerCommand
8282
83-
exec {fd}<> <(:)
84-
while read -r -t 5 -u "${fd}" || true; do
85-
if [ "${cluster_file}" -nt "/proc/self/fd/${fd}" ] && loadServerCommand
83+
exec {fd}<> <(:||:)
84+
while read -r -t 5 -u "${fd}" ||:; do
85+
if [[ "${cluster_file}" -nt "/proc/self/fd/${fd}" ]] && loadServerCommand
8686
then
87-
exec {fd}>&- && exec {fd}<> <(:)
87+
exec {fd}>&- && exec {fd}<> <(:||:)
8888
stat --format='Loaded shared servers dated %y' "${cluster_file}"
8989
fi
90-
if [ ! -d /proc/$(cat $PGADMIN4_PIDFILE) ]
90+
if [[ ! -d /proc/$(cat $PGADMIN4_PIDFILE) ]]
9191
then
92-
if [ $APP_RELEASE -eq 7 ]; then
92+
if [[ $APP_RELEASE -eq 7 ]]; then
9393
pgadmin4 &
9494
else
9595
gunicorn -c /etc/pgadmin/gunicorn_config.py --chdir $PGADMIN_DIR pgAdmin4:app &
@@ -263,16 +263,16 @@ containers:
263263
}
264264
loadServerCommand
265265
266-
exec {fd}<> <(:)
267-
while read -r -t 5 -u "${fd}" || true; do
268-
if [ "${cluster_file}" -nt "/proc/self/fd/${fd}" ] && loadServerCommand
266+
exec {fd}<> <(:||:)
267+
while read -r -t 5 -u "${fd}" ||:; do
268+
if [[ "${cluster_file}" -nt "/proc/self/fd/${fd}" ]] && loadServerCommand
269269
then
270-
exec {fd}>&- && exec {fd}<> <(:)
270+
exec {fd}>&- && exec {fd}<> <(:||:)
271271
stat --format='Loaded shared servers dated %y' "${cluster_file}"
272272
fi
273-
if [ ! -d /proc/$(cat $PGADMIN4_PIDFILE) ]
273+
if [[ ! -d /proc/$(cat $PGADMIN4_PIDFILE) ]]
274274
then
275-
if [ $APP_RELEASE -eq 7 ]; then
275+
if [[ $APP_RELEASE -eq 7 ]]; then
276276
pgadmin4 &
277277
else
278278
gunicorn -c /etc/pgadmin/gunicorn_config.py --chdir $PGADMIN_DIR pgAdmin4:app &

internal/pgbackrest/config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ bash -xc "pgbackrest restore ${opts}"
232232
rm -f "${pgdata}/patroni.dynamic.json"
233233
export PGDATA="${pgdata}" PGHOST='/tmp'
234234
235-
until [ "${recovery=}" = 'f' ]; do
236-
if [ -z "${recovery}" ]; then
235+
until [[ "${recovery=}" == 'f' ]]; do
236+
if [[ -z "${recovery}" ]]; then
237237
control=$(pg_controldata)
238238
read -r max_conn <<< "${control##*max_connections setting:}"
239239
read -r max_lock <<< "${control##*max_locks_per_xact setting:}"
@@ -253,7 +253,7 @@ unix_socket_directories = '/tmp'` +
253253
ekc + `
254254
huge_pages = ` + hugePagesSetting + `
255255
EOF
256-
if [ "$(< "${pgdata}/PG_VERSION")" -ge 12 ]; then
256+
if [[ "$(< "${pgdata}/PG_VERSION")" -ge 12 ]]; then
257257
read -r max_wals <<< "${control##*max_wal_senders setting:}"
258258
echo >> /tmp/postgres.restore.conf "max_wal_senders = '${max_wals}'"
259259
fi
@@ -265,7 +265,7 @@ recovery=$(psql -Atc "SELECT CASE
265265
WHEN NOT pg_catalog.pg_is_in_recovery() THEN false
266266
WHEN NOT pg_catalog.pg_is_wal_replay_paused() THEN true
267267
ELSE pg_catalog.pg_wal_replay_resume()::text = ''
268-
END recovery" && sleep 1) || true
268+
END recovery" && sleep 1) ||:
269269
done
270270
271271
pg_ctl stop --silent --wait --timeout=31536000
@@ -451,21 +451,21 @@ func reloadCommand(name string) []string {
451451
// mtimes.
452452
// - https://unix.stackexchange.com/a/407383
453453
const script = `
454-
exec {fd}<> <(:)
454+
exec {fd}<> <(:||:)
455455
until read -r -t 5 -u "${fd}"; do
456456
if
457-
[ "${filename}" -nt "/proc/self/fd/${fd}" ] &&
457+
[[ "${filename}" -nt "/proc/self/fd/${fd}" ]] &&
458458
pkill -HUP --exact --parent=0 pgbackrest
459459
then
460-
exec {fd}>&- && exec {fd}<> <(:)
460+
exec {fd}>&- && exec {fd}<> <(:||:)
461461
stat --dereference --format='Loaded configuration dated %y' "${filename}"
462462
elif
463-
{ [ "${directory}" -nt "/proc/self/fd/${fd}" ] ||
464-
[ "${authority}" -nt "/proc/self/fd/${fd}" ]
463+
{ [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] ||
464+
[[ "${authority}" -nt "/proc/self/fd/${fd}" ]]
465465
} &&
466466
pkill -HUP --exact --parent=0 pgbackrest
467467
then
468-
exec {fd}>&- && exec {fd}<> <(:)
468+
exec {fd}>&- && exec {fd}<> <(:||:)
469469
stat --format='Loaded certificates dated %y' "${directory}"
470470
fi
471471
done

internal/pgbackrest/reconcile_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -636,21 +636,21 @@ func TestAddServerToInstancePod(t *testing.T) {
636636
- --
637637
- |-
638638
monitor() {
639-
exec {fd}<> <(:)
639+
exec {fd}<> <(:||:)
640640
until read -r -t 5 -u "${fd}"; do
641641
if
642-
[ "${filename}" -nt "/proc/self/fd/${fd}" ] &&
642+
[[ "${filename}" -nt "/proc/self/fd/${fd}" ]] &&
643643
pkill -HUP --exact --parent=0 pgbackrest
644644
then
645-
exec {fd}>&- && exec {fd}<> <(:)
645+
exec {fd}>&- && exec {fd}<> <(:||:)
646646
stat --dereference --format='Loaded configuration dated %y' "${filename}"
647647
elif
648-
{ [ "${directory}" -nt "/proc/self/fd/${fd}" ] ||
649-
[ "${authority}" -nt "/proc/self/fd/${fd}" ]
648+
{ [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] ||
649+
[[ "${authority}" -nt "/proc/self/fd/${fd}" ]]
650650
} &&
651651
pkill -HUP --exact --parent=0 pgbackrest
652652
then
653-
exec {fd}>&- && exec {fd}<> <(:)
653+
exec {fd}>&- && exec {fd}<> <(:||:)
654654
stat --format='Loaded certificates dated %y' "${directory}"
655655
fi
656656
done
@@ -760,21 +760,21 @@ func TestAddServerToInstancePod(t *testing.T) {
760760
- --
761761
- |-
762762
monitor() {
763-
exec {fd}<> <(:)
763+
exec {fd}<> <(:||:)
764764
until read -r -t 5 -u "${fd}"; do
765765
if
766-
[ "${filename}" -nt "/proc/self/fd/${fd}" ] &&
766+
[[ "${filename}" -nt "/proc/self/fd/${fd}" ]] &&
767767
pkill -HUP --exact --parent=0 pgbackrest
768768
then
769-
exec {fd}>&- && exec {fd}<> <(:)
769+
exec {fd}>&- && exec {fd}<> <(:||:)
770770
stat --dereference --format='Loaded configuration dated %y' "${filename}"
771771
elif
772-
{ [ "${directory}" -nt "/proc/self/fd/${fd}" ] ||
773-
[ "${authority}" -nt "/proc/self/fd/${fd}" ]
772+
{ [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] ||
773+
[[ "${authority}" -nt "/proc/self/fd/${fd}" ]]
774774
} &&
775775
pkill -HUP --exact --parent=0 pgbackrest
776776
then
777-
exec {fd}>&- && exec {fd}<> <(:)
777+
exec {fd}>&- && exec {fd}<> <(:||:)
778778
stat --format='Loaded certificates dated %y' "${directory}"
779779
fi
780780
done
@@ -875,21 +875,21 @@ func TestAddServerToRepoPod(t *testing.T) {
875875
- --
876876
- |-
877877
monitor() {
878-
exec {fd}<> <(:)
878+
exec {fd}<> <(:||:)
879879
until read -r -t 5 -u "${fd}"; do
880880
if
881-
[ "${filename}" -nt "/proc/self/fd/${fd}" ] &&
881+
[[ "${filename}" -nt "/proc/self/fd/${fd}" ]] &&
882882
pkill -HUP --exact --parent=0 pgbackrest
883883
then
884-
exec {fd}>&- && exec {fd}<> <(:)
884+
exec {fd}>&- && exec {fd}<> <(:||:)
885885
stat --dereference --format='Loaded configuration dated %y' "${filename}"
886886
elif
887-
{ [ "${directory}" -nt "/proc/self/fd/${fd}" ] ||
888-
[ "${authority}" -nt "/proc/self/fd/${fd}" ]
887+
{ [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] ||
888+
[[ "${authority}" -nt "/proc/self/fd/${fd}" ]]
889889
} &&
890890
pkill -HUP --exact --parent=0 pgbackrest
891891
then
892-
exec {fd}>&- && exec {fd}<> <(:)
892+
exec {fd}>&- && exec {fd}<> <(:||:)
893893
stat --format='Loaded certificates dated %y' "${directory}"
894894
fi
895895
done

internal/pgbouncer/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ func reloadCommand(name string) []string {
250250
// mtimes.
251251
// - https://unix.stackexchange.com/a/407383
252252
const script = `
253-
exec {fd}<> <(:)
254-
while read -r -t 5 -u "${fd}" || true; do
255-
if [ "${directory}" -nt "/proc/self/fd/${fd}" ] && pkill -HUP --exact pgbouncer
253+
exec {fd}<> <(:||:)
254+
while read -r -t 5 -u "${fd}" ||:; do
255+
if [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] && pkill -HUP --exact pgbouncer
256256
then
257-
exec {fd}>&- && exec {fd}<> <(:)
257+
exec {fd}>&- && exec {fd}<> <(:||:)
258258
stat --format='Loaded configuration dated %y' "${directory}"
259259
fi
260260
done

internal/pgbouncer/reconcile_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ containers:
160160
- --
161161
- |-
162162
monitor() {
163-
exec {fd}<> <(:)
164-
while read -r -t 5 -u "${fd}" || true; do
165-
if [ "${directory}" -nt "/proc/self/fd/${fd}" ] && pkill -HUP --exact pgbouncer
163+
exec {fd}<> <(:||:)
164+
while read -r -t 5 -u "${fd}" ||:; do
165+
if [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] && pkill -HUP --exact pgbouncer
166166
then
167-
exec {fd}>&- && exec {fd}<> <(:)
167+
exec {fd}>&- && exec {fd}<> <(:||:)
168168
stat --format='Loaded configuration dated %y' "${directory}"
169169
fi
170170
done
@@ -274,11 +274,11 @@ containers:
274274
- --
275275
- |-
276276
monitor() {
277-
exec {fd}<> <(:)
278-
while read -r -t 5 -u "${fd}" || true; do
279-
if [ "${directory}" -nt "/proc/self/fd/${fd}" ] && pkill -HUP --exact pgbouncer
277+
exec {fd}<> <(:||:)
278+
while read -r -t 5 -u "${fd}" ||:; do
279+
if [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] && pkill -HUP --exact pgbouncer
280280
then
281-
exec {fd}>&- && exec {fd}<> <(:)
281+
exec {fd}>&- && exec {fd}<> <(:||:)
282282
stat --format='Loaded configuration dated %y' "${directory}"
283283
fi
284284
done
@@ -384,11 +384,11 @@ containers:
384384
- --
385385
- |-
386386
monitor() {
387-
exec {fd}<> <(:)
388-
while read -r -t 5 -u "${fd}" || true; do
389-
if [ "${directory}" -nt "/proc/self/fd/${fd}" ] && pkill -HUP --exact pgbouncer
387+
exec {fd}<> <(:||:)
388+
while read -r -t 5 -u "${fd}" ||:; do
389+
if [[ "${directory}" -nt "/proc/self/fd/${fd}" ]] && pkill -HUP --exact pgbouncer
390390
then
391-
exec {fd}>&- && exec {fd}<> <(:)
391+
exec {fd}>&- && exec {fd}<> <(:||:)
392392
stat --format='Loaded configuration dated %y' "${directory}"
393393
fi
394394
done

internal/pgmonitor/exporter.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ func ExporterStartCommand(builtinCollectors bool, commandFlags ...string) []stri
160160

161161
// Create a file descriptor with a no-op process that will not get
162162
// cleaned up
163-
`exec {fd}<> <(:)`,
163+
`exec {fd}<> <(:||:)`,
164164

165165
// Set up loop. Use read's timeout setting instead of sleep,
166166
// which uses up a lot of memory
167-
`while read -r -t 3 -u "${fd}" || true; do`,
167+
`while read -r -t 3 -u "${fd}" ||:; do`,
168168

169169
// If either directories' modify time is newer than our file descriptor's,
170170
// something must have changed, so kill the postgres_exporter
@@ -174,14 +174,14 @@ func ExporterStartCommand(builtinCollectors bool, commandFlags ...string) []stri
174174
// When something changes we want to get rid of the old file descriptor, get a fresh one
175175
// and restart the loop
176176
` echo "Something changed..."`,
177-
` exec {fd}>&- && exec {fd}<> <(:)`,
177+
` exec {fd}>&- && exec {fd}<> <(:||:)`,
178178
` stat --format='Latest queries file dated %y' "/conf"`,
179179
` stat --format='Latest password file dated %y' "/opt/crunchy/password"`,
180180
` fi`,
181181

182182
// If postgres_exporter is not running, restart it
183183
// Use the recorded pid as a proxy for checking if postgres_exporter is running
184-
` if [ ! -e /proc/$(head -1 ${POSTGRES_EXPORTER_PIDFILE?}) ] ; then`,
184+
` if [[ ! -e /proc/$(head -1 ${POSTGRES_EXPORTER_PIDFILE?}) ]] ; then`,
185185
` start_postgres_exporter`,
186186
` fi`,
187187
`done`,

0 commit comments

Comments
 (0)