From 8d523a6df9117343d54d405bdf049ba5a7045afa Mon Sep 17 00:00:00 2001 From: Patrick Cernko <pcernko@mpi-klsb.mpg.de> Date: Tue, 5 Oct 2021 11:56:30 +0200 Subject: [PATCH] converted to bash, fixed path to mbox2sympa.pl --- import_mbox.sh | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/import_mbox.sh b/import_mbox.sh index 88620cb..167c8e4 100755 --- a/import_mbox.sh +++ b/import_mbox.sh @@ -1,4 +1,8 @@ -#!/usr/bin/env zsh +#!/bin/bash + +set -e + +base=$(dirname $0) # import_mbox # List archive import @@ -18,7 +22,7 @@ # Configuration variables SYMPA_USER=sympa:sympa -SYMPA_ROOT=/usr/local/share/sympa +SYMPA_ROOT=/var/lib/sympa MBOX_BACKUP=import.mbox set -e @@ -28,41 +32,45 @@ SYNTAX="$0 archive.mbox listname domain" MBOX_FILE="$1" LIST_NAME="$2" SYMPA_DOMAIN="$3" -[ ! -f "$MBOX_FILE" ] && echo "Missing or invalid archive file!" && echo "$SYNTAX" && exit 1 -[ ! -d "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME" ] && echo "Missing or invalid list name!" && echo "$SYNTAX" && exit 1 +if [ ! -f "$MBOX_FILE" ]; then + echo "Missing or invalid archive file!" >&2 + echo "$SYNTAX" >&2 + exit 1 +fi +if [ ! -d "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME" ]; then + echo "Missing or invalid list name!" >&2 + echo "$SYNTAX" >&2 + exit 1 +fi # Create archives directory if not yet done mkdir -p "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME/archives" # Check directory is empty (prevents dialogs...) -COUNT=`ls $SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME/archives | wc -l` -(( COUNT > 0 )) && echo "Sorry, Sympa text archives directory not empty - I stop!" && exit 2 - -set -e -set -x +COUNT=$(ls $SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME/archives | wc -l) +if [ $COUNT -gt 0 ]; then + echo "Sorry, Sympa text archives directory not empty - I stop!" >&2 + exit 2 +fi # Copy mbox file -echo "Step 1: copying input file to expl/$LIST_NAME/archives/$MBOX_BACKUP" +echo "Step 1: copying input file to expl/$LIST_NAME/archives/$MBOX_BACKUP" >&2 cp -v "$MBOX_FILE" "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME/archives/$MBOX_BACKUP" pushd "$SYMPA_ROOT/list_data/$SYMPA_DOMAIN/$LIST_NAME/archives" # Convert to Sympa text archives -echo "Step 2: converting $MBOX_BACKUP into .log files" -/root/git/github.com/mailman2sympa/mbox2sympa.pl $MBOX_BACKUP +echo "Step 2: converting $MBOX_BACKUP into .log files" >&2 +$base/mbox2sympa.pl $MBOX_BACKUP rm $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" # Convert to Sympa web archives input files -echo "Step 3: converting .log files into arc/${LIST_NAME}\@${SYMPA_DOMAIN}/\*/arctxt files" -su -m sympa -c "/usr/local/libexec/sympa/arc2webarc.pl $LIST_NAME $SYMPA_DOMAIN" || true - -# Generate the HTML archives -echo "Step 4: triggering web archives regeneration" -#su sympa -s /bin/bash -c "touch /var/spool/sympa/outgoing/.rebuild.$LIST_NAME@$SYMPA_DOMAIN" +echo "Step 3: converting .log files into arc/${LIST_NAME}\@${SYMPA_DOMAIN}/\*/arctxt files" >&2 +sudo -u sympa /usr/share/sympa/bin/arc2webarc.pl $LIST_NAME $SYMPA_DOMAIN || true # That's it! -echo "Job done - web archives should be ready in a few minutes" -echo "You may monitor the Sympa log for errors..." +echo "Job done - web archives should be ready in a few minutes" >&2 +echo "You may monitor the Sympa log for errors..." >&2 exit 0 -- GitLab