From 51844316dfe1ad62db531dfd8b96c0e0a00f3611 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 14 Sep 2020 21:03:55 +0200 Subject: [PATCH] IDEMPIERE-4441 More shellcheck (#254) Fix issue caused by previous commit - RUN_SyncDB broken --- .../utils.unix/oracle/MonitoredSyncDB.sh | 19 ++++++------------- .../utils.unix/oracle/SyncDB.sh | 17 +++++------------ .../utils.unix/postgresql/MonitoredSyncDB.sh | 17 +++++------------ .../utils.unix/postgresql/SyncDB.sh | 17 +++++------------ 4 files changed, 21 insertions(+), 49 deletions(-) diff --git a/org.adempiere.server-feature/utils.unix/oracle/MonitoredSyncDB.sh b/org.adempiere.server-feature/utils.unix/oracle/MonitoredSyncDB.sh index e285417cd3..497bcf0188 100755 --- a/org.adempiere.server-feature/utils.unix/oracle/MonitoredSyncDB.sh +++ b/org.adempiere.server-feature/utils.unix/oracle/MonitoredSyncDB.sh @@ -79,7 +79,7 @@ apply_script() OUTFILE="$2" FILE="$3" echo "Applying $SCRIPT" - $CMD > "$OUTFILE" 2>&1 < "$SCRIPT" + $CMD < "$SCRIPT" > "$OUTFILE" 2>&1 APPLIED=Y if grep -E "$ERROR_STRINGS" "$OUTFILE" > /dev/null 2>&1 then @@ -158,7 +158,7 @@ select count(*) from ad_migrationscript where name='$BASEFIX';" | $SILENTCMD | s notify_error() { - echo -e "$MSGERROR" + printf '%s' "$MSGERROR" printf '\n%s\n%s\n' "Error=true" "Errors were found during the process (see message above) - please inform and integrate a fix to restart this process again" SUPPORTEMAIL=$(echo "set heading off set feedback off @@ -181,7 +181,7 @@ select supportemail from ad_system;" | $SILENTCMD | sed -e 's:^ ::' | grep -v '^ echo "Content-Type: text/plain; charset=\"UTF-8\"" echo "Content-Transfer-Encoding: 7bit" echo "Content-Disposition: inline" - echo -e "$MSGERROR" + printf '%s' "$MSGERROR" echo "=================================" cat "$ATTACH" echo @@ -222,15 +222,8 @@ set echo off select name from ad_migrationscript;" | $SILENTCMD | sed -e 's:^ ::' | grep -v '^$' | sort > $TMPFOLDER/lisDB_$$.txt # Create list of files in the migration folder -: > $TMPFOLDER/lisFS_$$.txt -find . -type d -name "$ADEMPIERE_DB_PATH" | grep -v "./processes_post_migration/$ADEMPIERE_DB_PATH" | while read -r FOLDER -do - cd "${FOLDER}" || exit 1 - ls -- *.sql 2>/dev/null >> $TMPFOLDER/lisFS_$$.txt - cd "$DIR_SCRIPTS" || exit 1 -done -sort -o $TMPFOLDER/lisFS_$$.txt $TMPFOLDER/lisFS_$$.txt -sort -o $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisDB_$$.txt +find . -type f -wholename "*/${ADEMPIERE_DB_PATH}/*.sql" ! -wholename "./processes_post_migration/${ADEMPIERE_DB_PATH}/*" | sed -e 's:.*/::' | sort > $TMPFOLDER/lisFS_$$.txt + MSGERROR="" # extract and process the list of pending files comm -13 $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisFS_$$.txt > $TMPFOLDER/lisPENDING_$$.txt @@ -288,7 +281,7 @@ then do OUTFILE=$TMPFOLDER/SyncDB_out_$$/$(basename "$FILE" .sql).out echo "Applying $FILE" - $CMD > "$OUTFILE" 2>&1 < "$FILE" + $CMD < "$FILE" > "$OUTFILE" 2>&1 if grep -E "$ERROR_STRINGS" "$OUTFILE" > /dev/null 2>&1 then echo "Found error in $SCRIPT" diff --git a/org.adempiere.server-feature/utils.unix/oracle/SyncDB.sh b/org.adempiere.server-feature/utils.unix/oracle/SyncDB.sh index 9cec7405fe..1df67168bd 100644 --- a/org.adempiere.server-feature/utils.unix/oracle/SyncDB.sh +++ b/org.adempiere.server-feature/utils.unix/oracle/SyncDB.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Author: Carlos Ruiz - globalqss # Script to synchronize the database for with latest migration scripts @@ -54,15 +54,8 @@ set echo off select name from ad_migrationscript;" | $SILENTCMD | sed -e 's:^ ::' | grep -v '^$' | sort > $TMPFOLDER/lisDB_$$.txt # Create list of files in the migration folder -: > $TMPFOLDER/lisFS_$$.txt -find . -type d -name "$ADEMPIERE_DB_PATH" | grep -v "./processes_post_migration/$ADEMPIERE_DB_PATH" | while read -r FOLDER -do - cd "${FOLDER}" || (echo "ERROR: Cannot change to folder $FOLDER"; exit 1) - ls -- *.sql 2>/dev/null >> $TMPFOLDER/lisFS_$$.txt - cd "$DIR_SCRIPTS" || (echo "ERROR: Cannot change to folder $DIR_SCRIPTS"; exit 1) -done -sort -o $TMPFOLDER/lisFS_$$.txt $TMPFOLDER/lisFS_$$.txt -sort -o $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisDB_$$.txt +find . -type f -wholename "*/${ADEMPIERE_DB_PATH}/*.sql" ! -wholename "./processes_post_migration/${ADEMPIERE_DB_PATH}/*" | sed -e 's:.*/::' | sort > $TMPFOLDER/lisFS_$$.txt + MSGERROR="" APPLIED=N # extract and process the list of pending files @@ -70,7 +63,7 @@ comm -13 $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisFS_$$.txt > $TMPFOLDER/lisPENDING if [ -s $TMPFOLDER/lisPENDING_$$.txt ] then mkdir $TMPFOLDER/SyncDB_out_$$ - cat $TMPFOLDER/lisPENDING_$$.txt | while read -r FILE + while read -r FILE do SCRIPT=$(find . -name "$FILE" | grep "/$ADEMPIERE_DB_PATH/") OUTFILE=$TMPFOLDER/SyncDB_out_$$/$(basename "$FILE" .sql).out @@ -83,7 +76,7 @@ then # Stop processing to allow user to fix the problem before processing additional files break fi - done + done < $TMPFOLDER/lisPENDING_$$.txt else if [ -s $TMPFOLDER/lisFS_$$.txt ] then diff --git a/org.adempiere.server-feature/utils.unix/postgresql/MonitoredSyncDB.sh b/org.adempiere.server-feature/utils.unix/postgresql/MonitoredSyncDB.sh index a5f5ab7251..df3b1f5bd9 100755 --- a/org.adempiere.server-feature/utils.unix/postgresql/MonitoredSyncDB.sh +++ b/org.adempiere.server-feature/utils.unix/postgresql/MonitoredSyncDB.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Author: Carlos Ruiz - globalqss # Script to synchronize the database with latest migration scripts allowing a remote monitored way @@ -173,7 +173,7 @@ process_fix() notify_error() { - echo -e "$MSGERROR" + printf '%s' "$MSGERROR" printf '\n%s\n%s\n' "Error=true" "Errors were found during the process (see message above) - please inform and integrate a fix to restart this process again" SUPPORTEMAIL=$($SILENTCMD -c "select supportemail from ad_system" | sed -e 's/ //g') SENDMAIL=$(command -v sendmail) @@ -191,7 +191,7 @@ notify_error() echo "Content-Type: text/plain; charset=\"UTF-8\"" echo "Content-Transfer-Encoding: 7bit" echo "Content-Disposition: inline" - echo -e "$MSGERROR" + printf '%s' "$MSGERROR" echo "=================================" cat "$ATTACH" echo @@ -222,15 +222,8 @@ done < $TMPFOLDER/lisERR_$$.txt echo "select name from ad_migrationscript" | $SILENTCMD | sed -e 's:^ ::' | grep -v '^$' | sort > $TMPFOLDER/lisDB_$$.txt # Create list of files in the migration folder -: > $TMPFOLDER/lisFS_$$.txt -find . -type d -name "$ADEMPIERE_DB_PATH" | grep -v "./processes_post_migration/$ADEMPIERE_DB_PATH" | while read -r FOLDER -do - cd "${FOLDER}" || exit 1 - ls -- *.sql 2>/dev/null >> $TMPFOLDER/lisFS_$$.txt - cd "$DIR_SCRIPTS" || exit 1 -done -sort -o $TMPFOLDER/lisFS_$$.txt $TMPFOLDER/lisFS_$$.txt -sort -o $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisDB_$$.txt +find . -type f -wholename "*/${ADEMPIERE_DB_PATH}/*.sql" ! -wholename "./processes_post_migration/${ADEMPIERE_DB_PATH}/*" | sed -e 's:.*/::' | sort > $TMPFOLDER/lisFS_$$.txt + MSGERROR="" # extract and process the list of pending files comm -13 $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisFS_$$.txt > $TMPFOLDER/lisPENDING_$$.txt diff --git a/org.adempiere.server-feature/utils.unix/postgresql/SyncDB.sh b/org.adempiere.server-feature/utils.unix/postgresql/SyncDB.sh index 726d69c586..e36abfdfcc 100644 --- a/org.adempiere.server-feature/utils.unix/postgresql/SyncDB.sh +++ b/org.adempiere.server-feature/utils.unix/postgresql/SyncDB.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Author: Carlos Ruiz - globalqss # Script to synchronize the database for with latest migration scripts @@ -51,15 +51,8 @@ cd "$DIR_SCRIPTS" || (echo "ERROR: Cannot change to folder $DIR_SCRIPTS"; exit 1 echo "select name from ad_migrationscript" | $SILENTCMD | sed -e 's:^ ::' | grep -v '^$' | sort > $TMPFOLDER/lisDB_$$.txt # Create list of files in the migration folder -: > $TMPFOLDER/lisFS_$$.txt -find . -type d -name "$ADEMPIERE_DB_PATH" | grep -v "./processes_post_migration/$ADEMPIERE_DB_PATH" | while read -r FOLDER -do - cd "${FOLDER}" || (echo "ERROR: Cannot change to folder $FOLDER"; exit 1) - ls -- *.sql 2>/dev/null >> $TMPFOLDER/lisFS_$$.txt - cd "$DIR_SCRIPTS" || (echo "ERROR: Cannot change to folder $DIR_SCRIPTS"; exit 1) -done -sort -o $TMPFOLDER/lisFS_$$.txt $TMPFOLDER/lisFS_$$.txt -sort -o $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisDB_$$.txt +find . -type f -wholename "*/${ADEMPIERE_DB_PATH}/*.sql" ! -wholename "./processes_post_migration/${ADEMPIERE_DB_PATH}/*" | sed -e 's:.*/::' | sort > $TMPFOLDER/lisFS_$$.txt + MSGERROR="" APPLIED=N # extract and process the list of pending files @@ -67,7 +60,7 @@ comm -13 $TMPFOLDER/lisDB_$$.txt $TMPFOLDER/lisFS_$$.txt > $TMPFOLDER/lisPENDING if [ -s $TMPFOLDER/lisPENDING_$$.txt ] then mkdir $TMPFOLDER/SyncDB_out_$$ - cat $TMPFOLDER/lisPENDING_$$.txt | while read -r FILE + while read -r FILE do SCRIPT=$(find . -name "$FILE" | grep "/$ADEMPIERE_DB_PATH/") OUTFILE=$TMPFOLDER/SyncDB_out_$$/$(basename "$FILE" .sql).out @@ -80,7 +73,7 @@ then # Stop processing to allow user to fix the problem before processing additional files break fi - done + done < $TMPFOLDER/lisPENDING_$$.txt else if [ -s $TMPFOLDER/lisFS_$$.txt ] then