2 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
4 ####################################################
8 ## returns the next available file name given a file
9 ## in the form @CFGDIR@/backup.d/10.sys
10 ## sets variable $next_filename
14 dir=`dirname $next_filename`
15 file=`basename $next_filename`
18 while [ -f $next_filename ]; do
20 next_filename="$dir/$number.$suffix"
25 ## installs packages (passed in as $@) if not present
29 installed=`dpkg -s $pkg | grep 'ok installed'`
30 if [ -z "$installed" ]; then
31 booleanBox "install $pkg?" "This backup action requires package $pkg. Do you want to install it now?"
34 echo "hit return to continue...."
42 ## menu for the wizards
45 # (re-)initialize vservers support
48 listBegin "new action menu" "select an action to create"
49 listItem return "return to main menu"
50 for data in $HELPERS; do
52 helper_function=${data%%:*}
53 helper_info=${data##*:}
54 listItem $helper_function "$helper_info"
60 [ "$result" = "return" -o "$result" = "" ] && return
61 run_wizard=${result}_wizard
64 # 0 is ok, 1 is cancel, anything else is bad.
65 if [ $result != 1 -a $result != 0 ]; then
66 echo "An error occurred ($result), bailing out. Hit return to continue."
72 booleanBox "remove action" "Are you sure you want to remove action file $1?"
80 echo "Hit return to continue..."
85 if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then
86 if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then
87 EDITOR="`readlink /etc/alternatives/editor`"
88 elif [ -x "`which nano`" ]; then
90 elif [ -x "`which vim`" ]; then
92 elif [ -x "`which vi`" ]; then
95 echo "No suitable editor found."
96 echo "Please define $EDITOR or configure /etc/alternatives/editor."
104 backupninja --test --run $1
105 echo "Hit return to continue..."
119 filename=`basename $1`
120 inputBox "rename action" "enter a new filename" $filename
121 mv $dir/$filename $dir/$REPLY
126 base=`basename $action`
127 if [ "${base##*.}" == "disabled" ]; then
133 menuBox "action menu" "$action $first" \
134 main "return to main menu" \
135 view "view configuration" \
136 xedit "launch external editor" \
137 $enable "$enable action" \
138 name "change the filename" \
139 run "run this action now" \
140 test "do a test run" \
141 kill "remove this action"
142 [ $? = 1 ] && return;
145 "view") dialog --textbox $action 0 0;;
146 "xedit") do_xedit $action;;
147 "disable") do_disable $action; return;;
148 "enable") do_enable $action; return;;
149 "name") do_rename $action; return;;
150 "run") do_run $action;;
151 "test") do_run_test $action;;
152 "kill") do_rm_action $action; return;;
158 #####################################################
161 if [ ! -x "`which dialog`" ]; then
162 echo "ninjahelper is a menu based wizard for backupninja."
163 echo "It requires 'dialog' in order to run. Do you want to install dialog now?"
167 if [ "$install" == "yes" ]; then
168 apt-get install dialog
170 elif [ "$install" == "no" ]; then
173 echo "You must answer 'yes' or 'no'"
179 conffile="@CFGDIR@/backupninja.conf"
180 if [ ! -r "$conffile" ]; then
181 echo "Configuration file $conffile not found."
186 libdirectory=`grep '^libdirectory' $conffile | @AWK@ '{print $3}'`
187 if [ -z "$libdirectory" ]; then
188 if [ -d "@libdir@" ]; then
189 libdirectory="@libdir@"
191 echo "Could not find entry 'libdirectory' in $conffile."
195 if [ ! -d "$libdirectory" ]; then
196 echo "Lib directory $libdirectory not found."
201 # include shared functions
202 . $libdirectory/easydialog
203 . $libdirectory/tools
204 . $libdirectory/vserver
206 # am I running as root?
207 if [ "$UID" != "0" ]; then
208 msgBox "warning" "`basename $0` must be run by root!"
212 # get global config options (second param is the default)
214 getconf configdirectory @CFGDIR@/backup.d
215 if [ ! -d $configdirectory ]; then
216 msgBox "warning" "The backupninja configuration directory $configdirectory does not exist. Ninjahelper cannot run without it!"
219 getconf scriptdirectory @datadir@
221 # load all the helpers
223 for file in `find $scriptdirectory -follow -name '*.helper'`; do
226 echo "An error occurred while loading $file. Hit return to continue."
231 setApplicationTitle "ninjahelper"
234 #####################################################
242 for file in `find ${configdirectory} -follow -mindepth 1 -maxdepth 1 -type f ! -name '.*.swp' | sort -n`; do
243 menulist="$menulist $i $file"
248 menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \
249 new "create a new backup action" \
250 quit "leave ninjahelper"
252 [ $? = 1 -o $? = 255 ] && exit 0;
255 if [ "$choice" == "new" ]; then
257 elif [ "$choice" == "quit" ]; then
260 action=${actions[$choice]};
261 if [ -f "$action" ]; then
264 msgBox "error" "error: cannot find the file '$action'"