From b32a18a6aefa2863684183d8164d68063d7f59b3 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Mon, 22 Aug 2022 09:15:44 -0500 Subject: [PATCH] Update 01-migrations Fix broken bash syntax --- root/etc/cont-init.d/01-migrations | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/root/etc/cont-init.d/01-migrations b/root/etc/cont-init.d/01-migrations index 4ab4464..aaf084a 100755 --- a/root/etc/cont-init.d/01-migrations +++ b/root/etc/cont-init.d/01-migrations @@ -5,25 +5,25 @@ MIGRATIONS_HISTORY="/config/.migrations" echo "[migrations] started" -if [ ! -d $MIGRATIONS_DIR ]; then +if [[ ! -d ${MIGRATIONS_DIR} ]]; then echo "[migrations] no migrations found" exit fi -for MIGRATION in $(ls -1 ${MIGRATIONS_DIR}/* | sort -n); do +for MIGRATION in $(find ${MIGRATIONS_DIR}/* | sort -n); do NAME="$(basename "${MIGRATION}")" - if [ -f $MIGRATIONS_HISTORY ] && grep -Fxq "$NAME" $MIGRATIONS_HISTORY; then + if [[ -f ${MIGRATIONS_HISTORY} ]] && grep -Fxq "${NAME}" ${MIGRATIONS_HISTORY}; then echo "[migrations] ${NAME}: skipped" continue fi echo "[migrations] ${NAME}: executing..." - chmod +x $MIGRATION - EXIT_CODE=$(/bin/bash ${MIGRATION}; echo $?) - if [ $EXIT_CODE -ne 0 ]; then - echo "[migrations] ${NAME}: failed with exit code $EXIT_CODE, contact support" - exit $EXIT_CODE + chmod +x "${MIGRATION}" + EXIT_CODE=$(/bin/bash "${MIGRATION}"; echo $?) + if [[ ${EXIT_CODE} -ne 0 ]]; then + echo "[migrations] ${NAME}: failed with exit code ${EXIT_CODE}, contact support" + exit "${EXIT_CODE}" fi - echo $NAME >> $MIGRATIONS_HISTORY + echo "${NAME}" >> ${MIGRATIONS_HISTORY} echo "[migrations] ${NAME}: succeeded" done