Skip to content

Commit 959f246

Browse files
authored
style(shell): clear remaining ShellCheck warnings across 8.0.0 scripts (#660)
## Summary Finishes the ShellCheck cleanup started in #652#655. Applies the same patterns that landed in the 7.0.4 image to the 8.0.0 image, plus the glob-loop rewrite to `fsupgrade-{2..7}.sh`. After this, every file covered by `.github/workflows/shellcheck.yml` produces zero findings locally. ### Changes - `docker/openemr/8.0.0/env.stub` — new stub file declaring runtime env vars supplied by docker-compose, for SC2154 silencing. Pattern established in #653/#655. - `docker/openemr/8.0.0/openemr.sh` and `docker/openemr/8.0.0/ssl.sh`: - Add the env.stub source wrapped in `if false; then … fi` so ShellCheck follows it statically but the `.` command never runs at container startup. BusyBox ash (Alpine's `/bin/sh`) exits on special-builtin failure even with `|| true`, which is what broke the container in #655's first attempt. - `{ > file ; } &> /dev/null` → POSIX `: > file 2>/dev/null` (SC2188, SC3020) with an expanded comment explaining why `set -o noclobber` + O_CREAT|O_EXCL is the right TOCTOU-safe leader-election primitive. - `echo -n` → `printf '%s'` (SC3037). - Hoist `$(nproc --all)` to `jobs=` so ShellCheck can see its exit status (SC2312). - Inline `# shellcheck disable=SC2310` with an explanatory comment at each retry-predicate `while` (`swarm_wait`, `! auto_setup`). - `docker/openemr/8.0.0/upgrade/fsupgrade-{2..7}.sh` — rewrite `for X in $(find sites/* -maxdepth 0 -type d)` as `for X in sites/*/; do X="${X%/}"; sitename=${X##*/}` (SC2044, drops the `basename` subshell). Matches #654. ### Clears SC2044 (13), SC2154 (15), SC2188 (1), SC2310 (3), SC2312 (1), SC3020 (1), SC3037 (1). ## Test plan - [x] `shellcheck --check-sourced --external-sources` over the full set of 113 files matched by the workflow returns no findings - [x] `bash -n` on each modified script passes - [ ] CI green: ShellCheck + Production Docker (7.0.4/8.0.0/8.1.0/8.1.1/binary/flex)
1 parent 84ca0c3 commit 959f246

9 files changed

Lines changed: 103 additions & 28 deletions

File tree

docker/openemr/8.0.0/env.stub

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# shellcheck shell=sh
2+
# Stub file for ShellCheck SC2154 (vars referenced but not assigned).
3+
# These variables come from the Docker container environment, set by
4+
# docker-compose's `environment:` block or `-e` flags on `docker run`.
5+
# This file exists solely to tell ShellCheck the names are intentional;
6+
# it is not sourced at runtime.
7+
8+
# openemr.sh
9+
: "${K8S:=}"
10+
: "${SWARM_MODE:=}"
11+
: "${MANUAL_SETUP:=}"
12+
: "${REDIS_SERVER:=}"
13+
: "${PHPREDIS_BUILD:=}"
14+
: "${PHP_VERSION_ABBR:=}"
15+
: "${REDIS_USERNAME:=}"
16+
: "${REDIS_PASSWORD:=}"
17+
: "${REDIS_X509:=}"
18+
: "${REDIS_TLS:=}"
19+
: "${XDEBUG_IDE_KEY:=}"
20+
: "${XDEBUG_ON:=}"
21+
22+
# ssl.sh
23+
: "${DOMAIN:=}"
24+
: "${OPERATOR:=}"

docker/openemr/8.0.0/openemr.sh

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ set -e
1212
# shellcheck source=SCRIPTDIR/utilities/devtoolsLibrary.source
1313
. /root/devtoolsLibrary.source
1414

15+
# Environment variables used by this script are supplied by the Docker runtime
16+
# (docker-compose `environment:` or `-e` flags). The env.stub file declares
17+
# them for ShellCheck's benefit using `: "${VAR:=}"` assignments that leave
18+
# real runtime values untouched. The stub is not shipped into the container
19+
# image; the `if false` keeps the `.` statically visible to ShellCheck's
20+
# source-follower without ever running it — BusyBox ash treats `.` as a
21+
# special builtin and exits the shell on file-not-found even with `|| true`.
22+
if false; then
23+
# shellcheck source=docker/openemr/8.0.0/env.stub
24+
. /root/env.stub
25+
fi
26+
1527
swarm_wait() {
1628
if [ ! -f /var/www/localhost/htdocs/openemr/sites/docker-completed ]; then
1729
# true
@@ -75,13 +87,23 @@ elif [ "${K8S}" = "worker" ]; then
7587
fi
7688

7789
if [ "${SWARM_MODE}" = "yes" ]; then
78-
# atomically test for leadership
90+
# Atomically test for leadership. Multiple swarm containers race through this block,
91+
# and exactly one must become the leader. A `[ -f file ]` check followed by a create
92+
# has a TOCTOU race — every racer sees the file missing, every racer creates it, every
93+
# racer declares itself leader. Instead, `set -o noclobber` makes the redirect below
94+
# use `open(O_CREAT|O_EXCL)`: the kernel serializes the creation, exactly one redirect
95+
# succeeds, and every other container's redirect fails with EEXIST and falls into the
96+
# `|| AUTHORITY=no` branch. One winner by construction.
7997
set -o noclobber
80-
{ > /var/www/localhost/htdocs/openemr/sites/docker-leader ; } &> /dev/null || AUTHORITY=no
98+
: > /var/www/localhost/htdocs/openemr/sites/docker-leader 2>/dev/null || AUTHORITY=no
8199
set +o noclobber
82100

83101
if [ "${AUTHORITY}" = "no" ] &&
84102
[ ! -f /var/www/localhost/htdocs/openemr/sites/docker-completed ]; then
103+
# swarm_wait is a retry predicate: its failure is the loop termination
104+
# signal, not a script-fatal condition. Disabling set -e in the while
105+
# condition is intentional.
106+
# shellcheck disable=SC2310
85107
while swarm_wait; do
86108
echo "Waiting for the docker-leader to finish configuration before proceeding."
87109
sleep 10;
@@ -224,6 +246,10 @@ if [ "${AUTHORITY}" = "yes" ]; then
224246
[ "${MANUAL_SETUP}" != "yes" ]; then
225247

226248
echo "Running quick setup!"
249+
# auto_setup is a retry predicate: the loop drives it to success and
250+
# the ! inverts its exit for the exit condition. Disabling set -e in
251+
# both the ! and while contexts is intentional.
252+
# shellcheck disable=SC2310
227253
while ! auto_setup; do
228254
echo "Couldn't set up. Any of these reasons could be what's wrong:"
229255
echo " - You didn't spin up a MySQL container or connect your OpenEMR container to a mysql instance"
@@ -253,7 +279,7 @@ if
253279
fi
254280
c=$(( c + 1 ))
255281
done
256-
echo -n "${DOCKER_VERSION_ROOT}" > /var/www/localhost/htdocs/openemr/sites/default/docker-version
282+
printf '%s' "${DOCKER_VERSION_ROOT}" > /var/www/localhost/htdocs/openemr/sites/default/docker-version
257283
echo "Completed upgrade"
258284
fi
259285
fi
@@ -284,7 +310,8 @@ if [ "${REDIS_SERVER}" != "" ] &&
284310
phpize83
285311
# note for php 8.3, needed to change from './configure --enable-redis-igbinary' to:
286312
./configure --with-php-config=/usr/bin/php-config83 --enable-redis-igbinary
287-
make -j "$(nproc --all)"
313+
jobs=$(nproc --all)
314+
make -j "${jobs}"
288315
make install
289316
echo "extension=redis" > "/etc/php${PHP_VERSION_ABBR}/conf.d/20_redis.ini"
290317
rm -fr /tmpredis/phpredis

docker/openemr/8.0.0/ssl.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
#
99
set -e
1010

11+
# Environment variables used by this script are supplied by the Docker runtime
12+
# (docker-compose `environment:` or `-e` flags). The env.stub file declares
13+
# them for ShellCheck's benefit using `: "${VAR:=}"` assignments that leave
14+
# real runtime values untouched. The stub is not shipped into the container
15+
# image; the `if false` keeps the `.` statically visible to ShellCheck's
16+
# source-follower without ever running it — BusyBox ash treats `.` as a
17+
# special builtin and exits the shell on file-not-found even with `|| true`.
18+
if false; then
19+
# shellcheck source=docker/openemr/8.0.0/env.stub
20+
. /root/env.stub
21+
fi
22+
1123
if ! [ -f /etc/ssl/private/selfsigned.key.pem ]; then
1224
openssl req -x509 -newkey rsa:4096 \
1325
-keyout /etc/ssl/private/selfsigned.key.pem \

docker/openemr/8.0.0/upgrade/fsupgrade-2.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ priorOpenemrVersion="5.0.2"
66
echo "Start: Upgrade to docker-version 2"
77

88
# Perform codebase upgrade on each directory in sites/
9-
for dir in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
10-
sitename=$(basename "${dir}")
9+
for dir in /var/www/localhost/htdocs/openemr/sites/*/; do
10+
dir="${dir%/}"
11+
sitename=${dir##*/}
1112

1213
# Ensure have all directories
1314
echo "Start: Ensure have all directories in ${sitename}"
@@ -39,8 +40,9 @@ chown -R apache:root /var/www/localhost/htdocs/openemr/sites/
3940
echo "Completed: Fix permissions"
4041

4142
# Perform database upgrade on each directory in sites/
42-
for dirdata in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
43-
sitename=$(basename "${dirdata}")
43+
for dirdata in /var/www/localhost/htdocs/openemr/sites/*/; do
44+
dirdata="${dirdata%/}"
45+
sitename=${dirdata##*/}
4446

4547
# Upgrade database
4648
echo "Start: Upgrade database for ${sitename} from ${priorOpenemrVersion}"

docker/openemr/8.0.0/upgrade/fsupgrade-3.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ priorOpenemrVersion="6.0.0"
66
echo "Start: Upgrade to docker-version 3"
77

88
# Perform codebase upgrade on each directory in sites/
9-
for dir in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
10-
sitename=$(basename "${dir}")
9+
for dir in /var/www/localhost/htdocs/openemr/sites/*/; do
10+
dir="${dir%/}"
11+
sitename=${dir##*/}
1112

1213
# Ensure have all directories
1314
echo "Start: Ensure have all directories in ${sitename}"
@@ -39,8 +40,9 @@ chown -R apache:root /var/www/localhost/htdocs/openemr/sites/
3940
echo "Completed: Fix permissions"
4041

4142
# Perform database upgrade on each directory in sites/
42-
for dirdata in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
43-
sitename=$(basename "${dirdata}")
43+
for dirdata in /var/www/localhost/htdocs/openemr/sites/*/; do
44+
dirdata="${dirdata%/}"
45+
sitename=${dirdata##*/}
4446

4547
# Upgrade database
4648
echo "Start: Upgrade database for ${sitename} from ${priorOpenemrVersion}"

docker/openemr/8.0.0/upgrade/fsupgrade-4.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ priorOpenemrVersion="6.1.0"
66
echo "Start: Upgrade to docker-version 4"
77

88
# Perform codebase upgrade on each directory in sites/
9-
for dir in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
10-
sitename=$(basename "${dir}")
9+
for dir in /var/www/localhost/htdocs/openemr/sites/*/; do
10+
dir="${dir%/}"
11+
sitename=${dir##*/}
1112

1213
# Ensure have all directories
1314
echo "Start: Ensure have all directories in ${sitename}"
@@ -39,8 +40,9 @@ chown -R apache:root /var/www/localhost/htdocs/openemr/sites/
3940
echo "Completed: Fix permissions"
4041

4142
# Perform database upgrade on each directory in sites/
42-
for dirdata in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
43-
sitename=$(basename "${dirdata}")
43+
for dirdata in /var/www/localhost/htdocs/openemr/sites/*/; do
44+
dirdata="${dirdata%/}"
45+
sitename=${dirdata##*/}
4446

4547
# Upgrade database
4648
echo "Start: Upgrade database for ${sitename} from ${priorOpenemrVersion}"

docker/openemr/8.0.0/upgrade/fsupgrade-5.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ priorOpenemrVersion="7.0.0"
66
echo "Start: Upgrade to docker-version 5"
77

88
# Perform codebase upgrade on each directory in sites/
9-
for dir in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
10-
sitename=$(basename "${dir}")
9+
for dir in /var/www/localhost/htdocs/openemr/sites/*/; do
10+
dir="${dir%/}"
11+
sitename=${dir##*/}
1112

1213
# Ensure have all directories
1314
echo "Start: Ensure have all directories in ${sitename}"
@@ -39,8 +40,9 @@ chown -R apache:root /var/www/localhost/htdocs/openemr/sites/
3940
echo "Completed: Fix permissions"
4041

4142
# Perform database upgrade on each directory in sites/
42-
for dirdata in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
43-
sitename=$(basename "${dirdata}")
43+
for dirdata in /var/www/localhost/htdocs/openemr/sites/*/; do
44+
dirdata="${dirdata%/}"
45+
sitename=${dirdata##*/}
4446

4547
# Upgrade database
4648
echo "Start: Upgrade database for ${sitename} from ${priorOpenemrVersion}"

docker/openemr/8.0.0/upgrade/fsupgrade-6.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ priorOpenemrVersion="7.0.1"
66
echo "Start: Upgrade to docker-version 6"
77

88
# Perform codebase upgrade on each directory in sites/
9-
for dir in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
10-
sitename=$(basename "${dir}")
9+
for dir in /var/www/localhost/htdocs/openemr/sites/*/; do
10+
dir="${dir%/}"
11+
sitename=${dir##*/}
1112

1213
# Ensure have all directories
1314
echo "Start: Ensure have all directories in ${sitename}"
@@ -39,8 +40,9 @@ chown -R apache:root /var/www/localhost/htdocs/openemr/sites/
3940
echo "Completed: Fix permissions"
4041

4142
# Perform database upgrade on each directory in sites/
42-
for dirdata in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
43-
sitename=$(basename "${dirdata}")
43+
for dirdata in /var/www/localhost/htdocs/openemr/sites/*/; do
44+
dirdata="${dirdata%/}"
45+
sitename=${dirdata##*/}
4446

4547
# Upgrade database
4648
echo "Start: Upgrade database for ${sitename} from ${priorOpenemrVersion}"

docker/openemr/8.0.0/upgrade/fsupgrade-7.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ priorOpenemrVersion="7.0.2"
66
echo "Start: Upgrade to docker-version 7"
77

88
# Perform codebase upgrade on each directory in sites/
9-
for dir in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
10-
sitename=$(basename "${dir}")
9+
for dir in /var/www/localhost/htdocs/openemr/sites/*/; do
10+
dir="${dir%/}"
11+
sitename=${dir##*/}
1112

1213
# Ensure have all directories
1314
echo "Start: Ensure have all directories in ${sitename}"
@@ -39,8 +40,9 @@ chown -R apache:root /var/www/localhost/htdocs/openemr/sites/
3940
echo "Completed: Fix permissions"
4041

4142
# Perform database upgrade on each directory in sites/
42-
for dirdata in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
43-
sitename=$(basename "${dirdata}")
43+
for dirdata in /var/www/localhost/htdocs/openemr/sites/*/; do
44+
dirdata="${dirdata%/}"
45+
sitename=${dirdata##*/}
4446

4547
# Upgrade database
4648
echo "Start: Upgrade database for ${sitename} from ${priorOpenemrVersion}"

0 commit comments

Comments
 (0)