#!/bin/sh
#------------------------------------------------------------------------------
# /var/install/bin/subversion-tools-listbackups - list backup files
#
# Creation   :  2018-07-11 daniel
# Last Update:  2023-07-23 09:11:10
#
# Copyright (c) 2025 the eisfair team, team(at)eisfair(dot)org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#------------------------------------------------------------------------------

#include eislib
. /var/install/include/eislib
. /etc/config.d/subversion

clrhome

# Mount backup media
if [ ! -z "${SVN_BACKUP_MOUNT}" ]
then
    eval ${SVN_BACKUP_MOUNT} 2>&1
    if [ "$?" != "0" ]
    then
        echo "unable to execute: ${SVN_BACKUP_MOUNT}"
        anykey
        exit 1
    fi
fi

# list backup files
mecho -info "List of backup files:"
backup_files=$(/bin/ls -t "${SVN_BACKUP_TARGET}/"*.backup.bz2 2>/dev/null)
c="1"
for file in ${backup_files}
do
    mecho -info -n "$c  "
    mecho "${file}"
    c=$(($c + 1))
done

# Unount backup media
if [ ! -z "${SVN_BACKUP_UMOUNT}" ]
then
    eval ${SVN_BACKUP_UMOUNT} 2>&1
    if [ "$?" != "0" ]
    then
        echo "unable to execute: ${SVN_BACKUP_UMOUNT}"
    fi
fi

anykey
exit 0