aboutsummaryrefslogtreecommitdiff
path: root/src/ninjahelper.in
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2005-11-29 10:10:08 +0000
committerintrigeri <intrigeri@boum.org>2005-11-29 10:10:08 +0000
commit9208b449da1a1df50c2759946c9931f456af1e87 (patch)
tree4758ed8c827dad3015c738513f6c2e70c1322347 /src/ninjahelper.in
parent13893e6d255a0b3ff1ac2ffb74cff0652d2b61f4 (diff)
downloadbackupninja-9208b449da1a1df50c2759946c9931f456af1e87.tar.gz
backupninja-9208b449da1a1df50c2759946c9931f456af1e87.tar.bz2
r3562@krups: intrigeri | 2005-11-16 20:20:16 +0100
Moved more code to lib/ (conffile-related functions, parseini. Added dup helper, using new modular vservers-related functions shared for all helpers.
Diffstat (limited to 'src/ninjahelper.in')
-rwxr-xr-xsrc/ninjahelper.in155
1 files changed, 120 insertions, 35 deletions
diff --git a/src/ninjahelper.in b/src/ninjahelper.in
index 451f389..0d7050c 100755
--- a/src/ninjahelper.in
+++ b/src/ninjahelper.in
@@ -58,6 +58,8 @@ require_packages() {
## menu for the wizards
##
donew() {
+ unset host_or_vservers
+ unset vservers_chooser_vsnames
listBegin "new action menu" "select an action to create"
listItem return "return to main menu"
for data in $HELPERS; do
@@ -163,6 +165,102 @@ doaction() {
}
#####################################################
+## VSERVERS RELATED FUNCTIONS
+
+##
+## If vservers are not enabled, exit silently and set host_or_vservers to 'host'.
+## 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
+## Sets, respectively, $host_or_vservers to 'host', 'vservers', or 'both'
+## $host_or_vservers is unset when a new helper is run.
+## Returns 1 if cancelled.
+##
+host_or_vservers_chooser() {
+ local title=$1
+ # exit silently if vservers are not enabled
+ if [ "$vservers" != "yes" ]; then
+ host_or_vservers='host'
+ return
+ fi
+ # 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
+}
+
+##
+## If the argument is the name of a vserver selected for backup (in
+## $vservers_chooser_vsnames), 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 $vservers_chooser_vsnames ; 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 among "all vservers" and a not-empty subset of these.
+## Sets global $vservers_chooser_vsnames variable to "all" or to a
+## space-separated name list.
+## Depends on host_or_vservers() to have already run.
+## $vservers_chooser_vsnames is unset when a new helper is run.
+## Returns 1 if cancelled.
+##
+vservers_chooser() {
+ local title=$1
+ local i=
+ [ -n "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR is not set in $conffile and could not be guessed."; return 1)
+ [ -d "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR ($VROOTDIR) does not exist."; return 1)
+
+ booleanBox "$title" "Do you want to backup all vservers?" ` [ -z "$vservers_chooser_vsnames" -o "$vservers_chooser_vsnames" == "all" ] || echo no`
+ if [ $? = 0 ]; then
+ vservers_chooser_vsnames="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 `ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES"`; do
+ listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver`
+ done
+ listDisplay checklist
+ [ $? = 0 ] || return 1
+ done
+ # remove quotes around each vserver name
+ vservers_chooser_vsnames=`echo $REPLY | tr -d '"'`
+ fi
+}
+
+#####################################################
## begin program
if [ ! -x "`which dialog`" ]; then
@@ -182,64 +280,51 @@ if [ ! -x "`which dialog`" ]; then
done
fi
+# bootstrap
conffile="@CFGDIR@/backupninja.conf"
if [ ! -r "$conffile" ]; then
echo "Configuration file $conffile not found."
exit 1
fi
-# find $scriptdir
-scriptdir=`grep scriptdirectory $conffile | awk '{print $3}'`
-if [ -z "$scriptdir" ]; then
- if [ -d "@datadir@" ]; then
- scriptdir="@datadir@"
- else
- echo "Could not find entry 'scriptdirectory' in $conffile"
- exit 1
- fi
-else
- if [ ! -d "$scriptdir" ]; then
- echo "Script directory $scriptdir not found."
- exit 1
- fi
-fi
-
-# find $libdir
-libdir=`grep libdirectory $conffile | awk '{print $3}'`
-if [ -z "$libdir" ]; then
+# find $libdirectory
+libdirectory=`grep '^libdirectory' $conffile | awk '{print $3}'`
+if [ -z "$libdirectory" ]; then
if [ -d "@libdir@" ]; then
- libdir="@libdir@"
+ libdirectory="@libdir@"
else
echo "Could not find entry 'libdirectory' in $conffile."
exit 1
fi
else
- if [ ! -d "$libdir" ]; then
- echo "Lib directory $libdir not found."
+ if [ ! -d "$libdirectory" ]; then
+ echo "Lib directory $libdirectory not found."
exit 1
fi
fi
-configdirectory=`grep configdirectory $conffile | awk '{print $3}'`
-if [ ! -n "$configdirectory" ]; then
- echo "Cound not find entry 'configdirectory' in $conffile"
- exit 1
-fi
-if [ ! -d "$configdirectory" ]; then
- echo "Configuration directory $configdirectory not found."
- exit 1
-fi
-
-. $libdir/easydialog
+# include shared functions
+. $libdirectory/easydialog
+. $libdirectory/tools
+# am I running as root?
if [ "$UID" != "0" ]; then
- msgBox "warning" "ninjahelper must be run by root!"
+ msgBox "warning" "$0 must be run by root!"
exit 1
fi
+# get global config options (second param is the default)
+setfile $conffile
+getconf configdirectory @CFGDIR@/backup.d
+getconf scriptdirectory @datadir@
+getconf vservers no
+getconf VSERVERINFO /usr/sbin/vserver-info
+getconf VSERVER /usr/sbin/vserver
+getconf VROOTDIR `if [ -f "$VSERVERINFO" ]; then $VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'; fi`
+
# load all the helpers
HELPERS=""
-for file in `find $scriptdir -follow -name '*.helper'`; do
+for file in `find $scriptdirectory -follow -name '*.helper'`; do
check_perms $file
. $file
done