Skip to content

Commit 0590ada

Browse files
authored
fix(shell): SC2292; use [[ in bash (#458)
1 parent 441d7b3 commit 0590ada

File tree

13 files changed

+154
-154
lines changed

13 files changed

+154
-154
lines changed

docker/mysql-xtrabackup-final/xbackup-wrapper.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ exec > /tmp/xtrabackup-launch.log 2>&1
55
cd /root
66

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

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

22-
if [ -f force-full-backup ]; then
22+
if [[ -f force-full-backup ]]; then
2323
rm force-full-backup
2424
./xbackup.sh -t full
2525
exit $?
2626
fi
2727

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

docker/mysql-xtrabackup/docker-entrypoint.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -eo pipefail
33
shopt -s nullglob
44

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

@@ -26,14 +26,14 @@ file_env() {
2626
local var="$1"
2727
local fileVar="${var}_FILE"
2828
local def="${2:-}"
29-
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
29+
if [[ "${!var:-}" ]] && [[ "${!fileVar:-}" ]]; then
3030
echo >&2 "error: both ${var} and ${fileVar} are set (but are exclusive)"
3131
exit 1
3232
fi
3333
local val="${def}"
34-
if [ "${!var:-}" ]; then
34+
if [[ "${!var:-}" ]]; then
3535
val="${!var}"
36-
elif [ "${!fileVar:-}" ]; then
36+
elif [[ "${!fileVar:-}" ]]; then
3737
val="$(< "${!fileVar}")"
3838
fi
3939
export "${var}"="${val}"
@@ -65,7 +65,7 @@ if [ "$1" = 'mysqld' -a -z "${wantHelp}" -a "$(id -u)" = '0' ]; then
6565
mkdir -p "${DATADIR}"
6666
chown -R mysql:mysql "${DATADIR}"
6767

68-
if [ -f /root/pending-restore ]; then
68+
if [[ -f /root/pending-restore ]]; then
6969
/root/xrecovery-final.sh
7070
fi
7171

@@ -78,7 +78,7 @@ if [ "$1" = 'mysqld' -a -z "${wantHelp}" ]; then
7878
# Get config
7979
DATADIR="$(_get_config 'datadir' "$@")"
8080

81-
if [ ! -d "${DATADIR}/mysql" ]; then
81+
if [[ ! -d "${DATADIR}/mysql" ]]; then
8282
file_env 'MYSQL_ROOT_PASSWORD'
8383
if [ -z "${MYSQL_ROOT_PASSWORD}" -a -z "${MYSQL_ALLOW_EMPTY_PASSWORD}" -a -z "${MYSQL_RANDOM_ROOT_PASSWORD}" ]; then
8484
echo >&2 'error: database is uninitialized and password option is not specified '
@@ -92,7 +92,7 @@ if [ "$1" = 'mysqld' -a -z "${wantHelp}" ]; then
9292
"$@" --initialize-insecure
9393
echo 'Database initialized'
9494

95-
if command -v mysql_ssl_rsa_setup > /dev/null && [ ! -e "${DATADIR}/server-key.pem" ]; then
95+
if command -v mysql_ssl_rsa_setup > /dev/null && [[ ! -e "${DATADIR}/server-key.pem" ]]; then
9696
# https://github.com/mysql/mysql-server/blob/23032807537d8dd8ee4ec1c4d40f0633cd4e12f9/packaging/deb-in/extra/mysql-systemd-start#L81-L84
9797
echo 'Initializing certificates'
9898
mysql_ssl_rsa_setup --datadir="${DATADIR}"
@@ -112,17 +112,17 @@ if [ "$1" = 'mysqld' -a -z "${wantHelp}" ]; then
112112
echo 'MySQL init process in progress...'
113113
sleep 1
114114
done
115-
if [ "${i}" = 0 ]; then
115+
if [[ "${i}" = 0 ]]; then
116116
echo >&2 'MySQL init process failed.'
117117
exit 1
118118
fi
119119

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

125-
if [ ! -z "${MYSQL_RANDOM_ROOT_PASSWORD}" ]; then
125+
if [[ ! -z "${MYSQL_RANDOM_ROOT_PASSWORD}" ]]; then
126126
export MYSQL_ROOT_PASSWORD="$(pwgen -1 32)"
127127
echo "GENERATED ROOT PASSWORD: ${MYSQL_ROOT_PASSWORD}"
128128
fi
@@ -151,12 +151,12 @@ if [ "$1" = 'mysqld' -a -z "${wantHelp}" ]; then
151151

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

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

158158
file_env 'MYSQL_DATABASE'
159-
if [ "${MYSQL_DATABASE}" ]; then
159+
if [[ "${MYSQL_DATABASE}" ]]; then
160160
echo "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE}\` ;" | "${mysql[@]}"
161161
mysql+=( "${MYSQL_DATABASE}" )
162162
fi
@@ -166,7 +166,7 @@ if [ "$1" = 'mysqld' -a -z "${wantHelp}" ]; then
166166
if [ "${MYSQL_USER}" -a "${MYSQL_PASSWORD}" ]; then
167167
echo "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}' ;" | "${mysql[@]}"
168168

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

@@ -184,7 +184,7 @@ if [ "$1" = 'mysqld' -a -z "${wantHelp}" ]; then
184184
echo
185185
done
186186

187-
if [ ! -z "${MYSQL_ONETIME_PASSWORD}" ]; then
187+
if [[ ! -z "${MYSQL_ONETIME_PASSWORD}" ]]; then
188188
"${mysql[@]}" <<< "ALTER USER 'root'@'%' PASSWORD EXPIRE;"
189189
fi
190190
if ! kill -s TERM "${pid}" || ! wait "${pid}"; then
@@ -198,7 +198,7 @@ if [ "$1" = 'mysqld' -a -z "${wantHelp}" ]; then
198198
fi
199199
fi
200200

201-
if [ -f /root/pending-restore ]; then
201+
if [[ -f /root/pending-restore ]]; then
202202
/root/xrecovery-final.sh
203203
fi
204204

docker/mysql-xtrabackup/xbackup-wrapper.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ exec > /tmp/xtrabackup-launch.log 2>&1
55
cd /root
66

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

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

22-
if [ -f force-full-backup ]; then
22+
if [[ -f force-full-backup ]]; then
2323
rm force-full-backup
2424
./xbackup.sh -t full
2525
exit $?
2626
fi
2727

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

0 commit comments

Comments
 (0)