Skip to content

Commit 641c315

Browse files
committed
fix(shell): all remaining shellcheck issues
1 parent 8564976 commit 641c315

File tree

7 files changed

+145
-124
lines changed

7 files changed

+145
-124
lines changed

docker/openemr/7.0.3/openemr.sh

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,54 @@ set -e
1212
# shellcheck source=SCRIPTDIR/utilities/devtoolsLibrary.source
1313
. /root/devtoolsLibrary.source
1414

15-
swarm_wait() {
16-
if [ ! -f /var/www/localhost/htdocs/openemr/sites/docker-completed ]; then
17-
# true
18-
return 0
19-
else
20-
# false
21-
return 1
22-
fi
23-
}
15+
# defaults
16+
: "${DEMO_MODE:=no}" \
17+
"${DEVELOPER_TOOLS:=no}" \
18+
"${EASY_DEV_MODE:=no}" \
19+
"${EASY_DEV_MODE_NEW:=no}" \
20+
"${EMPTY:=no}" \
21+
"${FLEX_REPOSITORY_TAG:=}" \
22+
"${FORCE_NO_BUILD_MODE:=no}" \
23+
"${GITHUB_COMPOSER_TOKEN:=}" \
24+
"${GITHUB_COMPOSER_TOKEN_ENCODED:=}" \
25+
"${INSANE_DEV_MODE:=no}" \
26+
"${K8S:=}" \
27+
"${MANUAL_SETUP:=no}" \
28+
"${PHPREDIS_BUILD:=}" \
29+
"${REDIS_PASSWORD:=}" \
30+
"${REDIS_SERVER:=}" \
31+
"${REDIS_TLS:=}" \
32+
"${REDIS_USERNAME:=}" \
33+
"${REDIS_X509:=}" \
34+
"${SWARM_MODE:=no}" \
35+
"${XDEBUG_IDE_KEY:=}" \
36+
"${XDEBUG_ON:=no}"
2437

2538
auto_setup() {
2639
prepareVariables
2740

2841
find . -not -perm 600 -exec chmod 600 {} \+
2942

30-
#create temporary file cache directory for auto_configure.php to use
43+
# create temporary file cache directory for auto_configure.php to use
3144
TMP_FILE_CACHE_LOCATION="/tmp/php-file-cache"
32-
mkdir ${TMP_FILE_CACHE_LOCATION}
33-
34-
#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
45+
mkdir "${TMP_FILE_CACHE_LOCATION}"
46+
47+
# create auto_configure.ini to be able to leverage opcache for operations
48+
{
49+
echo "opcache.enable=1"
50+
echo "opcache.enable_cli=1"
51+
echo "opcache.file_cache=${TMP_FILE_CACHE_LOCATION}"
52+
echo "opcache.file_cache_only=1"
53+
echo "opcache.file_cache_consistency_checks=1"
54+
echo "opcache.enable_file_override=1"
55+
echo "opcache.max_accelerated_files=1000000"
56+
} > auto_configure.ini
4357

4458
#run auto_configure
45-
php auto_configure.php -c auto_configure.ini -f ${CONFIGURATION} || return 1
59+
php auto_configure.php -c auto_configure.ini -f "${CONFIGURATION}" || return 1
4660

4761
#remove temporary file cache directory and auto_configure.ini
48-
rm -r ${TMP_FILE_CACHE_LOCATION}
62+
rm -r "${TMP_FILE_CACHE_LOCATION}"
4963
rm auto_configure.ini
5064

5165
echo "OpenEMR configured."
@@ -66,21 +80,21 @@ auto_setup() {
6680
# - false for the Kubernetes startup job and manual image runs
6781
AUTHORITY=yes
6882
OPERATOR=yes
69-
if [ "${K8S}" = "admin" ]; then
70-
OPERATOR=no
71-
elif [ "${K8S}" = "worker" ]; then
72-
AUTHORITY=no
73-
fi
83+
case "${K8S}" in
84+
admin) OPERATOR=no;;
85+
worker) AUTHORITY=no;;
86+
*) :;;
87+
esac
7488

75-
if [ "${SWARM_MODE}" = "yes" ]; then
89+
if [ "${SWARM_MODE}" = yes ]; then
7690
# atomically test for leadership
7791
set -o noclobber
78-
{ > /var/www/localhost/htdocs/openemr/sites/docker-leader ; } &> /dev/null || AUTHORITY=no
92+
{ : > /var/www/localhost/htdocs/openemr/sites/docker-leader ; } > /dev/null 2>&1 || AUTHORITY=no
7993
set +o noclobber
8094

8195
if [ "${AUTHORITY}" = "no" ] &&
8296
[ ! -f /var/www/localhost/htdocs/openemr/sites/docker-completed ]; then
83-
while swarm_wait; do
97+
until [ -f /var/www/localhost/htdocs/openemr/sites/docker-completed ]; do
8498
echo "Waiting for the docker-leader to finish configuration before proceeding."
8599
sleep 10;
86100
done
@@ -222,13 +236,16 @@ if [ "${AUTHORITY}" = "yes" ]; then
222236
[ "${MANUAL_SETUP}" != "yes" ]; then
223237

224238
echo "Running quick setup!"
225-
while ! auto_setup; do
239+
set +e
240+
# shellcheck disable=SC2310
241+
until auto_setup; do
226242
echo "Couldn't set up. Any of these reasons could be what's wrong:"
227243
echo " - You didn't spin up a MySQL container or connect your OpenEMR container to a mysql instance"
228244
echo " - MySQL is still starting up and wasn't ready for connection yet"
229245
echo " - The Mysql credentials were incorrect"
230246
sleep 1;
231247
done
248+
set -e
232249
echo "Setup Complete!"
233250
fi
234251
fi
@@ -246,13 +263,13 @@ if
246263
while [ "${c}" -le "${DOCKER_VERSION_ROOT}" ]; do
247264
if [ "${c}" -gt "${DOCKER_VERSION_SITES}" ] ; then
248265
echo "Start: Processing fsupgrade-${c}.sh upgrade script"
249-
sh /root/fsupgrade-${c}.sh
266+
sh "/root/fsupgrade-${c}.sh"
250267
echo "Completed: Processing fsupgrade-${c}.sh upgrade script"
251268
fi
252269
c=$(( c + 1 ))
253270
done
254-
echo -n ${DOCKER_VERSION_ROOT} > /var/www/localhost/htdocs/openemr/sites/default/docker-version
255-
echo "Completed upgrade"
271+
printf '%s' "${DOCKER_VERSION_ROOT}" > /var/www/localhost/htdocs/openemr/sites/default/docker-version
272+
echo 'Completed upgrade'
256273
fi
257274
fi
258275

@@ -282,7 +299,8 @@ if [ "${REDIS_SERVER}" != "" ] &&
282299
phpize83
283300
# note for php 8.3, needed to change from './configure --enable-redis-igbinary' to:
284301
./configure --with-php-config=/usr/bin/php-config83 --enable-redis-igbinary
285-
make -j $(nproc --all)
302+
num_procs=$(nproc --all)
303+
make -j "${num_procs}"
286304
make install
287305
echo "extension=redis" > /etc/php83/conf.d/20_redis.ini
288306
rm -fr /tmpredis/phpredis
@@ -333,7 +351,7 @@ fi
333351

334352
if
335353
[ "${AUTHORITY}" = "yes" ] ||
336-
[ "${SWARM_MODE}" = "yes" ]; then
354+
[ "${SWARM_MODE}" = yes ]; then
337355
if
338356
[ "${CONFIG}" = "1" ] &&
339357
[ "${MANUAL_SETUP}" != "yes" ]; then
@@ -355,7 +373,7 @@ if
355373
# Set file and directory permissions
356374
# Note this is only done once in swarm mode (to prevent breakage) since is a shared volume.
357375
if
358-
[ "${SWARM_MODE}" != "yes" ] ||
376+
[ "${SWARM_MODE}" != yes ] ||
359377
[ ! -f /var/www/localhost/htdocs/openemr/sites/docker-completed ]; then
360378
echo "Setting sites/default/documents permissions to 700"
361379
find sites/default/documents -not -perm 700 -exec chmod 700 {} \+
@@ -377,7 +395,7 @@ fi
377395

378396
# Note this is only done once in swarm mode (to prevent breakage) since is a shared volume.
379397
if
380-
[ "${SWARM_MODE}" != "yes" ] ||
398+
[ "${SWARM_MODE}" != yes ] ||
381399
[ ! -f /var/www/localhost/htdocs/openemr/sites/docker-completed ]; then
382400
if [ -f /var/www/localhost/htdocs/openemr/sites/default/documents/certificates/mysql-ca ]; then
383401
# for specific issue in docker and kubernetes that is required for successful openemr adodb/laminas connections
@@ -429,13 +447,13 @@ else
429447
fi
430448

431449
if [ "${AUTHORITY}" = "yes" ] &&
432-
[ "${SWARM_MODE}" = "yes" ]; then
450+
[ "${SWARM_MODE}" = yes ]; then
433451
# Set flag that the docker-leader configuration is complete
434452
touch /var/www/localhost/htdocs/openemr/sites/docker-completed
435453
rm -f /var/www/localhost/htdocs/openemr/sites/docker-leader
436454
fi
437455

438-
if [ "${SWARM_MODE}" = "yes" ]; then
456+
if [ "${SWARM_MODE}" = yes ]; then
439457
# Set flag that the instance is ready when in swarm mode
440458
echo
441459
echo "swarm mode on: this instance is ready"

docker/openemr/7.0.3/utilities/devtoolsLibrary.source

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ resetOpenemr() {
8585
installOpenemr() {
8686
echo "Re-installing OpenEMR"
8787
cp /root/auto_configure.php /var/www/localhost/htdocs/
88-
php /var/www/localhost/htdocs/auto_configure.php -f ${CONFIGURATION}
88+
php /var/www/localhost/htdocs/auto_configure.php -f "${CONFIGURATION}"
8989
rm -f /var/www/localhost/htdocs/auto_configure.php
9090
}
9191

@@ -259,21 +259,20 @@ generateMultisiteBank() {
259259
# Activate older versions of InstallerAuto that require `sed` activation.
260260
sed -i "s@exit;@//exit;@" /var/www/localhost/htdocs/openemr/contrib/util/installScripts/InstallerAuto.php
261261
a=1
262-
while [ ${a} -le "$1" ]
263-
do
262+
while [ "${a}" -le "$1" ]; do
264263
run="run${a}"
265264
echo "dropping ${run} sql database, sql user, and directory if they already exist (just ignore any errors that are displayed)"
266265
mysql -u "${CUSTOM_ROOT_USER}" --password="${MYSQL_ROOT_PASS}" -h "${MYSQL_HOST}" -P "${CUSTOM_PORT}" -e "DROP DATABASE ${run}"
267266
mysql -u "${CUSTOM_ROOT_USER}" --password="${MYSQL_ROOT_PASS}" -h "${MYSQL_HOST}" -P "${CUSTOM_PORT}" -e "DROP USER '${run}'"
268-
rm -fr /var/www/localhost/htdocs/openemr/sites/${run}
267+
rm -fr "/var/www/localhost/htdocs/openemr/sites/${run}"
269268
rm /tmp/setup_dump.sql
270269
echo "adding ${run} multisite"
271-
php /var/www/localhost/htdocs/openemr/contrib/util/installScripts/InstallerAuto.php rootpass="${MYSQL_ROOT_PASS}" server="${MYSQL_HOST}" port="${CUSTOM_PORT}" loginhost=% login=${run} pass=${run} dbname=${run} site=${run} source_site_id=default clone_database=yes
272-
chown -R apache /var/www/localhost/htdocs/openemr/sites/${run}
273-
find /var/www/localhost/htdocs/openemr/sites/${run} -type d -print0 | xargs -0 chmod 500
274-
find /var/www/localhost/htdocs/openemr/sites/${run} -type f -print0 | xargs -0 chmod 400
275-
find /var/www/localhost/htdocs/openemr/sites/${run}/documents -type d -print0 | xargs -0 chmod 700
276-
find /var/www/localhost/htdocs/openemr/sites/${run}/documents -type f -print0 | xargs -0 chmod 700
270+
php /var/www/localhost/htdocs/openemr/contrib/util/installScripts/InstallerAuto.php rootpass="${MYSQL_ROOT_PASS}" server="${MYSQL_HOST}" port="${CUSTOM_PORT}" loginhost=% "login=${run}" "pass=${run}" "dbname=${run}" "site=${run}" source_site_id=default clone_database=yes
271+
chown -R apache "/var/www/localhost/htdocs/openemr/sites/${run}"
272+
find "/var/www/localhost/htdocs/openemr/sites/${run}" -type d -print0 | xargs -0 chmod 500
273+
find "/var/www/localhost/htdocs/openemr/sites/${run}" -type f -print0 | xargs -0 chmod 400
274+
find "/var/www/localhost/htdocs/openemr/sites/${run}/documents" -type d -print0 | xargs -0 chmod 700
275+
find "/var/www/localhost/htdocs/openemr/sites/${run}/documents" -type f -print0 | xargs -0 chmod 700
277276
echo "completed adding ${run} multisite"
278277
a=$((a + 1))
279278
done

docker/openemr/7.0.4/utilities/devtoolsLibrary.source

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ resetOpenemr() {
8585
installOpenemr() {
8686
echo "Re-installing OpenEMR"
8787
cp /root/auto_configure.php /var/www/localhost/htdocs/
88-
php /var/www/localhost/htdocs/auto_configure.php -f ${CONFIGURATION}
88+
php /var/www/localhost/htdocs/auto_configure.php -f "${CONFIGURATION}"
8989
rm -f /var/www/localhost/htdocs/auto_configure.php
9090
}
9191

@@ -260,21 +260,21 @@ generateMultisiteBank() {
260260
# Activate older versions of InstallerAuto that require `sed` activation.
261261
sed -i "s@exit;@//exit;@" /var/www/localhost/htdocs/openemr/contrib/util/installScripts/InstallerAuto.php
262262
a=1
263-
while [ ${a} -le "$1" ]
263+
while [ "${a}" -le "$1" ]
264264
do
265265
run="run${a}"
266266
echo "dropping ${run} sql database, sql user, and directory if they already exist (just ignore any errors that are displayed)"
267267
mariadb --skip-ssl -u "${CUSTOM_ROOT_USER}" --password="${MYSQL_ROOT_PASS}" -h "${MYSQL_HOST}" -P "${CUSTOM_PORT}" -e "DROP DATABASE ${run}"
268268
mariadb --skip-ssl -u "${CUSTOM_ROOT_USER}" --password="${MYSQL_ROOT_PASS}" -h "${MYSQL_HOST}" -P "${CUSTOM_PORT}" -e "DROP USER '${run}'"
269-
rm -fr /var/www/localhost/htdocs/openemr/sites/${run}
269+
rm -fr "/var/www/localhost/htdocs/openemr/sites/${run}"
270270
rm /tmp/setup_dump.sql
271271
echo "adding ${run} multisite"
272-
php /var/www/localhost/htdocs/openemr/contrib/util/installScripts/InstallerAuto.php rootpass="${MYSQL_ROOT_PASS}" server="${MYSQL_HOST}" port="${CUSTOM_PORT}" loginhost=% login=${run} pass=${run} dbname=${run} site=${run} source_site_id=default clone_database=yes
273-
chown -R apache /var/www/localhost/htdocs/openemr/sites/${run}
274-
find /var/www/localhost/htdocs/openemr/sites/${run} -type d -print0 | xargs -0 chmod 500
275-
find /var/www/localhost/htdocs/openemr/sites/${run} -type f -print0 | xargs -0 chmod 400
276-
find /var/www/localhost/htdocs/openemr/sites/${run}/documents -type d -print0 | xargs -0 chmod 700
277-
find /var/www/localhost/htdocs/openemr/sites/${run}/documents -type f -print0 | xargs -0 chmod 700
272+
php /var/www/localhost/htdocs/openemr/contrib/util/installScripts/InstallerAuto.php rootpass="${MYSQL_ROOT_PASS}" server="${MYSQL_HOST}" port="${CUSTOM_PORT}" loginhost=% "login=${run}" "pass=${run}" "dbname=${run}" "site=${run}" source_site_id=default clone_database=yes
273+
chown -R apache "/var/www/localhost/htdocs/openemr/sites/${run}"
274+
find "/var/www/localhost/htdocs/openemr/sites/${run}" -type d -print0 | xargs -0 chmod 500
275+
find "/var/www/localhost/htdocs/openemr/sites/${run}" -type f -print0 | xargs -0 chmod 400
276+
find "/var/www/localhost/htdocs/openemr/sites/${run}/documents" -type d -print0 | xargs -0 chmod 700
277+
find "/var/www/localhost/htdocs/openemr/sites/${run}/documents" -type f -print0 | xargs -0 chmod 700
278278
echo "completed adding ${run} multisite"
279279
a=$((a + 1))
280280
done

docker/openemr/flex/openemr.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set -e
3535
"${INSANE_DEV_MODE:=no}" \
3636
"${K8S:=}" \
3737
"${MANUAL_SETUP:=no}" \
38+
"${PHP_VERSION_ABBR:=}" \
3839
"${REDIS_PASSWORD:=}" \
3940
"${REDIS_SERVER:=}" \
4041
"${REDIS_USERNAME:=}" \
@@ -492,8 +493,8 @@ if [ "${REDIS_SERVER}" != "" ] &&
492493
echo "redis setup"
493494
fi
494495

495-
sed -i "[email protected]_handler = [email protected]_handler = redis@" /etc/php${PHP_VERSION_ABBR}/php.ini
496-
sed -i 's@;session.save_path = "/tmp"@session.save_path = "'"${REDIS_PATH}"'"@"' /etc/php${PHP_VERSION_ABBR}/php.ini
496+
sed -i "[email protected]_handler = [email protected]_handler = redis@" "/etc/php${PHP_VERSION_ABBR}/php.ini"
497+
sed -i 's@;session.save_path = "/tmp"@session.save_path = "'"${REDIS_PATH}"'"@"' "/etc/php${PHP_VERSION_ABBR}/php.ini"
497498
# Ensure only configure this one time
498499
touch /etc/php-redis-configured
499500
fi
@@ -503,14 +504,14 @@ if [ "${XDEBUG_IDE_KEY}" != "" ] ||
503504
sh xdebug.sh
504505
#also need to turn off opcache since it can not be turned on with xdebug
505506
if [ ! -f /etc/php-opcache-jit-configured ]; then
506-
echo "opcache.enable=0" >> /etc/php${PHP_VERSION_ABBR}/php.ini
507+
echo "opcache.enable=0" >> "/etc/php${PHP_VERSION_ABBR}/php.ini"
507508
touch /etc/php-opcache-jit-configured
508509
fi
509510
else
510511
# 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))
511512
if [ ! -f /etc/php-opcache-jit-configured ]; then
512-
echo "opcache.jit=tracing" >> /etc/php${PHP_VERSION_ABBR}/php.ini
513-
echo "opcache.jit_buffer_size=100M" >> /etc/php${PHP_VERSION_ABBR}/php.ini
513+
echo "opcache.jit=tracing" >> "/etc/php${PHP_VERSION_ABBR}/php.ini"
514+
echo "opcache.jit_buffer_size=100M" >> "/etc/php${PHP_VERSION_ABBR}/php.ini"
514515
touch /etc/php-opcache-jit-configured
515516
fi
516517
fi

0 commit comments

Comments
 (0)