3 ####################################################
6 function check_perms() {
8 local perms=`ls -ld $file`
9 group_w_perm=${perms:5:1}
10 world_w_perm=${perms:8:1}
11 if [ "$group_w_perm" == "w" -o "$world_w_perm" == "w" ]; then
13 echo "helper scripts must not be group or world writable! Dying on file $file"
16 if [ `ls -ld $file | awk '{print $3}'` != "root" ]; then
17 echo "helper scripts must be owned by root! Dying on file $file"
24 ## returns the next available file name given a file
25 ## in the form @CFGDIR@/backup.d/10.sys
26 ## sets variable $next_filename
30 dir=`dirname $next_filename`
31 file=`basename $next_filename`
34 while [ -f $next_filename ]; do
36 next_filename="$dir/$number.$suffix"
41 ## installs packages (passed in as $@) if not present
45 installed=`dpkg -s $pkg | grep 'ok installed'`
46 if [ -z "$installed" ]; then
47 booleanBox "install $pkg?" "This backup action requires package $pkg. Do you want to install it now?"
50 echo "hit return to continue...."
58 ## menu for the wizards
61 # (re-)initialize vservers support
64 listBegin "new action menu" "select an action to create"
65 listItem return "return to main menu"
66 for data in $HELPERS; do
68 helper_function=${data%%:*}
69 helper_info=${data##*:}
70 listItem $helper_function "$helper_info"
76 [ "$result" = "return" ] && return
77 result=${result}_wizard
82 booleanBox "remove action" "Are you sure you want to remove action file $1?"
90 echo "Hit return to continue..."
95 if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then
96 if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then
97 EDITOR="`readlink /etc/alternatives/editor`"
98 elif [ -x "`which nano`" ]; then
100 elif [ -x "`which vim`" ]; then
102 elif [ -x "`which vi`" ]; then
105 echo "No suitable editor found."
106 echo "Please define $EDITOR or configure /etc/alternatives/editor."
114 backupninja --test --run $1
115 echo "Hit return to continue..."
129 filename=`basename $1`
130 inputBox "rename action" "enter a new filename" $filename
131 mv $dir/$filename $dir/$REPLY
136 base=`basename $action`
137 if [ "${base##*.}" == "disabled" ]; then
143 menuBox "action menu" "$action $first" \
144 main "return to main menu" \
145 view "view configuration" \
146 xedit "launch external editor" \
147 $enable "$enable action" \
148 name "change the filename" \
149 run "run this action now" \
150 test "do a test run" \
151 kill "remove this action"
152 [ $? = 1 ] && return;
155 "view") dialog --textbox $action 0 0;;
156 "xedit") do_xedit $action;;
157 "disable") do_disable $action; return;;
158 "enable") do_enable $action; return;;
159 "name") do_rename $action; return;;
160 "run") do_run $action;;
161 "test") do_run_test $action;;
162 "kill") do_rm_action $action; return;;
168 #####################################################
171 if [ ! -x "`which dialog`" ]; then
172 echo "ninjahelper is a menu based wizard for backupninja."
173 echo "It requires 'dialog' in order to run. Do you want to install dialog now?"
177 if [ "$install" == "yes" ]; then
178 apt-get install dialog
180 elif [ "$install" == "no" ]; then
183 echo "You must answer 'yes' or 'no'"
189 conffile="@CFGDIR@/backupninja.conf"
190 if [ ! -r "$conffile" ]; then
191 echo "Configuration file $conffile not found."
196 libdirectory=`grep '^libdirectory' $conffile | awk '{print $3}'`
197 if [ -z "$libdirectory" ]; then
198 if [ -d "@libdir@" ]; then
199 libdirectory="@libdir@"
201 echo "Could not find entry 'libdirectory' in $conffile."
205 if [ ! -d "$libdirectory" ]; then
206 echo "Lib directory $libdirectory not found."
211 # include shared functions
212 . $libdirectory/easydialog
213 . $libdirectory/tools
214 . $libdirectory/vserver
216 # am I running as root?
217 if [ "$UID" != "0" ]; then
218 msgBox "warning" "`basename $0` must be run by root!"
222 # get global config options (second param is the default)
224 getconf configdirectory @CFGDIR@/backup.d
225 getconf scriptdirectory @datadir@
227 # load all the helpers
229 for file in `find $scriptdirectory -follow -name '*.helper'`; do
234 setApplicationTitle "ninjahelper"
237 #####################################################
245 for file in `find $conf/etc/backup.d/ -type f | sort -n`; do
246 menulist="$menulist $i $file"
251 menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \
252 new "create a new backup action" \
253 quit "leave ninjahelper"
255 [ $? = 1 -o $? = 255 ] && exit 0;
258 if [ "$choice" == "new" ]; then
260 elif [ "$choice" == "quit" ]; then
263 action=${actions[$choice]};
264 if [ -f "$action" ]; then
267 msgBox "error" "error: cannot find the file '$action'"