Add most functionality to add_source.sh

This commit is contained in:
Nico Schottelius 2007-08-16 17:49:43 +02:00
parent 70c62e2514
commit 54538da003

View file

@ -11,28 +11,25 @@ CSOURCES="${CCOLLECT_CONF}/sources"
CDEFAULTS="${CCOLLECT_CONF}/defaults" CDEFAULTS="${CCOLLECT_CONF}/defaults"
SCONFIG="${CDEFAULTS}/sources" SCONFIG="${CDEFAULTS}/sources"
exclude="${SCONFIG}/exclude" # standard options: variable2filename
summary="${SCONFIG}/summary" exclude="exclude"
intervals="${SCONFIG}/intervals" summary="summary"
intervals="intervals"
pre_exec="${SCONFIG}/pre_exec" pre_exec="pre_exec"
post_exec="${SCONFIG}/post_exec" post_exec="post_exec"
rsync_options="rsync_options"
rsync_options="${SCONFIG}/rsync_options" verbose="verbose"
very_verbose="very_verbose"
verbose="${SCONFIG}/verbose"
vverbose="${SCONFIG}/very_verbose"
# options that we simply copy over # options that we simply copy over
standard_opts="exclude summary intervals pre_exec post_exec rsync_options verbose very_verbose" standard_opts="exclude summary intervals pre_exec post_exec rsync_options verbose very_verbose"
# options not in standard ccollect, used only for source # options not in standard ccollect, used only for source generation
# generation
src_prefix="${SCONFIG}/source_prefix" src_prefix="${SCONFIG}/source_prefix"
src_postfix="${SCONFIG}/source_postfix" src_postfix="${SCONFIG}/source_postfix"
destination_base="${SCONFIG}/destination_base" destination_base="${SCONFIG}/destination_base"
self=$(basename $0) self="$(basename $0)"
# functions first # functions first
_echo() _echo()
@ -54,25 +51,54 @@ fi
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
done source="$1"; shift
# create source
# Tests
if [ -e "${fullname}" ]; then
_echo "${fullname} already exists. Aborting."
exit 2
fi
# copy standard files
# create source
# create destination directory
# Create # Create
_echo "Creating ${fullname} ..." _echo "Creating ${source} ..."
mkdir -p "${fullname}" || exit 3
fullname="${CSOURCES}/${source}"
# create source
if [ -e "${fullname}" ]; then
_echo "${fullname} already exists. Skipping."
continue
fi
mkdir -p "${fullname}" || _exit_err Cannot create \"${fullname}\".
# copy standard files
for file in $standard_opts; do
eval rfile=\"\$$file\"
echo r: $rfile
eval filename=${SCONFIG}/${rfile}
echo f: $filename
if [ -e "${filename}" ]; then
_echo Copying $rfile for $source ...
cp -r "${filename}" "${fullname}/${rfile}"
fi
done
# create source entry
if [ -f "${src_prefix}" ]; then
source_source="$(cat "${src_prefix}")" || _exit_err "Reading $src_prefix failed."
fi
source_source="${source_source}${source}"
if [ -f "${src_postfix}" ]; then
source_source="${source_source}$(cat "${src_postfix}")" || _exit_err "Reading $src_postfix failed."
fi
_echo "Adding ${source_source} as source for ${source}"
echo "${source_source}" > "${fullname}/source"
# create destination directory
dest="${destination_base}/${source}"
_echo "Creating destination ${dest} ..."
mkdir -p "${dest}" || _exit_err "${fullname}: Cannot create ${dest}."
done
exit 0
echo "root@${source}:/" > "${fullname}/source" echo "root@${source}:/" > "${fullname}/source"
cat << eof > "${fullname}/exclude" || exit 4 cat << eof > "${fullname}/exclude" || exit 4