begin to implement new style option parsing
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
This commit is contained in:
parent
de6a7893fc
commit
ca1231a576
1 changed files with 51 additions and 64 deletions
115
ccollect.sh
115
ccollect.sh
|
@ -40,8 +40,8 @@ CPREEXEC="${CDEFAULTS}/pre_exec"
|
|||
CPOSTEXEC="${CDEFAULTS}/post_exec"
|
||||
|
||||
TMP=$(mktemp "/tmp/${__myname}.XXXXXX")
|
||||
VERSION=0.7.1
|
||||
RELEASE="2009-02-02"
|
||||
VERSION=0.8
|
||||
RELEASE="2009-XX-XX"
|
||||
HALF_VERSION="ccollect ${VERSION}"
|
||||
FULL_VERSION="ccollect ${VERSION} (${RELEASE})"
|
||||
|
||||
|
@ -55,9 +55,13 @@ DDATE="date +%Y-%m-%d-%H:%M:%S"
|
|||
TSORT="tc"
|
||||
|
||||
#
|
||||
# unset parallel execution
|
||||
# unset values
|
||||
#
|
||||
PARALLEL=""
|
||||
USE_ALL=""
|
||||
export INTERVAL=""
|
||||
export no_sources=0
|
||||
|
||||
|
||||
#
|
||||
# catch signals
|
||||
|
@ -87,6 +91,9 @@ add_name()
|
|||
awk "{ print \"[${name}] \" \$0 }"
|
||||
}
|
||||
|
||||
#
|
||||
# Execute on remote host, if backing up to a remote host
|
||||
#
|
||||
pcmd()
|
||||
{
|
||||
if [ "$remote_host" ]; then
|
||||
|
@ -96,21 +103,15 @@ pcmd()
|
|||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Version
|
||||
#
|
||||
display_version()
|
||||
{
|
||||
echo "${FULL_VERSION}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
#
|
||||
# Tell how to use us
|
||||
#
|
||||
usage()
|
||||
{
|
||||
echo "${__myname}: <interval name> [args] <sources to backup>"
|
||||
echo "${__myname}: [args] <interval name> <sources to backup>"
|
||||
echo ""
|
||||
echo " ccollect creates (pseudo) incremental backups"
|
||||
echo ""
|
||||
|
@ -128,49 +129,12 @@ usage()
|
|||
}
|
||||
|
||||
#
|
||||
# need at least interval and one source or --all
|
||||
# Parse options
|
||||
#
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
if [ "$1" = "-V" -o "$1" = "--version" ]; then
|
||||
display_version
|
||||
else
|
||||
usage
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# check for configuraton directory
|
||||
#
|
||||
[ -d "${CCOLLECT_CONF}" ] || _exit_err "No configuration found in " \
|
||||
"\"${CCOLLECT_CONF}\" (is \$CCOLLECT_CONF properly set?)"
|
||||
|
||||
#
|
||||
# Filter arguments
|
||||
#
|
||||
export INTERVAL="$1"; shift
|
||||
i=1
|
||||
no_sources=0
|
||||
|
||||
#
|
||||
# Capture options and create source "array"
|
||||
#
|
||||
WE=""
|
||||
ALL=""
|
||||
NO_MORE_ARGS=""
|
||||
while [ "$#" -ge 1 ]; do
|
||||
eval arg=\"\$1\"; shift
|
||||
|
||||
if [ "${NO_MORE_ARGS}" = 1 ]; then
|
||||
eval source_${no_sources}=\"${arg}\"
|
||||
no_sources=$((${no_sources}+1))
|
||||
|
||||
# make variable available for subscripts
|
||||
eval export source_${no_sources}
|
||||
else
|
||||
case "${arg}" in
|
||||
case "$1" in
|
||||
-a|--all)
|
||||
ALL=1
|
||||
USE_ALL=1
|
||||
;;
|
||||
-v|--verbose)
|
||||
set -x
|
||||
|
@ -181,33 +145,56 @@ while [ "$#" -ge 1 ]; do
|
|||
-h|--help)
|
||||
usage
|
||||
;;
|
||||
-V|--version)
|
||||
display_version
|
||||
;;
|
||||
-h|--help|-*)
|
||||
usage
|
||||
;;
|
||||
--)
|
||||
NO_MORE_ARGS=1
|
||||
break
|
||||
;;
|
||||
*)
|
||||
eval source_${no_sources}=\"$arg\"
|
||||
no_sources=$(($no_sources+1))
|
||||
break
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
i=$(($i+1))
|
||||
shift
|
||||
done
|
||||
|
||||
# also export number of sources
|
||||
export no_sources
|
||||
|
||||
#
|
||||
# check for configuraton directory
|
||||
#
|
||||
[ -d "${CCOLLECT_CONF}" ] || _exit_err "No configuration found in " \
|
||||
"\"${CCOLLECT_CONF}\" (is \$CCOLLECT_CONF properly set?)"
|
||||
|
||||
#
|
||||
# Capture sources in an "array"
|
||||
#
|
||||
while [ "$#" -ge 1 ]; do
|
||||
eval arg=\"\$1\"; shift
|
||||
|
||||
if [ -z "$INTERVAL" ]; then
|
||||
INTERVAL="$arg"
|
||||
else
|
||||
eval source_${no_sources}=\"${arg}\"
|
||||
no_sources="$((${no_sources}+1))"
|
||||
|
||||
# make variable available for subscripts
|
||||
eval export source_${no_sources}
|
||||
fi
|
||||
done
|
||||
|
||||
#
|
||||
# Look, if we should take ALL sources
|
||||
#
|
||||
if [ "${ALL}" = 1 ]; then
|
||||
# reset everything specified before
|
||||
no_sources=0
|
||||
if [ "${USE_ALL}" = 1 ]; then
|
||||
no_sources="0"
|
||||
|
||||
#
|
||||
# get entries from sources
|
||||
#
|
||||
cwd=$(pwd -P)
|
||||
cwd="$(pwd -P)"
|
||||
( cd "${CSOURCES}" && ls > "${TMP}" ); ret=$?
|
||||
|
||||
[ "${ret}" -eq 0 ] || _exit_err "Listing of sources failed. Aborting."
|
||||
|
@ -221,7 +208,7 @@ fi
|
|||
#
|
||||
# Need at least ONE source to backup
|
||||
#
|
||||
if [ "${no_sources}" -lt 1 ]; then
|
||||
if [ "${no_sources}" -lt 1 -o -z "${INTERVAL}" ]; then
|
||||
usage
|
||||
else
|
||||
_techo "${HALF_VERSION}: Beginning backup using interval ${INTERVAL}"
|
||||
|
@ -595,4 +582,4 @@ if [ -x "${CPOSTEXEC}" ]; then
|
|||
fi
|
||||
|
||||
rm -f "${TMP}"
|
||||
_techo "Finished ${WE}"
|
||||
_techo "Finished"
|
||||
|
|
Loading…
Reference in a new issue