diff options
Diffstat (limited to 'lib/beam/common.in')
-rw-r--r-- | lib/beam/common.in | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/lib/beam/common.in b/lib/beam/common.in new file mode 100644 index 0000000..49b41eb --- /dev/null +++ b/lib/beam/common.in @@ -0,0 +1,135 @@ +#! /bin/bash +# This file is part of BEAM +# Copyright (C) 2012 Sergey Poznyakoff +# +# BEAM 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, or (at your option) +# any later version. +# +# BEAM 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 BEAM. If not, see <http://www.gnu.org/licenses/>. + +# Force C locale +LC_ALL=C +export LC_ALL + +prologue_hook= +epilogue_hook= + +# User configuration variables +backup_tar_options= +backup_suffix= +backup_archive_dir= +backup_snapshot_dir= +backup_verbose= +backup_logfile="/var/log/backup" + +error() { + echo >&2 $0: $* +} + +logit() { + echo `date`: $* +} + +abend() { + ec=$1 + shift + error $@ + exit $ec +} + +tarcode() { + case $1 in + 0) echo "`date`: success";; + 1) echo "`date`: some files changed while being archived";; + 2) echo "`date`: fatal error occurred, but trying to continue anyway" + tarerror=$((tarerror + 1));; + *) echo "`date`: unexpected error code $1" + tarerror=$((tarerror + 1)); + esac +} + +load_config() { + local delayed_exit + + test -z "$BEAM_CONFIG" && BEAM_CONFIG=@SYSCONFDIR@/beam.conf + if [ -r $BEAM_CONFIG ]; then + . $BEAM_CONFIG + else + abend 1 "configuration file $BEAM_CONFIG does not exist or is unreadable" + fi + + if [ -z "$backup_items" ]; then + abend 1 "backup_items not specified" + fi + + delayed_exit= + loaded_types= + for item in $backup_items + do + eval type=\$${item}_type + if [ -z "$type" ]; then + error "${item}_type not set" + delayed_exit=1 + continue + fi + + if echo "$loaded_types" | grep -wq $type; then + : + elif [ -x $libdir/${type}.sh ]; then + . $libdir/${type}.sh || delayed_exit=1 + loaded_types="$loaded_files +$type" + else + error "$libdir/${type}.sh not found" + delayed_exit=1 + fi + + ${type}_check $item || delayed_exit=1 + done + + test -n "$delayed_exit" && abend 1 "aborting" + + tar_suffix=${backup_suffix:-.tar} + + if [ -n "$backup_bucket_name" ]; then + . @LIBDIR@/beam/s3.sh + prologue_hook="$prologue_hook s3_mount" + fi +} + +runhook() { + local hook_list + + eval hook_list=\$$1 + for hook in $hook_list + do + $hook + done +} + +print_version() { + name=$(basename $0) + cat <<EOF +$name (@PACKAGE_NAME@) @PACKAGE_VERSION@ +Copyright (C) 2012 Sergey Poznyakoff +License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +EOF + exit 0 +} + +wtf() { + l=`echo "${1#beam-}"|sed "s|.|.|g"` + s=$(echo " " | sed "s|$l|${1#beam-}|") + shift + echo " $s $@" +} |