Add next year archive after previous one

This commit is contained in:
Bob Mottram 2017-07-15 14:54:53 +01:00
parent 59f018b336
commit aa87b5c188
1 changed files with 9 additions and 2 deletions

View File

@ -50,9 +50,16 @@ for d in /home/*/ ; do
# add the archive to .muttrc if needed
if [ -f $MUTTRC ]; then
MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
BACKUP_DIRECTORY=archive-$(date +"%Y")
YR=$(date +"%Y")
PREV_YR=$((YR - 1))
BACKUP_DIRECTORY=archive-$YR
PREV_BACKUP_DIRECTORY=archive-$PREV_YR
if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then
sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC
if [[ $MUTT_MAILBOXES == *$PREV_BACKUP_DIRECTORY* ]]; then
sed -i "s|$PREV_BACKUP_DIRECTORY|$PREV_BACKUP_DIRECTORY =$BACKUP_DIRECTORY|g" $MUTTRC
else
sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC
fi
chown $USERNAME:$USERNAME $MUTTRC
fi
fi