ccollect/tools/ccollect_delete_source.sh

95 lines
1.9 KiB
Bash
Raw Normal View History

2007-08-16 16:36:35 +00:00
#!/bin/sh
# Nico Schottelius
# 2007-08-16
# Written for Netstream (www.netstream.ch)
2007-08-16 18:06:42 +00:00
# Delete sources and their backups (optionally).
2007-08-17 08:48:04 +00:00
# Copying: GPLv3 (See file COPYING in top directory)
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=yes
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=$(cd "${fullname}/destination" && pwd -P) || _exit_err "Cannot change to ${fullname}/destination"
_echo "Deleting ${ddir} ..."
rm -r "${ddir}"
fi
_echo "Deleting ${fullname} ..."
rm -r "${fullname}"
done
exit 0