Skip to content

fix(shell): SC2292; use [[ in bash #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docker/mysql-xtrabackup-final/xbackup-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@

exec > /tmp/xtrabackup-launch.log 2>&1

cd /root

Check warning on line 5 in docker/mysql-xtrabackup-final/xbackup-wrapper.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

# if you recover into a clean system, initial xbackup.sh init was run back then and should not repeat
if [ -f restore-process-complete ]; then
if [ ! -f xtrabackup.database.txt ]; then
if [[ -f restore-process-complete ]]; then
if [[ ! -f xtrabackup.database.txt ]]; then
echo openemr > xtrabackup.database.txt
chmod 600 xtrabackup.database.txt
fi
touch allsetup.ok
rm restore-process-complete
fi

if [ ! -f allsetup.ok ]; then
if [[ ! -f allsetup.ok ]]; then
./xbackup.sh -u openemr -a && ./xbackup.sh -t full && touch allsetup.ok && exit 0
exit 1
fi

if [ -f force-full-backup ]; then
if [[ -f force-full-backup ]]; then
rm force-full-backup
./xbackup.sh -t full
exit $?
fi

# I don't like forcing it like this, but if the backup fails one day, we need to try it the next
# here's the problem: manual run during an automated run will cause destruction and havoc and woe
if [ $(date +%u) = 7 ]; then
if [[ $(date +%u) = 7 ]]; then

Check warning on line 30 in docker/mysql-xtrabackup-final/xbackup-wrapper.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
./xbackup.sh -t full -f
else
./xbackup.sh -t incr -f
Expand Down
30 changes: 15 additions & 15 deletions docker/mysql-xtrabackup/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
shopt -s nullglob

# if command starts with an option, prepend mysqld
if [ "${1:0:1}" = '-' ]; then
if [[ "${1:0:1}" = '-' ]]; then
set -- mysqld "$@"
fi

# skip setup if they want an option that stops mysqld
wantHelp=
for arg; do
case "${arg}" in

Check warning on line 13 in docker/mysql-xtrabackup/docker-entrypoint.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Consider adding a default *) case, even if it just exits with error.
-'?'|--help|--print-defaults|-V|--version)
wantHelp=1
break
Expand All @@ -26,14 +26,14 @@
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
if [[ "${!var:-}" ]] && [[ "${!fileVar:-}" ]]; then

Check warning on line 29 in docker/mysql-xtrabackup/docker-entrypoint.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Prefer explicit -n to check non-empty string (or use =/-ne to check boolean/integer).

Check warning on line 29 in docker/mysql-xtrabackup/docker-entrypoint.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Prefer explicit -n to check non-empty string (or use =/-ne to check boolean/integer).
echo >&2 "error: both ${var} and ${fileVar} are set (but are exclusive)"
exit 1
fi
local val="${def}"
if [ "${!var:-}" ]; then
if [[ "${!var:-}" ]]; then

Check warning on line 34 in docker/mysql-xtrabackup/docker-entrypoint.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Prefer explicit -n to check non-empty string (or use =/-ne to check boolean/integer).
val="${!var}"
elif [ "${!fileVar:-}" ]; then
elif [[ "${!fileVar:-}" ]]; then

Check warning on line 36 in docker/mysql-xtrabackup/docker-entrypoint.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Prefer explicit -n to check non-empty string (or use =/-ne to check boolean/integer).
val="$(< "${!fileVar}")"
fi
export "${var}"="${val}"
Expand All @@ -55,17 +55,17 @@
# latter only show values present in config files, and not server defaults
_get_config() {
local conf="$1"; shift
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "'"${conf}"'" { print $2; exit }'

Check warning on line 58 in docker/mysql-xtrabackup/docker-entrypoint.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
}

# allow the container to be started with `--user`
if [ "$1" = 'mysqld' -a -z "${wantHelp}" -a "$(id -u)" = '0' ]; then

Check warning on line 62 in docker/mysql-xtrabackup/docker-entrypoint.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

Check warning on line 62 in docker/mysql-xtrabackup/docker-entrypoint.sh

View workflow job for this annotation

GitHub Actions / ShellCheck

Prefer [[ ]] over [ ] for tests in Bash/Ksh.
_check_config "$@"
DATADIR="$(_get_config 'datadir' "$@")"
mkdir -p "${DATADIR}"
chown -R mysql:mysql "${DATADIR}"

if [ -f /root/pending-restore ]; then
if [[ -f /root/pending-restore ]]; then
/root/xrecovery-final.sh
fi

Expand All @@ -78,7 +78,7 @@
# Get config
DATADIR="$(_get_config 'datadir' "$@")"

if [ ! -d "${DATADIR}/mysql" ]; then
if [[ ! -d "${DATADIR}/mysql" ]]; then
file_env 'MYSQL_ROOT_PASSWORD'
if [ -z "${MYSQL_ROOT_PASSWORD}" -a -z "${MYSQL_ALLOW_EMPTY_PASSWORD}" -a -z "${MYSQL_RANDOM_ROOT_PASSWORD}" ]; then
echo >&2 'error: database is uninitialized and password option is not specified '
Expand All @@ -92,7 +92,7 @@
"$@" --initialize-insecure
echo 'Database initialized'

if command -v mysql_ssl_rsa_setup > /dev/null && [ ! -e "${DATADIR}/server-key.pem" ]; then
if command -v mysql_ssl_rsa_setup > /dev/null && [[ ! -e "${DATADIR}/server-key.pem" ]]; then
# https://github.com/mysql/mysql-server/blob/23032807537d8dd8ee4ec1c4d40f0633cd4e12f9/packaging/deb-in/extra/mysql-systemd-start#L81-L84
echo 'Initializing certificates'
mysql_ssl_rsa_setup --datadir="${DATADIR}"
Expand All @@ -112,17 +112,17 @@
echo 'MySQL init process in progress...'
sleep 1
done
if [ "${i}" = 0 ]; then
if [[ "${i}" = 0 ]]; then
echo >&2 'MySQL init process failed.'
exit 1
fi

if [ -z "${MYSQL_INITDB_SKIP_TZINFO}" ]; then
if [[ -z "${MYSQL_INITDB_SKIP_TZINFO}" ]]; then
# sed is for https://bugs.mysql.com/bug.php?id=20545
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql
fi

if [ ! -z "${MYSQL_RANDOM_ROOT_PASSWORD}" ]; then
if [[ ! -z "${MYSQL_RANDOM_ROOT_PASSWORD}" ]]; then
export MYSQL_ROOT_PASSWORD="$(pwgen -1 32)"
echo "GENERATED ROOT PASSWORD: ${MYSQL_ROOT_PASSWORD}"
fi
Expand Down Expand Up @@ -151,12 +151,12 @@

printf '%s\n' "${sql[@]}" | "${mysql[@]}"

if [ ! -z "${MYSQL_ROOT_PASSWORD}" ]; then
if [[ ! -z "${MYSQL_ROOT_PASSWORD}" ]]; then
mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
fi

file_env 'MYSQL_DATABASE'
if [ "${MYSQL_DATABASE}" ]; then
if [[ "${MYSQL_DATABASE}" ]]; then
echo "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE}\` ;" | "${mysql[@]}"
mysql+=( "${MYSQL_DATABASE}" )
fi
Expand All @@ -166,7 +166,7 @@
if [ "${MYSQL_USER}" -a "${MYSQL_PASSWORD}" ]; then
echo "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}' ;" | "${mysql[@]}"

if [ "${MYSQL_DATABASE}" ]; then
if [[ "${MYSQL_DATABASE}" ]]; then
echo "GRANT ALL ON \`${MYSQL_DATABASE}\`.* TO '${MYSQL_USER}'@'%' ;" | "${mysql[@]}"
fi

Expand All @@ -184,7 +184,7 @@
echo
done

if [ ! -z "${MYSQL_ONETIME_PASSWORD}" ]; then
if [[ ! -z "${MYSQL_ONETIME_PASSWORD}" ]]; then
"${mysql[@]}" <<< "ALTER USER 'root'@'%' PASSWORD EXPIRE;"
fi
if ! kill -s TERM "${pid}" || ! wait "${pid}"; then
Expand All @@ -198,7 +198,7 @@
fi
fi

if [ -f /root/pending-restore ]; then
if [[ -f /root/pending-restore ]]; then
/root/xrecovery-final.sh
fi

Expand Down
10 changes: 5 additions & 5 deletions docker/mysql-xtrabackup/xbackup-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ exec > /tmp/xtrabackup-launch.log 2>&1
cd /root

# if you recover into a clean system, initial xbackup.sh init was run back then and should not repeat
if [ -f restore-process-complete ]; then
if [ ! -f xtrabackup.database.txt ]; then
if [[ -f restore-process-complete ]]; then
if [[ ! -f xtrabackup.database.txt ]]; then
echo openemr > xtrabackup.database.txt
chmod 600 xtrabackup.database.txt
fi
touch allsetup.ok
rm restore-process-complete
fi

if [ ! -f allsetup.ok ]; then
if [[ ! -f allsetup.ok ]]; then
./xbackup.sh -u openemr -a && ./xbackup.sh -t full && touch allsetup.ok && exit 0
exit 1
fi

if [ -f force-full-backup ]; then
if [[ -f force-full-backup ]]; then
rm force-full-backup
./xbackup.sh -t full
exit $?
fi

# I don't like forcing it like this, but if the backup fails one day, we need to try it the next
# here's the problem: manual run during an automated run will cause destruction and havoc and woe
if [ $(date +%u) = 7 ]; then
if [[ $(date +%u) = 7 ]]; then
./xbackup.sh -t full -f
else
./xbackup.sh -t incr -f
Expand Down
Loading
Loading