From 7ad2a10894925190bbd7a2065f30b1ad46b7aa70 Mon Sep 17 00:00:00 2001 From: viennet Date: Mon, 28 Dec 2020 22:09:20 +0100 Subject: [PATCH] shellcheck --- config/restore_scodoc_data.sh | 30 +++++++++++++++--------------- config/save_scodoc_data.sh | 10 +++++----- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/config/restore_scodoc_data.sh b/config/restore_scodoc_data.sh index f2bd87858..e94b15111 100755 --- a/config/restore_scodoc_data.sh +++ b/config/restore_scodoc_data.sh @@ -15,7 +15,7 @@ SCODOC_DIR="${INSTANCE_DIR}/Products/ScoDoc" SCODOC_VAR_DIR="${INSTANCE_DIR}/var/scodoc" source utils.sh -check_uid_root $0 +check_uid_root "$0" # Safety check echo "Ce script va remplacer les donnees de votre installation ScoDoc par celles" @@ -28,7 +28,7 @@ echo echo "TOUTES LES BASES POSTGRESQL SERONT EFFACEES !!!" echo echo -n "Voulez vous poursuivre cette operation ? (y/n) [n]" -read ans +read -r ans if [ ! "$(norm_ans "$ans")" = 'Y' ] then echo "Annulation" @@ -57,7 +57,7 @@ then echo "Opening tgz archive..." tmp=$(mktemp -d) chmod a+rx "$tmp" - cd "$tmp" + cd "$tmp" || terminate "directory error" tar xfz "$SRC" SRC=$(ls -1d "$tmp"/*) IS_TMP=1 @@ -83,18 +83,18 @@ su -c "$SCODOC_DIR/config/psql_restore_databases.sh $PG_DUMPFILE" postgres # echo Copying data files... -rm -rf "$INSTANCE_DIR/var" +rm -rf "${INSTANCE_DIR:?}/var" $COPY "$SRC/var" "$INSTANCE_DIR" -if [ ! -e "${SCODOC_VAR_DIR}/config/" ] +if [ ! -e "${SCODOC_VAR_DIR:?}/config/" ] then - mkdir "${SCODOC_VAR_DIR}/config/" - chown www-data.www-data "${SCODOC_VAR_DIR}/config/" - chmod 775 "${SCODOC_VAR_DIR}/config/" + mkdir "${SCODOC_VAR_DIR:?}/config/" + chown www-data.www-data "${SCODOC_VAR_DIR:?}/config/" + chmod 775 "${SCODOC_VAR_DIR:?}/config/" fi -rm -rf "$SCODOC_DIR/config/depts" -if [ -e "$SRC/depts" ] +rm -rf "${SCODOC_DIR:?}/config/depts" +if [ -e "${SRC:?}/depts" ] then # legacy depts => move them to var $COPY "$SRC/depts" "${SCODOC_VAR_DIR}/config/" @@ -107,7 +107,7 @@ then $COPY "$SRC/photos" "${SCODOC_VAR_DIR}/" fi -rm -rf "$SCODOC_DIR/logos" +rm -rf "${SCODOC_DIR:?}/logos" $COPY "$SRC/logos" "$SCODOC_DIR/" mv "$SCODOC_DIR/config/scodoc_config.py" "$SCODOC_DIR/config/scodoc_config.py.$(date +%Y%m%d-%H%M%S)" @@ -119,7 +119,7 @@ then iconv -f iso8859-15 -t utf-8 "$SCODOC_DIR/config/scodoc_config.py.orig" > "$SCODOC_DIR/config/scodoc_config.py" fi -rm -rf "$INSTANCE_DIR/log" +rm -rf "${INSTANCE_DIR:?}/log" $COPY "$SRC/log" "$INSTANCE_DIR/" # Fix file ownership and access rights @@ -130,13 +130,13 @@ chown -R www-data.root "$SCODOC_DIR" chmod -R 775 "$SCODOC_DIR" # Remove tmp directory -if [ $IS_TMP = "1" ] +if [ "$IS_TMP" = "1" ] then - rm -rf $tmp + rm -rf "${tmp}" fi # Mise a jour BD ScoDoc -cd $SCODOC_DIR/config +cd ${SCODOC_DIR:?}/config || terminate "no config directory" ./upgrade.sh # diff --git a/config/save_scodoc_data.sh b/config/save_scodoc_data.sh index a53c76403..389ed16c3 100755 --- a/config/save_scodoc_data.sh +++ b/config/save_scodoc_data.sh @@ -35,7 +35,7 @@ INSTANCE_DIR=/opt/scodoc SCODOC_DIR="$INSTANCE_DIR/Products/ScoDoc" source utils.sh -check_uid_root $0 +check_uid_root "$0" echo "Stopping ScoDoc..." scodocctl stop @@ -44,9 +44,9 @@ scodocctl stop echo "Dumping SQL database..." chown postgres "$DEST" su -c "pg_dumpall > \"$DEST\"/scodoc.dump.txt" postgres -if [ ! $? -eq 0 ] +if [ ! "$?" -eq 0 ] then - echo "Error dumping postgresql database\nPlease check that SQL server is running\nAborting." + printf "Error dumping postgresql database\nPlease check that SQL server is running\nAborting." exit 1 fi chown root "$DEST" @@ -57,7 +57,7 @@ cp -rp "$INSTANCE_DIR/var" "$DEST" # Depts db config (now in .../var) shopt -s nullglob -if [ ! -z "$(echo ${SCODOC_DIR}/config/depts/*.cfg)" ] +if [ -n "$(echo ${SCODOC_DIR}/config/depts/*.cfg)" ] then echo "Copying legacy depts configs..." cp -rp "$SCODOC_DIR/config/depts" "$DEST" @@ -86,6 +86,6 @@ cp -rp "$INSTANCE_DIR/log" "$DEST" echo echo "Archiving backup files in a $DEST.tgz..." base=$(basename "$DEST") -(cd "$DEST"/..; tar cfz "$DEST".tgz "$base") +(cd "$DEST"/.. || terminate "directory error"; tar cfz "$DEST".tgz "$base") echo "Done (you can copy " "$DEST"".tgz to destination machine)."