ccollect/tools/ccollect_delete_source

109 lines
2.5 KiB
Plaintext
Raw Normal View History

2007-08-16 16:36:35 +00:00
#!/bin/sh
#
# 2007-2008 Nico Schottelius (nico-ccollect at schottelius.org)
#
# This file is part of ccollect.
#
# ccollect 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 3 of the License, or
# (at your option) any later version.
#
# ccollect is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ccollect. If not, see <http://www.gnu.org/licenses/>.
#
# 2007-08-16 Written for Netstream (www.netstream.ch)
2007-08-16 18:06:42 +00:00
# Delete sources and their backups (optionally).
2008-03-17 08:17:53 +00:00
#
2007-08-16 16:36:35 +00:00
# standard values
CCOLLECT_CONF="${CCOLLECT_CONF:-/etc/ccollect}"
CSOURCES="${CCOLLECT_CONF}/sources"
self="$(basename $0)"
# functions first
_echo()
{
echo "${self}> $@"
}
_exit_err()
{
_echo "$@"
rm -f "$TMP"
exit 1
}
# argv
if [ $# -lt 1 ]; then
2007-08-16 16:45:20 +00:00
_echo "${self} [-f] [-d] <sources to delete>"
_echo " -f: Do not ask, simply delete. Dangerous and good for sysadmins."
_echo " -d: Also delete the destination (removes all backups)"
2007-08-16 16:36:35 +00:00
_exit_err "Exiting."
fi
params_possible=yes
force=""
backups=""
while [ $# -gt 0 ]; do
if [ "$params_possible" ]; then
case "$1" in
"-f"|"--force")
force="-r"
2007-08-16 16:45:20 +00:00
shift; continue
2007-08-16 16:36:35 +00:00
;;
"-d"|"--destination")
backups=yes
2007-08-16 16:45:20 +00:00
shift; continue
;;
--)
params_possible=""
shift; continue
2007-08-16 16:36:35 +00:00
;;
2007-08-16 16:45:20 +00:00
-*|--*)
2007-08-16 16:36:35 +00:00
_exit_err "Unknown option: $1"
;;
esac
fi
# Reached here? So there are no more parameters.
params_possible=""
2007-08-16 16:45:20 +00:00
source="$1"; shift
2007-08-16 16:36:35 +00:00
# Create
_echo "Deleting ${source} ..."
fullname="${CSOURCES}/${source}"
# ask the user per source, if she's not forcing us
if [ -z "$force" ]; then
sure=""
2007-08-16 16:45:20 +00:00
echo -n "Do you really want to delete ${source} (y/n)? "
2007-08-16 16:36:35 +00:00
read sure
if [ "$sure" != "y" ]; then
_echo "Skipping ${source}."
continue
fi
fi
if [ "$backups" ]; then
ddir="$(cat "${fullname}/destination")"
absdir="$(cd "${ddir}" && pwd -P)" || _exit_err "Cannot change to ${ddir}"
_echo "Deleting ${absdir} ..."
echo rm -r $force "${absdir}"
2007-08-16 16:36:35 +00:00
fi
_echo "Deleting ${fullname} ..."
echo rm -r $force "${fullname}"
2007-08-16 16:36:35 +00:00
done
exit 0