aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2009-02-19 12:23:29 -0500
committerMicah Anderson <micah@riseup.net>2009-02-19 12:23:29 -0500
commit539fd1471907422d81626260ea4f1e23e4d398a4 (patch)
treeefe32e02a285fe1d241e16c6701a95a8201d79e7 /lib
parent27a7859c42394a78c16b24f0d08ca28667bb1efa (diff)
downloadbackupninja-539fd1471907422d81626260ea4f1e23e4d398a4.tar.gz
backupninja-539fd1471907422d81626260ea4f1e23e4d398a4.tar.bz2
move the branches directories up to the root of the repository
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am29
-rw-r--r--lib/Makefile.in336
-rw-r--r--lib/easydialog.in267
-rw-r--r--lib/parseini.in130
-rw-r--r--lib/tools.in48
-rw-r--r--lib/vserver.in250
6 files changed, 1060 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644
index 0000000..11eba37
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1,29 @@
+pkglib_SCRIPTS = easydialog parseini tools vserver
+
+CLEANFILES = $(pkglib_SCRIPTS)
+
+EXTRA_DIST = easydialog.in parseini.in tools.in vserver.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"
+
+easydialog: $(srcdir)/easydialog.in
+ rm -f easydialog
+ $(edit) easydialog.in > easydialog
+
+parseini: $(srcdir)/parseini.in
+ rm -f parseini
+ $(edit) parseini.in > parseini
+
+tools: $(srcdir)/tools.in
+ rm -f tools
+ $(edit) tools.in > tools
+
+vserver: $(srcdir)/vserver.in
+ rm -f vserver
+ $(edit) vserver.in > vserver
diff --git a/lib/Makefile.in b/lib/Makefile.in
new file mode 100644
index 0000000..e22f8fe
--- /dev/null
+++ b/lib/Makefile.in
@@ -0,0 +1,336 @@
+# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+subdir = lib
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_CLEAN_FILES =
+am__installdirs = "$(DESTDIR)$(pkglibdir)"
+pkglibSCRIPT_INSTALL = $(INSTALL_SCRIPT)
+SCRIPTS = $(pkglib_SCRIPTS)
+SOURCES =
+DIST_SOURCES =
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BASH = @BASH@
+CFGDIR = @CFGDIR@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+HAVE_RPM = @HAVE_RPM@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+MKTEMP = @MKTEMP@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_cv_have_rpm = @ac_cv_have_rpm@
+am__leading_dot = @am__leading_dot@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+pkglib_SCRIPTS = easydialog parseini tools vserver
+CLEANFILES = $(pkglib_SCRIPTS)
+EXTRA_DIST = easydialog.in parseini.in tools.in vserver.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"
+
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu lib/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu lib/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-pkglibSCRIPTS: $(pkglib_SCRIPTS)
+ @$(NORMAL_INSTALL)
+ test -z "$(pkglibdir)" || $(MKDIR_P) "$(DESTDIR)$(pkglibdir)"
+ @list='$(pkglib_SCRIPTS)'; for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ if test -f $$d$$p; then \
+ f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
+ echo " $(pkglibSCRIPT_INSTALL) '$$d$$p' '$(DESTDIR)$(pkglibdir)/$$f'"; \
+ $(pkglibSCRIPT_INSTALL) "$$d$$p" "$(DESTDIR)$(pkglibdir)/$$f"; \
+ else :; fi; \
+ done
+
+uninstall-pkglibSCRIPTS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(pkglib_SCRIPTS)'; for p in $$list; do \
+ f=`echo "$$p" | sed 's|^.*/||;$(transform)'`; \
+ echo " rm -f '$(DESTDIR)$(pkglibdir)/$$f'"; \
+ rm -f "$(DESTDIR)$(pkglibdir)/$$f"; \
+ done
+tags: TAGS
+TAGS:
+
+ctags: CTAGS
+CTAGS:
+
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(SCRIPTS)
+installdirs:
+ for dir in "$(DESTDIR)$(pkglibdir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic mostlyclean-am
+
+distclean: distclean-am
+ -rm -f Makefile
+distclean-am: clean-am distclean-generic
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-exec-am: install-pkglibSCRIPTS
+
+install-html: install-html-am
+
+install-info: install-info-am
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-pkglibSCRIPTS
+
+.MAKE: install-am install-strip
+
+.PHONY: all all-am check check-am clean clean-generic distclean \
+ distclean-generic distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-pkglibSCRIPTS install-ps \
+ install-ps-am install-strip installcheck installcheck-am \
+ installdirs maintainer-clean maintainer-clean-generic \
+ mostlyclean mostlyclean-generic pdf pdf-am ps ps-am uninstall \
+ uninstall-am uninstall-pkglibSCRIPTS
+
+
+easydialog: $(srcdir)/easydialog.in
+ rm -f easydialog
+ $(edit) easydialog.in > easydialog
+
+parseini: $(srcdir)/parseini.in
+ rm -f parseini
+ $(edit) parseini.in > parseini
+
+tools: $(srcdir)/tools.in
+ rm -f tools
+ $(edit) tools.in > tools
+
+vserver: $(srcdir)/vserver.in
+ rm -f vserver
+ $(edit) vserver.in > vserver
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/lib/easydialog.in b/lib/easydialog.in
new file mode 100644
index 0000000..056c76c
--- /dev/null
+++ b/lib/easydialog.in
@@ -0,0 +1,267 @@
+#!@BASH@
+# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
+
+# copyright 2002 lmoore@tump.com under the terms of the GNU LGPL.
+# additions 2005 collective@riseup.net
+
+# whiptail has trouble being called in the foo=$(whiptail ...) fashion for
+# some reason. this is very annoying. this means that we need to use
+# temporary files to store the answers from the input and list based boxes
+# and then read the answers into a REPLY variable. that just really
+# stinks, oh well, that's what you get when you have a weak link
+# implementation...
+#
+# inputBox and passwordBox could be refactored to use a common function
+
+test -z "$WIDTH" && WIDTH=0
+test -z "$HEIGHT" && HEIGHT=0
+BACKTITLE=""
+DIALOG=dialog
+HELP=
+
+setApplicationTitle() {
+ BACKTITLE=$*
+}
+
+setHelp() {
+ HELP="$@"
+}
+
+setDimension() {
+ WIDTH=$1
+ HEIGHT=$2
+}
+
+booleanBox() {
+ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
+ `[ "$3" == no ] && echo '--defaultno'` --yesno "$2" $HEIGHT $WIDTH
+}
+
+msgBox() {
+ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
+ --msgbox "$2" $HEIGHT $WIDTH
+}
+
+gaugeBox() {
+ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
+ --gauge "$2" $HEIGHT $WIDTH 0
+}
+
+inputBox() {
+ local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
+ trap "rm -f $temp" 0
+ REPLY=
+ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
+ --inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp
+ local status=$?
+ [ $status = 0 ] && REPLY=$(cat $temp)
+ rm -f $temp
+ return $status
+}
+
+# Xdialog and {dialog,whiptail} use different mechanism to "qoute" the
+# values from a checklist. {dialog,whiptail} uses standard double quoting
+# while Xdialog uses a "/" as the separator. the slash is arguably better,
+# but the double quoting is more standard. anyway, this function can be
+# overridden to allow a derived implementation to change it's quoting
+# mechanism to the standard double-quoting one. it receives two
+# arguements, the file that has the data and the box type.
+_listReplyHook() {
+ cat $1
+}
+
+# this is the base implementation of all the list based boxes, it works
+# out nicely that way. the real function just passes it's arguments to
+# this function with an extra argument specifying the actual box that
+# needs to be rendered.
+_genericListBox() {
+ local box=$1
+ shift 1
+ local title=$1
+ local text=$2
+ shift 2
+ local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
+ trap "rm -f $temp" 0
+ REPLY=
+ $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \
+ $box "$text" $HEIGHT $WIDTH 10 \
+ "$@" 2> $temp
+ local status=$?
+ [ $status = 0 ] && REPLY=$(_listReplyHook $temp $box)
+ rm -f $temp
+ _DEFAULT=
+ return $status
+}
+
+setDefault() {
+ _DEFAULT="--default-item $1"
+}
+
+menuBox() {
+ _genericListBox --menu "$@"
+}
+
+## a menu box with additional help info displayed
+## at the bottom of the window when an item is selected
+menuBoxHelp() {
+ HELP="--item-help"
+ _genericListBox --menu "$@"
+ status=$?
+ HELP=
+ return $status
+}
+
+## a menu box with an addition button 'help'
+menuBoxHelpFile() {
+ HELP="--help-button"
+ _genericListBox --menu "$@"
+ status=$?
+ HELP=
+ return $status
+}
+
+checkBox() {
+ _genericListBox --checklist "$@"
+}
+
+radioBox() {
+ _genericListBox --radiolist "$@"
+}
+
+textBox() {
+ $DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH
+}
+
+passwordBox() {
+ local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
+ trap "rm -f $temp" 0
+ REPLY=
+ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
+ --passwordbox "$2" $HEIGHT $WIDTH 2> $temp
+ local status=$?
+ [ $status = 0 ] && REPLY=$(cat $temp)
+ rm -f $temp
+ return $status
+}
+
+
+#########################################################
+## begin-item-display style lists
+##
+## these lists are built by calling fuctions multiple times.
+## this can make it easier to build your list in a loop
+##
+
+listBegin() {
+ _menu_title=$1
+ _menu_msg=$2
+ _menu_items=0
+ _menu_text=
+ _menu_labels=
+ _menu_status=
+}
+
+listItem() {
+ _menu_labels[$_menu_items]=$1
+ _menu_text[$_menu_items]=$2
+ _menu_status[$_menu_items]=$3 # available only for checklist
+ let "_menu_items += 1"
+}
+
+
+##
+## takes one of:
+## menu, checklist, radiolist
+##
+listDisplay() {
+ boxtype=$1
+ local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
+ trap "rm -f $temp" 0
+
+ local label
+ local text
+ local status
+ (
+ echo -ne " $HELP $_DEFAULT "
+ echo -ne " --backtitle '$BACKTITLE' "
+ echo -ne " --title '$_menu_title' "
+ echo -ne " --$boxtype '$_menu_msg' "
+ echo -ne " $HEIGHT $WIDTH 10 "
+ for ((i=0; i < $_menu_items ; i++)); do
+ label=${_menu_labels[$i]}
+ text=${_menu_text[$i]}
+ status=${_menu_status[$i]}
+ echo -ne " $label '$text' $status "
+ done
+ ) | xargs $DIALOG 2> $temp
+
+ local status=$?
+ REPLY=""
+ [ $status = 0 ] && REPLY=`cat $temp`
+ rm -f $temp
+ _DEFAULT=
+ return $status
+}
+
+####################################################
+## FORM
+
+_form_gap=2
+formBegin() {
+ _form_title=$1
+ _form_items=0
+ _form_labels=
+ _form_text=
+}
+
+formItem() {
+ _form_labels[$_form_items]=$1
+ _form_text[$_form_items]=$2
+ let "_form_items += 1"
+}
+
+formDisplay() {
+ local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
+
+ max_length=0
+ for ((i=0; i < ${#_form_labels[@]} ; i++)); do
+ label=${_form_labels[$i]}
+ length=`expr length $label`
+ if [ $length -gt $max_length ]; then
+ max_length=$length
+ fi
+ done
+ let "max_length += 2"
+
+ local xpos=1
+ (
+ echo -n -e "--form '$_form_title' 0 0 20"
+ for ((i=0; i < $_form_items ; i++)); do
+ label=${_form_labels[$i]}
+ text=${_form_text[$i]}
+ echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30"
+ let "xpos += _form_gap"
+ done
+ ) | xargs $DIALOG 2> $temp
+ local status=$?
+
+ ##
+ ## the exit status is meaningless, it is always 0.
+ ## i can't figure out how to get the exit status of dialog
+ ## if we do "dialog `arg code`" or "dialog $args", then the quotes
+ ## get messed up and dialog won't run.
+ ## if we do "(arg code) | xargs dialog", then the exit status is
+ ## swallowed by xargs. xargs should return different exit status
+ ## depending on the exit status of the command run, but i have
+ ## never been able to get that to work.
+ ##
+
+ REPLY=
+ if [ $status = 0 ]; then
+ IFS=$''
+ REPLY=`cat $temp`
+ IFS=$' \t\n'
+ fi
+ rm -f $temp
+ return $status
+}
diff --git a/lib/parseini.in b/lib/parseini.in
new file mode 100644
index 0000000..2f2124c
--- /dev/null
+++ b/lib/parseini.in
@@ -0,0 +1,130 @@
+# -*- mode: awk; indent-tabs-mode: nil; -*-
+#
+# parseini --- parses 'ini' style configuration files.
+#
+# Usage:
+# awk -f parseini S=<section> P=<param> <ini file>
+#
+# if section is an empty string, then we use the default section
+#
+# example ini file:
+#
+# fruit = apple
+# fruit = pear
+# multiline = this is a multiline \
+# parameter
+#
+# # this is a comment
+# [colors]
+# red = yes
+# green = no
+# blue = maybe
+#
+# [ocean]
+# fish = red
+# fish = blue
+#
+# example usage:
+# > awk -f parseini S=ocean P=fish testfile.ini
+# would return:
+# red
+# blue
+#
+
+BEGIN {
+ readlines = 1
+ implied = 1
+}
+
+# remove lines starting with #, but not #!
+/^#[^!]/ {next}
+
+# skip blank
+/^[ \r\t]*$/ {next}
+
+# we want to read the lines of the matched section
+# and disable for other sections
+/^\[.+\][ \r\t]*$/ {
+ continueline = 0
+ if (S && implied) {
+ nline = 0
+ implied = 0
+ }
+ if (S && match($0, "^\\[" S "\\][ \n]*")) {
+ # we found the section, so start reading.
+ readlines = 1
+ }
+ else {
+ # no section, so stop reading lines
+ if (readlines) readlines = 0
+ }
+ next
+}
+
+# when reading, store lines.
+
+{
+ if (!readlines) next
+ line[nline++] = $0
+ if ($0 ~ /\\[ \r\t]*$/)
+ continueline = 1
+ else
+ continueline = 0
+}
+
+# process the read lines lines, matching parameters
+
+END {
+ # if section is set but implied is still true
+ # then we never found the section, so use everything
+ if (S && implied) {
+ nline = 0
+ }
+
+ # if have P then find P in read lines and get values
+ if (P) {
+ MATCH = "^[ \r\t]*" P "[ \r\t]*="
+ continueline = 0
+ for (x = 0; x < nline; ++x) {
+ v = line[x]
+ if (continueline) {
+ sub(/[ \r\t]+$/, "", v)
+ if (v ~ /\\$/) {
+ v = substr(v, 1, length(v)-1)
+ sub(/[ \r\t]+$/, "", v)
+ }
+ if (v) value[nvalue++] = v
+ }
+ else if (v ~ MATCH) {
+ sub(MATCH, "", v)
+ sub(/^[ \r\t]+/, "", v)
+ sub(/[ \r\t]+$/, "", v)
+ if (v ~ /\\$/) {
+ continueline = 1
+ v = substr(v, 1, length(v)-1)
+ sub(/[ \r\t]+$/, "", v)
+ }
+ if (v) value[nvalue++] = v
+ }
+ }
+ # copy parameter definition to output array
+ nline = nvalue
+ for (x = 0; x < nvalue; ++x)
+ line[x] = value[x]
+ }
+
+ # trim all leading & trailing whitespace;
+ # except for leading whitespace in continuation lines,
+
+ for (x = 0; x < nline; ++x) {
+ sub(/^[ \r\t]+/, "", line[x])
+ sub(/[ \r\t]+$/, "", line[x])
+ }
+
+ # output the final result
+ for (x = 0; x < nline; ++x)
+ print line[x]
+
+ if (nline) exit 0
+ else exit 1
+}
diff --git a/lib/tools.in b/lib/tools.in
new file mode 100644
index 0000000..0005be9
--- /dev/null
+++ b/lib/tools.in
@@ -0,0 +1,48 @@
+#!@BASH@
+# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
+
+# This file contains functions shared between ninjahelper and backupninja.
+
+#####################################################
+## MISC FUNCTIONS
+
+#
+# create a temporary file in a secure way.
+#
+function maketemp() {
+ local tempfile=`mktemp /tmp/$1.XXXXXXXX`
+ echo $tempfile
+}
+
+#####################################################
+## CONFIG-FILE RELATED FUNCTIONS
+
+function setfile() {
+ CURRENT_CONF_FILE=$1
+}
+
+function setsection() {
+ CURRENT_SECTION=$1
+}
+
+#
+# sets a global var with name equal to $1
+# to the value of the configuration parameter $1
+# $2 is the default.
+#
+function getconf() {
+ CURRENT_PARAM=$1
+ ret=`@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE`
+ # if nothing is returned, set the default
+ if [ "$ret" == "" -a "$2" != "" ]; then
+ ret="$2"
+ fi
+
+ # replace * with %, so that it is not globbed.
+ ret="${ret//\\*/__star__}"
+
+ # this is weird, but single quotes are needed to
+ # allow for returned values with spaces. $ret is still expanded
+ # because it is in an 'eval' statement.
+ eval $1='$ret'
+}
diff --git a/lib/vserver.in b/lib/vserver.in
new file mode 100644
index 0000000..153a9b0
--- /dev/null
+++ b/lib/vserver.in
@@ -0,0 +1,250 @@
+# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
+
+#####################################################
+## VSERVERS RELATED FUNCTIONS FOR NINJAHELPER
+##
+## Depends on:
+## - easydialog library
+## - $conffile
+##
+## Global variables used and modified here:
+## - $vservers_are_available (yes/no)
+## - $found_vservers (list)
+## - $selected_vservers (list)
+## - $host_or_vservers (host/vservers/both)
+##
+
+##
+## Get vservers-related variables.
+## Then, if Vservers are enabled, check that:
+## - VROOTDIR is valid;
+## - at least one vserver can be found.
+## If, and only if, the above conditions are all true:
+## - set $vservers_are_available to 'yes';
+## - set $found_vservers to the list of all vservers found on the system.
+## This function has to be run once before a new helper is run.
+## If the argument is "nodialog", use the backupninja's message functions
+## instead of easydialog.
+##
+init_vservers() {
+ local arg=$1
+ # get global variables from the conffile
+ setfile $conffile
+ getconf vservers no
+ getconf VSERVERINFO /usr/sbin/vserver-info
+ getconf VSERVER /usr/sbin/vserver
+ getconf VROOTDIR `if [ -x "$VSERVERINFO" ]; then $VSERVERINFO info SYSINFO | grep '^ *vserver-Rootdir' | @AWK@ '{print $2}'; fi`
+ # canonicalize VROOTDIR
+ [ -z "$VROOTDIR" ] || VROOTDIR=`readlink --canonicalize $VROOTDIR`
+ # init this library's global variables
+ vservers_are_available=no
+ found_vservers=
+ selected_vservers=
+ host_or_vservers=host
+ # check vservers real availability
+ if [ $vservers = yes ]; then
+ if [ ! -x "$VSERVERINFO" ]; then
+ `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
+ "vservers enabled in $conffile, but vserver-info command was not found. Please set the VSERVERINFO configuration variable to its full path."
+ return
+ fi
+ if [ ! -x "$VSERVER" ]; then
+ `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
+ "vservers enabled in $conffile, but vserver command was not found. Please set the VSERVER configuration variable to its full path."
+ return
+ fi
+ if [ -z "$VROOTDIR" ]; then
+ `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
+ "vservers enabled in $conffile, but VROOTDIR is not set and could not be guessed."
+ return
+ fi
+ if [ ! -d "$VROOTDIR" ]; then
+ `if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
+ "vservers enabled in $conffile, but VROOTDIR ($VROOTDIR) does not exist.";
+ return
+ fi
+ found_vservers=`ls $VROOTDIR | grep -E -v "lost\+found|ARCHIVES" | tr "\n" " "`
+ if [ -z "$found_vservers" ]; then
+ `if [ "$arg" = nodialog ]; then echo warning; else echo "msgBox warning"; fi` \
+ "vservers enabled in $conffile, but no vserver was found in $VROOTDIR.";
+ return
+ fi
+ vservers_are_available=yes
+ fi
+}
+
+##
+## If all the arguments are existing vservers names, returns 0.
+## Else, returns 1. Also returns 1 if no argument is given.
+##
+vservers_exist() {
+ [ $# -ge 1 ] || return 1
+ local args="$1"
+ local vserver i found
+ for vserver in $args ; do
+ found=no
+ for i in $found_vservers ; do
+ if [ $vserver = $i ]; then
+ found=yes
+ break
+ fi
+ done
+ [ $found = yes ] || return 1
+ done
+ return 0
+}
+
+##
+## If all the arguments are running vservers names, returns 0.
+## Else, returns 1. Also returns 1 if no argument is given.
+##
+vservers_running() {
+ [ $# -ge 1 ] || return 1
+ local args="$1"
+ local vserver
+ for vserver in $args ; do
+ $VSERVERINFO -q $vserver RUNNING || return 1
+ done
+ return 0
+}
+
+##
+## If the argument is the name of a vserver selected by the current helper,
+## echoes 'on' and returns 0.
+## Else, echoes 'off' and returns 1.
+##
+vserver_is_selected() {
+ local vserver=$1
+ local vserver_is_selected=1
+ local i
+ for i in $selected_vservers ; do
+ [ "$vserver" == "$i" ] && vserver_is_selected=0
+ done
+ if [ $vserver_is_selected = 0 ]; then
+ echo on
+ else
+ echo off
+ fi
+ return $vserver_is_selected
+}
+
+##
+## Have the user choose one Vserver among the existing ones.
+## Set $selected_vservers to the chosen one's name.
+## Returns 1 if cancelled or if Vservers are not available.
+##
+choose_one_vserver() {
+ [ "$vservers_are_available" == "yes" ] || return 1
+ local title=$1
+ local i=
+ local vserver=
+ REPLY=
+ while [ -z "$REPLY" ]; do
+ [ -n "$selected_vservers" ] && setDefault $selected_vservers
+ listBegin "$title" "Choose at least one Linux-Vserver to backup:"
+ for vserver in $found_vservers; do
+ listItem "$vserver" "Backup $vserver vserver"
+ done
+ listDisplay menu
+ [ $? = 0 ] || return 1
+ done
+ selected_vservers=$REPLY
+}
+
+##
+## If Vservers are not enabled, set host_or_vservers='host' and then return
+## Else, have the user choose if he/she wants to perform the backup on the host
+## system or on one Vserver.
+## Set, respectively, $host_or_vservers to 'host' or 'vservers'.
+## Returns 1 if cancelled.
+##
+choose_host_or_one_vserver() {
+ if [ "$vservers_are_available" != "yes" ]
+ then
+ host_or_vservers='host'
+ return
+ fi
+ local title=$1
+ # if there is one, set the previously chosen item as the default
+ [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
+ menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
+ "host" "Host system" \
+ "vserver" "One Vserver"
+ [ $? = 0 ] || return 1
+ case $REPLY in
+ "host")
+ host_or_vservers='host'
+ ;;
+ "vserver")
+ host_or_vservers='vservers'
+ ;;
+ esac
+}
+
+##
+## If Vservers are not enabled, set host_or_vservers='host' and then return
+## Else, have the user choose the target he/she wants to perform the backup on:
+## - host system only;
+## - some vservers only;
+## - both the host system and some vservers.
+## Set, respectively, $host_or_vservers to 'host', 'vservers', or 'both'
+## Returns 1 if cancelled.
+##
+choose_host_or_vservers_or_both() {
+ if [ "$vservers_are_available" != "yes" ]
+ then
+ host_or_vservers='host'
+ return
+ fi
+ local title=$1
+ # if there is one, set the previously chosen item as the default
+ [ -n "$host_or_vservers" ] && setDefault $host_or_vservers
+ menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
+ "host" "Host system only" \
+ "vservers" "Vservers only" \
+ "both" "Host system and Vservers"
+ [ $? = 0 ] || return 1
+ case $REPLY in
+ "host")
+ host_or_vservers='host'
+ ;;
+ "vservers")
+ host_or_vservers='vservers'
+ ;;
+ "both")
+ host_or_vservers='both'
+ ;;
+ esac
+}
+
+##
+## Have the user choose among "all vservers" and a not-empty subset of these.
+## Set $selected_vservers to 'all' or to a space-separated name list.
+## Returns 1 if cancelled or if Vservers are not available.
+##
+choose_one_or_more_vservers() {
+ [ "$vservers_are_available" == "yes" ] || return 1
+ local title=$1
+ local i=
+ # UI
+ booleanBox "$title" "Do you want to backup all vservers?" ` [ -z "$selected_vservers" -o "$selected_vservers" == "all" ] || echo no`
+ if [ $? = 0 ]; then
+ selected_vservers="all"
+ else
+ # choose among the existing vservers
+ local vserver=
+ local vserver_was_selected=
+ REPLY=
+ while [ -z "$REPLY" ]; do
+ listBegin "$title" "Choose at least one Linux-Vserver to backup:"
+ # list existing vservers, preselecting the previously selected ones
+ for vserver in $found_vservers; do
+ listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver`
+ done
+ listDisplay checklist
+ [ $? = 0 ] || return 1
+ done
+ # remove quotes around each vserver name
+ selected_vservers=`echo $REPLY | tr -d '"'`
+ fi
+}