From: Matthijs Kooijman Date: Fri, 19 Mar 2010 20:30:31 +0000 (+0100) Subject: Add local and chroot backends. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=3c04ecde671ef12c01ff79393f936b879fb08f04;p=matthijs%2Fupstream%2Fbackupninja.git Add local and chroot backends. --- diff --git a/configure.in b/configure.in index da2d6ba..0bae7ea 100644 --- a/configure.in +++ b/configure.in @@ -80,6 +80,7 @@ AC_CONFIG_FILES([Makefile examples/Makefile handlers/Makefile lib/Makefile + lib/backends/Makefile man/Makefile src/Makefile]) diff --git a/lib/Makefile.am b/lib/Makefile.am index df8ed61..a3b11a5 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,6 +4,8 @@ CLEANFILES = $(pkglib_SCRIPTS) EXTRA_DIST = $(pkglib_SCRIPTS:%=%.in) +SUBDIRS = backends + edit = sed \ -e "s,@CFGDIR\@,$(CFGDIR),g" \ -e "s,@BASH\@,$(BASH),g" \ diff --git a/lib/backend.in b/lib/backend.in index 0c130f2..ea1be82 100644 --- a/lib/backend.in +++ b/lib/backend.in @@ -1,7 +1,7 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- # vim: set filetype=sh sw=3 sts=3 expandtab autoindent: -defined_backends=() +defined_backends=(local, chroot) available_backends=() function init_backends () { diff --git a/lib/backends/Makefile.am b/lib/backends/Makefile.am new file mode 100644 index 0000000..a297908 --- /dev/null +++ b/lib/backends/Makefile.am @@ -0,0 +1,19 @@ +BACKENDS = local chroot + +pkglib_SCRIPTS = $(BACKENDS) + +CLEANFILES = $(BACKENDS) + +EXTRA_DIST = $(BACKENDS:%=%.in) + +edit = sed \ + -e "s,@CFGDIR\@,$(CFGDIR),g" \ + -e "s,@BASH\@,$(BASH),g" \ + -e "s,@AWK\@,$(AWK),g" \ + -e "s,@SED\@,$(SED),g" \ + -e "s,@MKTEMP\@,$(MKTEMP),g" \ + -e "s,@libdir\@,$(pkglibdir),g" + +$(BACKENDS): %: $(srcdir)/%.in + rm -f $@ + $(edit) $@.in > $@ diff --git a/lib/backends/chroot.in b/lib/backends/chroot.in new file mode 100644 index 0000000..b0c5cfa --- /dev/null +++ b/lib/backends/chroot.in @@ -0,0 +1,42 @@ +# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: + +getconf CHROOT "`which chroot`" + +function backend_chroot_init () { + # Is the changeroot command available? + [ -x "$CHROOT" ] +} + +function backend_chroot_host_available () { + if [ -d "$1" ]; then + # The root exists and is a directory, everything ok + return 0 + else + if [ ! -e "$1" ]; then + # The root does not exist? + eval "$2=\"No such file or directory: '\$1'\"" + else + # The root exists, so is not a directory + eval "$2=\"Not a directory: '\$1'\"" + fi + return 1 + fi +} + +function backend_chroot_host_root () { + # The host part is the root, but strip any trailing slashes + echo "$1" | sed 's/\/*$//' +} + +function backend_chroot_run () { + # Run the command using the chroot command + "$CHROOT" "$root" "$@" +} + +function backend_chroot_interpolate_vars () { + echo "" +} + +function backend_chroot_interpolate_value () { +} diff --git a/lib/backends/local.in b/lib/backends/local.in new file mode 100644 index 0000000..069e201 --- /dev/null +++ b/lib/backends/local.in @@ -0,0 +1,33 @@ +# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: + +function backend_local_init () { + # We're always available + return 0 +} + +function backend_local_host_available () { + if [ -n "$1" ]; then + eval "$2=The local backend does not support named hosts: '\$1'" + return 1 + fi + # The empty host (i.e., "local:") is always available + return 0 +} + +function backend_local_host_root () { + # We just use the entire filesystem + echo "" +} + +function backend_local_run () { + # Running locally is simple, just run the command + "$@" +} + +function backend_local_interpolate_vars () { + echo "" +} + +function backend_local_interpolate_value () { +}