aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2009-02-19 12:20:44 -0500
committerMicah Anderson <micah@riseup.net>2009-02-19 12:20:44 -0500
commit27a7859c42394a78c16b24f0d08ca28667bb1efa (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /lib
parent386c4275946520bc590428e730a9d515155436a0 (diff)
downloadbackupninja-27a7859c42394a78c16b24f0d08ca28667bb1efa.tar.gz
backupninja-27a7859c42394a78c16b24f0d08ca28667bb1efa.tar.bz2
creating a debian only branch out of what used to be a subversion repository
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am29
-rw-r--r--lib/easydialog.in267
-rw-r--r--lib/parseini.in130
-rw-r--r--lib/tools.in48
-rw-r--r--lib/vserver.in250
5 files changed, 0 insertions, 724 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
deleted file mode 100644
index 11eba37..0000000
--- a/lib/Makefile.am
+++ /dev/null
@@ -1,29 +0,0 @@
-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/easydialog.in b/lib/easydialog.in
deleted file mode 100644
index 056c76c..0000000
--- a/lib/easydialog.in
+++ /dev/null
@@ -1,267 +0,0 @@
-#!@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
deleted file mode 100644
index 2f2124c..0000000
--- a/lib/parseini.in
+++ /dev/null
@@ -1,130 +0,0 @@
-# -*- 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
deleted file mode 100644
index 0005be9..0000000
--- a/lib/tools.in
+++ /dev/null
@@ -1,48 +0,0 @@
-#!@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
deleted file mode 100644
index 153a9b0..0000000
--- a/lib/vserver.in
+++ /dev/null
@@ -1,250 +0,0 @@
-# -*- 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
-}