Skip to content

Commit d2d3ae4

Browse files
kojiromikeclaude
andcommitted
fix(shell): address all shellcheck warnings with -oall
Changes across docker/openemr (7.0.4, 7.0.5, 8.0.0, binary, flex), packages/standard, and utilities: Shell style improvements: - Quote variables to prevent word splitting (SC2086) - Use `find -exec {} +` instead of `find -print0 | xargs -0` - Use arithmetic syntax `(( ))` instead of `[ ]` for numeric comparisons - Use single `=` in `[[ ]]` tests instead of `==` - Use single quotes for literal strings - Use `mkdir -p` instead of `[[ ! -d ]] && mkdir` - Use POSIX parameter expansion for optional args: `${VAR:+-flag} ${VAR:+"$VAR"}` - Use `:` instead of `true` for no-op commands - Use `echo` for simple strings, `printf` only when format specifiers needed - Replace manual ANSI escapes with tput Bug fixes: - Fix misplaced quote in chown command (7.0.4, 8.0.0 devtoolsLibrary.source) Legitimate shellcheck disables with comments: - SC2086: CONFIGURATION variable intentionally word-splits - SC2154: Variables passed as environment variables to container - SC2310: Functions in retry loops with set -e are intentional - SC2016: Literal $ in warning messages 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2c3fa44 commit d2d3ae4

File tree

33 files changed

+701
-1102
lines changed

33 files changed

+701
-1102
lines changed

docker/openemr/7.0.4/openemr.sh

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/sh
2+
# shellcheck disable=SC2154,SC2310
3+
# SC2154: Variables are passed as environment variables to the Docker container
4+
# SC2310: Functions used in retry loops with set -e are intentional
25
# Allows customization of openemr credentials, preventing the need for manual setup
36
# (Note can force a manual setup by setting MANUAL_SETUP to 'yes')
47
# - Required settings for auto installation are MYSQL_HOST and MYSQL_ROOT_PASS
@@ -28,24 +31,27 @@ auto_setup() {
2831
find . -not -perm 600 -exec chmod 600 {} \+
2932

3033
#create temporary file cache directory for auto_configure.php to use
31-
TMP_FILE_CACHE_LOCATION="/tmp/php-file-cache"
32-
mkdir ${TMP_FILE_CACHE_LOCATION}
34+
TMP_FILE_CACHE_LOCATION='/tmp/php-file-cache'
35+
mkdir "${TMP_FILE_CACHE_LOCATION}"
3336

3437
#create auto_configure.ini to be able to leverage opcache for operations
35-
touch auto_configure.ini
36-
echo "opcache.enable=1" >> auto_configure.ini
37-
echo "opcache.enable_cli=1" >> auto_configure.ini
38-
echo "opcache.file_cache=${TMP_FILE_CACHE_LOCATION}" >> auto_configure.ini
39-
echo "opcache.file_cache_only=1" >> auto_configure.ini
40-
echo "opcache.file_cache_consistency_checks=1" >> auto_configure.ini
41-
echo "opcache.enable_file_override=1" >> auto_configure.ini
42-
echo "opcache.max_accelerated_files=1000000" >> auto_configure.ini
38+
{
39+
echo 'opcache.enable=1'
40+
echo 'opcache.enable_cli=1'
41+
echo "opcache.file_cache=${TMP_FILE_CACHE_LOCATION}"
42+
echo 'opcache.file_cache_only=1'
43+
echo 'opcache.file_cache_consistency_checks=1'
44+
echo 'opcache.enable_file_override=1'
45+
echo 'opcache.max_accelerated_files=1000000'
46+
} > auto_configure.ini
4347

4448
#run auto_configure
49+
# CONFIGURATION is intentionally unquoted - it contains space-separated key=value pairs
50+
# shellcheck disable=SC2086
4551
php auto_configure.php -c auto_configure.ini -f ${CONFIGURATION} || return 1
4652

4753
#remove temporary file cache directory and auto_configure.ini
48-
rm -r ${TMP_FILE_CACHE_LOCATION}
54+
rm -r "${TMP_FILE_CACHE_LOCATION}"
4955
rm auto_configure.ini
5056

5157
echo "OpenEMR configured."
@@ -75,7 +81,7 @@ fi
7581
if [ "${SWARM_MODE}" = "yes" ]; then
7682
# atomically test for leadership
7783
set -o noclobber
78-
{ > /var/www/localhost/htdocs/openemr/sites/docker-leader ; } &> /dev/null || AUTHORITY=no
84+
{ : > /var/www/localhost/htdocs/openemr/sites/docker-leader ; } > /dev/null 2>&1 || AUTHORITY=no
7985
set +o noclobber
8086

8187
if [ "${AUTHORITY}" = "no" ] &&
@@ -241,18 +247,18 @@ if
241247

242248
if ${UPGRADE_YES}; then
243249
# Need to do the upgrade
244-
echo "Attempting upgrade"
250+
echo 'Attempting upgrade'
245251
c=${DOCKER_VERSION_SITES}
246252
while [ "${c}" -le "${DOCKER_VERSION_ROOT}" ]; do
247253
if [ "${c}" -gt "${DOCKER_VERSION_SITES}" ] ; then
248254
echo "Start: Processing fsupgrade-${c}.sh upgrade script"
249-
sh /root/fsupgrade-${c}.sh
255+
sh "/root/fsupgrade-${c}.sh"
250256
echo "Completed: Processing fsupgrade-${c}.sh upgrade script"
251257
fi
252258
c=$(( c + 1 ))
253259
done
254-
echo -n ${DOCKER_VERSION_ROOT} > /var/www/localhost/htdocs/openemr/sites/default/docker-version
255-
echo "Completed upgrade"
260+
printf '%s' "${DOCKER_VERSION_ROOT}" > /var/www/localhost/htdocs/openemr/sites/default/docker-version
261+
echo 'Completed upgrade'
256262
fi
257263
fi
258264

@@ -269,8 +275,8 @@ if [ "${REDIS_SERVER}" != "" ] &&
269275
# version 5.3.7 .
270276
if [ "${PHPREDIS_BUILD}" != "" ]; then
271277
apk update
272-
apk del --no-cache php${PHP_VERSION_ABBR}-redis
273-
apk add --no-cache git php${PHP_VERSION_ABBR}-dev php${PHP_VERSION_ABBR}-pecl-igbinary gcc make g++
278+
apk del --no-cache "php${PHP_VERSION_ABBR}-redis"
279+
apk add --no-cache git "php${PHP_VERSION_ABBR}-dev" "php${PHP_VERSION_ABBR}-pecl-igbinary" gcc make g++
274280
mkdir /tmpredis
275281
cd /tmpredis
276282
git clone https://github.com/phpredis/phpredis.git
@@ -282,11 +288,12 @@ if [ "${REDIS_SERVER}" != "" ] &&
282288
phpize83
283289
# note for php 8.3, needed to change from './configure --enable-redis-igbinary' to:
284290
./configure --with-php-config=/usr/bin/php-config83 --enable-redis-igbinary
285-
make -j $(nproc --all)
291+
nproc_count=$(nproc --all)
292+
make -j "${nproc_count}"
286293
make install
287-
echo "extension=redis" > /etc/php${PHP_VERSION_ABBR}/conf.d/20_redis.ini
294+
echo 'extension=redis' > "/etc/php${PHP_VERSION_ABBR}/conf.d/20_redis.ini"
288295
rm -fr /tmpredis/phpredis
289-
apk del --no-cache git php${PHP_VERSION_ABBR}-dev gcc make g++
296+
apk del --no-cache git "php${PHP_VERSION_ABBR}-dev" gcc make g++
290297
cd /var/www/localhost/htdocs/openemr
291298
fi
292299

@@ -327,7 +334,7 @@ if [ "${REDIS_SERVER}" != "" ] &&
327334

328335
# Configure PHP to use Redis for sessions via conf.d include file
329336
{
330-
printf 'session.save_handler = redis\n'
337+
echo 'session.save_handler = redis'
331338
printf 'session.save_path = "%s"\n' "${REDIS_PATH}"
332339
} > "/etc/php${PHP_VERSION_ABBR}/conf.d/redis-session.ini"
333340

@@ -436,14 +443,16 @@ if [ "${XDEBUG_IDE_KEY}" != "" ] ||
436443
sh xdebug.sh
437444
#also need to turn off opcache since it can not be turned on with xdebug
438445
if [ ! -f /etc/php-opcache-jit-configured ]; then
439-
echo "opcache.enable=0" >> /etc/php${PHP_VERSION_ABBR}/php.ini
446+
echo 'opcache.enable=0' >> "/etc/php${PHP_VERSION_ABBR}/php.ini"
440447
touch /etc/php-opcache-jit-configured
441448
fi
442449
else
443450
# Configure opcache jit if Xdebug is not being used (note opcache is already on, so just need to add setting(s) to php.ini that are different from the default setting(s))
444451
if [ ! -f /etc/php-opcache-jit-configured ]; then
445-
echo "opcache.jit=tracing" >> /etc/php${PHP_VERSION_ABBR}/php.ini
446-
echo "opcache.jit_buffer_size=100M" >> /etc/php${PHP_VERSION_ABBR}/php.ini
452+
{
453+
echo 'opcache.jit=tracing'
454+
echo 'opcache.jit_buffer_size=100M'
455+
} >> "/etc/php${PHP_VERSION_ABBR}/php.ini"
447456
touch /etc/php-opcache-jit-configured
448457
fi
449458
fi

docker/openemr/7.0.4/ssl.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/sh
2+
# shellcheck disable=SC2154
3+
# SC2154: Variables are passed as environment variables to the Docker container
24
#
35
# configures SSL
46
# optionally configures Let's Encrypt
@@ -25,28 +27,27 @@ if [ ! -f /etc/ssl/docker-selfsigned-configured ]; then
2527
fi
2628

2729
if [ "${DOMAIN}" != "" ]; then
28-
if [ "${EMAIL}" != "" ]; then
29-
EMAIL="-m ${EMAIL}"
30-
else
31-
echo "WARNING: SETTING AN EMAIL VIA \$EMAIL is HIGHLY RECOMMENDED IN ORDER TO"
32-
echo " RECEIVE ALERTS FROM LETSENCRYPT ABOUT YOUR SSL CERTIFICATE."
30+
if [ "${EMAIL}" = "" ]; then
31+
# shellcheck disable=SC2016
32+
echo 'WARNING: SETTING AN EMAIL VIA $EMAIL is HIGHLY RECOMMENDED IN ORDER TO'
33+
echo ' RECEIVE ALERTS FROM LETSENCRYPT ABOUT YOUR SSL CERTIFICATE.'
3334
fi
3435
# if a domain has been set, set up LE and target those certs
3536

36-
if ! [ -f /etc/letsencrypt/live/${DOMAIN}/fullchain.pem ]; then
37+
if ! [ -f "/etc/letsencrypt/live/${DOMAIN}/fullchain.pem" ]; then
3738
/usr/sbin/httpd -k start
3839
sleep 2
39-
certbot certonly --webroot -n -w /var/www/localhost/htdocs/openemr/ -d ${DOMAIN} ${EMAIL} --agree-tos
40+
certbot certonly --webroot -n -w /var/www/localhost/htdocs/openemr/ -d "${DOMAIN}" ${EMAIL:+-m} ${EMAIL:+"${EMAIL}"} --agree-tos
4041
/usr/sbin/httpd -k stop
41-
echo "1 23 * * * certbot renew -q --post-hook \"httpd -k graceful\"" >> /etc/crontabs/root
42+
echo '1 23 * * * certbot renew -q --post-hook "httpd -k graceful"' >> /etc/crontabs/root
4243
fi
4344

4445
# run letsencrypt as a daemon and reference the correct cert
4546
if [ ! -f /etc/ssl/docker-letsencrypt-configured ]; then
4647
rm -f /etc/ssl/certs/webserver.cert.pem
4748
rm -f /etc/ssl/private/webserver.key.pem
48-
ln -s /etc/letsencrypt/live/${DOMAIN}/fullchain.pem /etc/ssl/certs/webserver.cert.pem
49-
ln -s /etc/letsencrypt/live/${DOMAIN}/privkey.pem /etc/ssl/private/webserver.key.pem
49+
ln -s "/etc/letsencrypt/live/${DOMAIN}/fullchain.pem" /etc/ssl/certs/webserver.cert.pem
50+
ln -s "/etc/letsencrypt/live/${DOMAIN}/privkey.pem" /etc/ssl/private/webserver.key.pem
5051
touch /etc/ssl/docker-letsencrypt-configured
5152
fi
5253

Lines changed: 35 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,61 @@
11
#!/bin/sh
22
# Upgrade number 1 for OpenEMR docker
33
# From prior version 5.0.1 (needed for the sql upgrade script).
4-
priorOpenemrVersion="5.0.1"
4+
priorOpenemrVersion='5.0.1'
55

6-
echo "Start: Upgrade to docker-version 1"
6+
echo 'Start: Upgrade to docker-version 1'
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+
sitename=${dir%/}
11+
sitename=${sitename##*/}
1112

1213
# Ensure have all directories
1314
echo "Start: Ensure have all directories in ${sitename}"
14-
if [ ! -d ${dir}/documents/certificates ]; then
15-
mkdir -p ${dir}/documents/certificates
16-
fi
17-
if [ ! -d ${dir}/documents/couchdb ]; then
18-
mkdir -p ${dir}/documents/couchdb
19-
fi
20-
if [ ! -d ${dir}/documents/custom_menus/patient_menus ]; then
21-
mkdir -p ${dir}/documents/custom_menus/patient_menus
22-
fi
23-
if [ ! -d ${dir}/documents/edi ]; then
24-
mkdir -p ${dir}/documents/edi
25-
fi
26-
if [ ! -d ${dir}/documents/era ]; then
27-
mkdir -p ${dir}/documents/era
28-
fi
29-
if [ ! -d ${dir}/documents/letter_templates ]; then
30-
mkdir -p ${dir}/documents/letter_templates
31-
fi
32-
if [ ! -d ${dir}/documents/logs_and_misc/methods ]; then
33-
mkdir -p ${dir}/documents/logs_and_misc/methods
34-
fi
35-
if [ ! -d ${dir}/documents/mpdf/pdf_tmp ]; then
36-
mkdir -p ${dir}/documents/mpdf/pdf_tmp
37-
fi
38-
if [ ! -d ${dir}/documents/onsite_portal_documents/templates ]; then
39-
mkdir -p ${dir}/documents/onsite_portal_documents/templates
40-
fi
41-
if [ ! -d ${dir}/documents/procedure_results ]; then
42-
mkdir -p ${dir}/documents/procedure_results
43-
fi
44-
if [ ! -d ${dir}/documents/smarty/gacl ]; then
45-
mkdir -p ${dir}/documents/smarty/gacl
46-
fi
47-
if [ ! -d ${dir}/documents/smarty/main ]; then
48-
mkdir -p ${dir}/documents/smarty/main
49-
fi
50-
if [ ! -d ${dir}/documents/temp ]; then
51-
mkdir -p ${dir}/documents/temp
52-
fi
15+
mkdir -p "${dir}documents/certificates" \
16+
"${dir}documents/couchdb" \
17+
"${dir}documents/custom_menus/patient_menus" \
18+
"${dir}documents/edi" \
19+
"${dir}documents/era" \
20+
"${dir}documents/letter_templates" \
21+
"${dir}documents/logs_and_misc/methods" \
22+
"${dir}documents/mpdf/pdf_tmp" \
23+
"${dir}documents/onsite_portal_documents/templates" \
24+
"${dir}documents/procedure_results" \
25+
"${dir}documents/smarty/gacl" \
26+
"${dir}documents/smarty/main" \
27+
"${dir}documents/temp"
5328
echo "Completed: Ensure have all directories in ${sitename}"
5429

5530
# Update new directory structure
31+
# Move contents to new location (silently skip if dir missing/empty), then remove old dir
5632
echo "Start: Update new directory structure in ${sitename}"
57-
if [ -d ${dir}/era ]; then
58-
if [ "$(ls ${dir}/era)" ]; then
59-
mv -f ${dir}/era/* ${dir}/documents/era/
60-
fi
61-
rm -rf ${dir}/era
62-
fi
63-
if [ -d ${dir}/edi ]; then
64-
if [ "$(ls ${dir}/edi)" ]; then
65-
mv -f ${dir}/edi/* ${dir}/documents/edi/
66-
fi
67-
rm -rf ${dir}/edi
68-
fi
69-
if [ -d ${dir}/letter_templates ]; then
70-
if [ "$(ls ${dir}/letter_templates)" ]; then
71-
if [ -f ${dir}/letter_templates/custom_pdf.php ]; then
72-
mv -f ${dir}/letter_templates/custom_pdf.php ${dir}/
73-
fi
74-
mv -f ${dir}/letter_templates/* ${dir}/documents/letter_templates/
75-
fi
76-
rm -rf ${dir}/letter_templates
77-
fi
78-
if [ -d ${dir}/procedure_results ]; then
79-
if [ "$(ls ${dir}/procedure_results)" ]; then
80-
mv -f ${dir}/procedure_results/* ${dir}/documents/procedure_results/
81-
fi
82-
rm -rf ${dir}/procedure_results
83-
fi
33+
mv -f "${dir}era"/* "${dir}documents/era/" 2>/dev/null || true
34+
rm -rf "${dir}era/"
35+
mv -f "${dir}edi"/* "${dir}documents/edi/" 2>/dev/null || true
36+
rm -rf "${dir}edi/"
37+
mv -f "${dir}letter_templates/custom_pdf.php" "${dir}" 2>/dev/null || true
38+
mv -f "${dir}letter_templates"/* "${dir}documents/letter_templates/" 2>/dev/null || true
39+
rm -rf "${dir}letter_templates/"
40+
mv -f "${dir}procedure_results"/* "${dir}documents/procedure_results/" 2>/dev/null || true
41+
rm -rf "${dir}procedure_results/"
8442
echo "Completed: Update new directory structure in ${sitename}"
8543

8644
# Clear smarty cache
8745
echo "Start: Clear smarty cache in ${sitename}"
88-
rm -fr ${dir}/documents/smarty/gacl/*
89-
rm -fr ${dir}/documents/smarty/main/*
46+
rm -fr "${dir}documents/smarty/gacl"/* "${dir}documents/smarty/main"/*
9047
echo "Completed: Clear smarty cache in ${sitename}"
9148
done
9249

9350
# Fix permissions
94-
echo "Start: Fix permissions"
51+
echo 'Start: Fix permissions'
9552
chown -R apache:root /var/www/localhost/htdocs/openemr/sites/
96-
echo "Completed: Fix permissions"
53+
echo 'Completed: Fix permissions'
9754

9855
# Perform database upgrade on each directory in sites/
99-
for dirdata in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -type d ); do
100-
sitename=$(basename "${dirdata}")
56+
for dir in /var/www/localhost/htdocs/openemr/sites/*/; do
57+
sitename=${dir%/}
58+
sitename=${sitename##*/}
10159

10260
# Upgrade database
10361
echo "Start: Upgrade database for ${sitename} from ${priorOpenemrVersion}"
@@ -111,4 +69,4 @@ for dirdata in $(find /var/www/localhost/htdocs/openemr/sites/* -maxdepth 0 -typ
11169
echo "Completed: Upgrade database for ${sitename} from ${priorOpenemrVersion}"
11270
done
11371

114-
echo "Completed: Upgrade to docker-version 1"
72+
echo 'Completed: Upgrade to docker-version 1'

0 commit comments

Comments
 (0)