shellcheck

This commit is contained in:
viennet 2020-12-28 22:09:20 +01:00
parent dea24d0257
commit 7ad2a10894
2 changed files with 20 additions and 20 deletions

View File

@ -15,7 +15,7 @@ SCODOC_DIR="${INSTANCE_DIR}/Products/ScoDoc"
SCODOC_VAR_DIR="${INSTANCE_DIR}/var/scodoc" SCODOC_VAR_DIR="${INSTANCE_DIR}/var/scodoc"
source utils.sh source utils.sh
check_uid_root $0 check_uid_root "$0"
# Safety check # Safety check
echo "Ce script va remplacer les donnees de votre installation ScoDoc par celles" 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 "TOUTES LES BASES POSTGRESQL SERONT EFFACEES !!!"
echo echo
echo -n "Voulez vous poursuivre cette operation ? (y/n) [n]" echo -n "Voulez vous poursuivre cette operation ? (y/n) [n]"
read ans read -r ans
if [ ! "$(norm_ans "$ans")" = 'Y' ] if [ ! "$(norm_ans "$ans")" = 'Y' ]
then then
echo "Annulation" echo "Annulation"
@ -57,7 +57,7 @@ then
echo "Opening tgz archive..." echo "Opening tgz archive..."
tmp=$(mktemp -d) tmp=$(mktemp -d)
chmod a+rx "$tmp" chmod a+rx "$tmp"
cd "$tmp" cd "$tmp" || terminate "directory error"
tar xfz "$SRC" tar xfz "$SRC"
SRC=$(ls -1d "$tmp"/*) SRC=$(ls -1d "$tmp"/*)
IS_TMP=1 IS_TMP=1
@ -83,18 +83,18 @@ su -c "$SCODOC_DIR/config/psql_restore_databases.sh $PG_DUMPFILE" postgres
# #
echo Copying data files... echo Copying data files...
rm -rf "$INSTANCE_DIR/var" rm -rf "${INSTANCE_DIR:?}/var"
$COPY "$SRC/var" "$INSTANCE_DIR" $COPY "$SRC/var" "$INSTANCE_DIR"
if [ ! -e "${SCODOC_VAR_DIR}/config/" ] if [ ! -e "${SCODOC_VAR_DIR:?}/config/" ]
then then
mkdir "${SCODOC_VAR_DIR}/config/" mkdir "${SCODOC_VAR_DIR:?}/config/"
chown www-data.www-data "${SCODOC_VAR_DIR}/config/" chown www-data.www-data "${SCODOC_VAR_DIR:?}/config/"
chmod 775 "${SCODOC_VAR_DIR}/config/" chmod 775 "${SCODOC_VAR_DIR:?}/config/"
fi fi
rm -rf "$SCODOC_DIR/config/depts" rm -rf "${SCODOC_DIR:?}/config/depts"
if [ -e "$SRC/depts" ] if [ -e "${SRC:?}/depts" ]
then then
# legacy depts => move them to var # legacy depts => move them to var
$COPY "$SRC/depts" "${SCODOC_VAR_DIR}/config/" $COPY "$SRC/depts" "${SCODOC_VAR_DIR}/config/"
@ -107,7 +107,7 @@ then
$COPY "$SRC/photos" "${SCODOC_VAR_DIR}/" $COPY "$SRC/photos" "${SCODOC_VAR_DIR}/"
fi fi
rm -rf "$SCODOC_DIR/logos" rm -rf "${SCODOC_DIR:?}/logos"
$COPY "$SRC/logos" "$SCODOC_DIR/" $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)" 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" iconv -f iso8859-15 -t utf-8 "$SCODOC_DIR/config/scodoc_config.py.orig" > "$SCODOC_DIR/config/scodoc_config.py"
fi fi
rm -rf "$INSTANCE_DIR/log" rm -rf "${INSTANCE_DIR:?}/log"
$COPY "$SRC/log" "$INSTANCE_DIR/" $COPY "$SRC/log" "$INSTANCE_DIR/"
# Fix file ownership and access rights # Fix file ownership and access rights
@ -130,13 +130,13 @@ chown -R www-data.root "$SCODOC_DIR"
chmod -R 775 "$SCODOC_DIR" chmod -R 775 "$SCODOC_DIR"
# Remove tmp directory # Remove tmp directory
if [ $IS_TMP = "1" ] if [ "$IS_TMP" = "1" ]
then then
rm -rf $tmp rm -rf "${tmp}"
fi fi
# Mise a jour BD ScoDoc # Mise a jour BD ScoDoc
cd $SCODOC_DIR/config cd ${SCODOC_DIR:?}/config || terminate "no config directory"
./upgrade.sh ./upgrade.sh
# #

View File

@ -35,7 +35,7 @@ INSTANCE_DIR=/opt/scodoc
SCODOC_DIR="$INSTANCE_DIR/Products/ScoDoc" SCODOC_DIR="$INSTANCE_DIR/Products/ScoDoc"
source utils.sh source utils.sh
check_uid_root $0 check_uid_root "$0"
echo "Stopping ScoDoc..." echo "Stopping ScoDoc..."
scodocctl stop scodocctl stop
@ -44,9 +44,9 @@ scodocctl stop
echo "Dumping SQL database..." echo "Dumping SQL database..."
chown postgres "$DEST" chown postgres "$DEST"
su -c "pg_dumpall > \"$DEST\"/scodoc.dump.txt" postgres su -c "pg_dumpall > \"$DEST\"/scodoc.dump.txt" postgres
if [ ! $? -eq 0 ] if [ ! "$?" -eq 0 ]
then 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 exit 1
fi fi
chown root "$DEST" chown root "$DEST"
@ -57,7 +57,7 @@ cp -rp "$INSTANCE_DIR/var" "$DEST"
# Depts db config (now in .../var) # Depts db config (now in .../var)
shopt -s nullglob shopt -s nullglob
if [ ! -z "$(echo ${SCODOC_DIR}/config/depts/*.cfg)" ] if [ -n "$(echo ${SCODOC_DIR}/config/depts/*.cfg)" ]
then then
echo "Copying legacy depts configs..." echo "Copying legacy depts configs..."
cp -rp "$SCODOC_DIR/config/depts" "$DEST" cp -rp "$SCODOC_DIR/config/depts" "$DEST"
@ -86,6 +86,6 @@ cp -rp "$INSTANCE_DIR/log" "$DEST"
echo echo
echo "Archiving backup files in a $DEST.tgz..." echo "Archiving backup files in a $DEST.tgz..."
base=$(basename "$DEST") 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)." echo "Done (you can copy " "$DEST"".tgz to destination machine)."