2 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
4 ####################################################
7 function check_perms() {
9 local perms=`ls -ld $file`
10 group_w_perm=${perms:5:1}
11 world_w_perm=${perms:8:1}
12 if [ "$group_w_perm" == "w" -o "$world_w_perm" == "w" ]; then
14 echo "helper scripts must not be group or world writable! Dying on file $file"
17 if [ `ls -ld $file | awk '{print $3}'` != "root" ]; then
18 echo "helper scripts must be owned by root! Dying on file $file"
25 ## returns the next available file name given a file
26 ## in the form @CFGDIR@/backup.d/10.sys
27 ## sets variable $next_filename
31 dir=`dirname $next_filename`
32 file=`basename $next_filename`
35 while [ -f $next_filename ]; do
37 next_filename="$dir/$number.$suffix"
42 ## installs packages (passed in as $@) if not present
46 installed=`dpkg -s $pkg | grep 'ok installed'`
47 if [ -z "$installed" ]; then
48 booleanBox "install $pkg?" "This backup action requires package $pkg. Do you want to install it now?"
51 echo "hit return to continue...."
59 ## menu for the wizards
62 # (re-)initialize vservers support
65 listBegin "new action menu" "select an action to create"
66 listItem return "return to main menu"
67 for data in $HELPERS; do
69 helper_function=${data%%:*}
70 helper_info=${data##*:}
71 listItem $helper_function "$helper_info"
77 [ "$result" = "return" ] && return
78 result=${result}_wizard
83 booleanBox "remove action" "Are you sure you want to remove action file $1?"
91 echo "Hit return to continue..."
96 if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then
97 if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then
98 EDITOR="`readlink /etc/alternatives/editor`"
99 elif [ -x "`which nano`" ]; then
100 EDITOR="`which nano`"
101 elif [ -x "`which vim`" ]; then
103 elif [ -x "`which vi`" ]; then
106 echo "No suitable editor found."
107 echo "Please define $EDITOR or configure /etc/alternatives/editor."
115 backupninja --test --run $1
116 echo "Hit return to continue..."
130 filename=`basename $1`
131 inputBox "rename action" "enter a new filename" $filename
132 mv $dir/$filename $dir/$REPLY
137 base=`basename $action`
138 if [ "${base##*.}" == "disabled" ]; then
144 menuBox "action menu" "$action $first" \
145 main "return to main menu" \
146 view "view configuration" \
147 xedit "launch external editor" \
148 $enable "$enable action" \
149 name "change the filename" \
150 run "run this action now" \
151 test "do a test run" \
152 kill "remove this action"
153 [ $? = 1 ] && return;
156 "view") dialog --textbox $action 0 0;;
157 "xedit") do_xedit $action;;
158 "disable") do_disable $action; return;;
159 "enable") do_enable $action; return;;
160 "name") do_rename $action; return;;
161 "run") do_run $action;;
162 "test") do_run_test $action;;
163 "kill") do_rm_action $action; return;;
169 #####################################################
172 if [ ! -x "`which dialog`" ]; then
173 echo "ninjahelper is a menu based wizard for backupninja."
174 echo "It requires 'dialog' in order to run. Do you want to install dialog now?"
178 if [ "$install" == "yes" ]; then
179 apt-get install dialog
181 elif [ "$install" == "no" ]; then
184 echo "You must answer 'yes' or 'no'"
190 conffile="@CFGDIR@/backupninja.conf"
191 if [ ! -r "$conffile" ]; then
192 echo "Configuration file $conffile not found."
197 libdirectory=`grep '^libdirectory' $conffile | awk '{print $3}'`
198 if [ -z "$libdirectory" ]; then
199 if [ -d "@libdir@" ]; then
200 libdirectory="@libdir@"
202 echo "Could not find entry 'libdirectory' in $conffile."
206 if [ ! -d "$libdirectory" ]; then
207 echo "Lib directory $libdirectory not found."
212 # include shared functions
213 . $libdirectory/easydialog
214 . $libdirectory/tools
215 . $libdirectory/vserver
217 # am I running as root?
218 if [ "$UID" != "0" ]; then
219 msgBox "warning" "`basename $0` must be run by root!"
223 # get global config options (second param is the default)
225 getconf configdirectory @CFGDIR@/backup.d
226 getconf scriptdirectory @datadir@
228 # load all the helpers
230 for file in `find $scriptdirectory -follow -name '*.helper'`; do
235 setApplicationTitle "ninjahelper"
238 #####################################################
246 for file in `find $conf/etc/backup.d/ -type f | sort -n`; do
247 menulist="$menulist $i $file"
252 menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \
253 new "create a new backup action" \
254 quit "leave ninjahelper"
256 [ $? = 1 -o $? = 255 ] && exit 0;
259 if [ "$choice" == "new" ]; then
261 elif [ "$choice" == "quit" ]; then
264 action=${actions[$choice]};
265 if [ -f "$action" ]; then
268 msgBox "error" "error: cannot find the file '$action'"