From 1858a7466236bc35641376bf086ff06abc1cfc16 Mon Sep 17 00:00:00 2001
From: Patrick Cernko <pcernko@mpi-klsb.mpg.de>
Date: Tue, 5 Oct 2021 15:54:42 +0200
Subject: [PATCH] fix: bail out if arc dir already exists to avoid
 arc2webarc.pl getting interactive

---
 import_mbox.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/import_mbox.sh b/import_mbox.sh
index 167c8e4..a3ad0ac 100755
--- a/import_mbox.sh
+++ b/import_mbox.sh
@@ -37,11 +37,16 @@ if [ ! -f "$MBOX_FILE" ]; then
     echo "$SYNTAX" >&2
     exit 1
 fi
-if [ ! -d "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME" ]; then
+if [ ! -d $SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME ]; then
     echo "Missing or invalid list name!" >&2
     echo "$SYNTAX" >&2
     exit 1
 fi
+arcdir=$SYMPA_ROOT/arc/$LIST_NAME@$SYMPA_DOMAIN
+if [ -e $arcdir ]; then
+    echo "ERROR: arc dir '$arcdir' already exists, please clean up first" >&2
+    exit 1
+fi
 
 # Create archives directory if not yet done
 mkdir -p "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME/archives"
@@ -61,7 +66,7 @@ pushd "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME/archives"
 # Convert to Sympa text archives
 echo "Step 2: converting $MBOX_BACKUP into .log files" >&2
 $base/mbox2sympa.pl $MBOX_BACKUP
-rm $MBOX_BACKUP
+rm -f $MBOX_BACKUP
 
 chown -R $SYMPA_USER "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME/archives"
 chmod -R g=rX,o= "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME/archives"
-- 
GitLab