2 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
3 # vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
5 ####################################################
9 ## returns the next available file name given a file
10 ## in the form @CFGDIR@/backup.d/10.sys
11 ## sets variable $next_filename
15 dir=`dirname $next_filename`
16 file=`basename $next_filename`
19 while [ -f $next_filename ]; do
21 next_filename="$dir/$number.$suffix"
26 ## installs packages (passed in as $@) if not present
30 installed=`dpkg -s $pkg | grep 'ok installed'`
31 if [ -z "$installed" ]; then
32 booleanBox "install $pkg?" "This backup action requires package $pkg. Do you want to install it now?"
35 echo "hit return to continue...."
43 ## menu for the wizards
46 # (re-)initialize vservers support
49 listBegin "new action menu" "select an action to create"
50 listItem return "return to main menu"
51 for data in $HELPERS; do
53 helper_function=${data%%:*}
54 helper_info=${data##*:}
55 listItem $helper_function "$helper_info"
61 [ "$result" = "return" -o "$result" = "" ] && return
62 run_wizard=${result}_wizard
65 # 0 is ok, 1 is cancel, anything else is bad.
66 if [ $result != 1 -a $result != 0 ]; then
67 echo "An error occurred ($result), bailing out. Hit return to continue."
73 booleanBox "remove action" "Are you sure you want to remove action file $1?"
81 echo "Hit return to continue..."
86 if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then
87 if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then
88 EDITOR="`readlink /etc/alternatives/editor`"
89 elif [ -x "`which nano`" ]; then
91 elif [ -x "`which vim`" ]; then
93 elif [ -x "`which vi`" ]; then
96 echo "No suitable editor found."
97 echo "Please define $EDITOR or configure /etc/alternatives/editor."
105 backupninja --test --run $1
106 echo "Hit return to continue..."
120 filename=`basename $1`
121 inputBox "rename action" "enter a new filename" $filename
122 mv $dir/$filename $dir/$REPLY
127 base=`basename $action`
128 if [ "${base##*.}" == "disabled" ]; then
134 menuBox "action menu" "$action $first" \
135 main "return to main menu" \
136 view "view configuration" \
137 xedit "launch external editor" \
138 $enable "$enable action" \
139 name "change the filename" \
140 run "run this action now" \
141 test "do a test run" \
142 kill "remove this action"
143 [ $? = 1 ] && return;
146 "view") dialog --textbox $action 0 0;;
147 "xedit") do_xedit $action;;
148 "disable") do_disable $action; return;;
149 "enable") do_enable $action; return;;
150 "name") do_rename $action; return;;
151 "run") do_run $action;;
152 "test") do_run_test $action;;
153 "kill") do_rm_action $action; return;;
159 #####################################################
162 if [ ! -x "`which dialog`" ]; then
163 echo "ninjahelper is a menu based wizard for backupninja."
164 echo "It requires 'dialog' in order to run. Do you want to install dialog now?"
168 if [ "$install" == "yes" ]; then
169 apt-get install dialog
171 elif [ "$install" == "no" ]; then
174 echo "You must answer 'yes' or 'no'"
180 conffile="@CFGDIR@/backupninja.conf"
181 if [ ! -r "$conffile" ]; then
182 echo "Configuration file $conffile not found."
187 libdirectory=`grep '^libdirectory' $conffile | @AWK@ '{print $3}'`
188 if [ -z "$libdirectory" ]; then
189 if [ -d "@libdir@" ]; then
190 libdirectory="@libdir@"
192 echo "Could not find entry 'libdirectory' in $conffile."
196 if [ ! -d "$libdirectory" ]; then
197 echo "Lib directory $libdirectory not found."
202 # include shared functions
203 . $libdirectory/easydialog
204 . $libdirectory/tools
205 . $libdirectory/vserver
207 # am I running as root?
208 if [ "$UID" != "0" ]; then
209 msgBox "warning" "`basename $0` must be run by root!"
213 # get global config options (second param is the default)
215 getconf configdirectory @CFGDIR@/backup.d
216 if [ ! -d $configdirectory ]; then
217 msgBox "warning" "The backupninja configuration directory $configdirectory does not exist. Ninjahelper cannot run without it!"
220 getconf scriptdirectory @datadir@
222 # load all the helpers
224 for file in `find $scriptdirectory -follow -name '*.helper'`; do
227 echo "An error occurred while loading $file. Hit return to continue."
232 setApplicationTitle "ninjahelper"
235 #####################################################
243 for file in `find ${configdirectory} -follow -mindepth 1 -maxdepth 1 -type f ! -name '.*.swp' | sort -n`; do
244 menulist="$menulist $i $file"
249 menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \
250 new "create a new backup action" \
251 quit "leave ninjahelper"
253 [ $? = 1 -o $? = 255 ] && exit 0;
256 if [ "$choice" == "new" ]; then
258 elif [ "$choice" == "quit" ]; then
261 action=${actions[$choice]};
262 if [ -f "$action" ]; then
265 msgBox "error" "error: cannot find the file '$action'"