#!@BASH@
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
+# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
####################################################
## Functions
-function check_perms() {
- local file=$1
- local perms=`ls -ld $file`
- group_w_perm=${perms:5:1}
- world_w_perm=${perms:8:1}
- if [ "$group_w_perm" == "w" -o "$world_w_perm" == "w" ]; then
- echo $perms
- echo "helper scripts must not be group or world writable! Dying on file $file"
- exit
- fi
- if [ `ls -ld $file | awk '{print $3}'` != "root" ]; then
- echo "helper scripts must be owned by root! Dying on file $file"
- exit
- fi
-}
-
-
##
## returns the next available file name given a file
## in the form @CFGDIR@/backup.d/10.sys
require_packages() {
for pkg in "$@"; do
installed=`dpkg -s $pkg | grep 'ok installed'`
- if [ -z "$installed" ]; then
+ if [ -z "$installed" ]; then
booleanBox "install $pkg?" "This backup action requires package $pkg. Do you want to install it now?"
if [ $? = 0 ]; then
apt-get install $pkg
listItem $helper_function "$helper_info"
done
listDisplay menu
-
+
[ $? = 1 ] && return
result="$REPLY"
[ "$result" = "return" -o "$result" = "" ] && return
$run_wizard
result=$?
# 0 is ok, 1 is cancel, anything else is bad.
- if [ $result != 1 -a $result != 0 ]; then
+ if [ $result != 1 -a $result != 0 ]; then
echo "An error occurred ($result), bailing out. Hit return to continue."
read
- fi
+ fi
}
do_rm_action() {
do_xedit() {
if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then
if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then
- EDITOR="`readlink /etc/alternatives/editor`"
+ EDITOR="`readlink /etc/alternatives/editor`"
elif [ -x "`which nano`" ]; then
- EDITOR="`which nano`"
+ EDITOR="`which nano`"
elif [ -x "`which vim`" ]; then
- EDITOR="`which vim`"
+ EDITOR="`which vim`"
elif [ -x "`which vi`" ]; then
- EDITOR="`which vi`"
+ EDITOR="`which vi`"
else
- echo "No suitable editor found."
- echo "Please define $EDITOR or configure /etc/alternatives/editor."
- exit
+ echo "No suitable editor found."
+ echo "Please define $EDITOR or configure /etc/alternatives/editor."
+ exit
fi
fi
$EDITOR $1
name "change the filename" \
run "run this action now" \
test "do a test run" \
- kill "remove this action"
+ kill "remove this action"
[ $? = 1 ] && return;
result="$REPLY"
case "$result" in
- "view") dialog --textbox $action 0 0;;
+ "view") dialog --textbox $action 0 0;;
"xedit") do_xedit $action;;
"disable") do_disable $action; return;;
"enable") do_enable $action; return;;
"name") do_rename $action; return;;
"run") do_run $action;;
- "test") do_run_test $action;;
+ "test") do_run_test $action;;
"kill") do_rm_action $action; return;;
"main") return;;
esac
# bootstrap
conffile="@CFGDIR@/backupninja.conf"
if [ ! -r "$conffile" ]; then
- echo "Configuration file $conffile not found."
+ echo "Configuration file $conffile not found."
exit 1
fi
# find $libdirectory
-libdirectory=`grep '^libdirectory' $conffile | awk '{print $3}'`
+libdirectory=`grep '^libdirectory' $conffile | @AWK@ '{print $3}'`
if [ -z "$libdirectory" ]; then
if [ -d "@libdir@" ]; then
libdirectory="@libdir@"
else
- echo "Could not find entry 'libdirectory' in $conffile."
+ echo "Could not find entry 'libdirectory' in $conffile."
exit 1
fi
else
if [ ! -d "$libdirectory" ]; then
- echo "Lib directory $libdirectory not found."
+ echo "Lib directory $libdirectory not found."
exit 1
fi
fi
# load all the helpers
HELPERS=""
for file in `find $scriptdirectory -follow -name '*.helper'`; do
- check_perms $file
. $file
if [ $? != 0 ]; then
echo "An error occurred while loading $file. Hit return to continue."
menulist=
action=
let "i = 1"
-for file in `find $conf/etc/backup.d/ -mindepth 1 -maxdepth 1 -type f ! -name '.*.swp' | sort -n`; do
+for file in `find ${configdirectory} -follow -mindepth 1 -maxdepth 1 -type f ! -name '.*.swp' | sort -n`; do
menulist="$menulist $i $file"
actions[$i]=$file
let "i += 1"
menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \
new "create a new backup action" \
- quit "leave ninjahelper"
+ quit "leave ninjahelper"
[ $? = 1 -o $? = 255 ] && exit 0;