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" -o "$result" = "" ] && return
78 run_wizard=${result}_wizard
81 # 0 is ok, 1 is cancel, anything else is bad.
82 if [ $result != 1 -a $result != 0 ]; then
83 echo "An error occurred ($result), bailing out. Hit return to continue."
89 booleanBox "remove action" "Are you sure you want to remove action file $1?"
97 echo "Hit return to continue..."
102 if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then
103 if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then
104 EDITOR="`readlink /etc/alternatives/editor`"
105 elif [ -x "`which nano`" ]; then
106 EDITOR="`which nano`"
107 elif [ -x "`which vim`" ]; then
109 elif [ -x "`which vi`" ]; then
112 echo "No suitable editor found."
113 echo "Please define $EDITOR or configure /etc/alternatives/editor."
121 backupninja --test --run $1
122 echo "Hit return to continue..."
136 filename=`basename $1`
137 inputBox "rename action" "enter a new filename" $filename
138 mv $dir/$filename $dir/$REPLY
143 base=`basename $action`
144 if [ "${base##*.}" == "disabled" ]; then
150 menuBox "action menu" "$action $first" \
151 main "return to main menu" \
152 view "view configuration" \
153 xedit "launch external editor" \
154 $enable "$enable action" \
155 name "change the filename" \
156 run "run this action now" \
157 test "do a test run" \
158 kill "remove this action"
159 [ $? = 1 ] && return;
162 "view") dialog --textbox $action 0 0;;
163 "xedit") do_xedit $action;;
164 "disable") do_disable $action; return;;
165 "enable") do_enable $action; return;;
166 "name") do_rename $action; return;;
167 "run") do_run $action;;
168 "test") do_run_test $action;;
169 "kill") do_rm_action $action; return;;
175 #####################################################
178 if [ ! -x "`which dialog`" ]; then
179 echo "ninjahelper is a menu based wizard for backupninja."
180 echo "It requires 'dialog' in order to run. Do you want to install dialog now?"
184 if [ "$install" == "yes" ]; then
185 apt-get install dialog
187 elif [ "$install" == "no" ]; then
190 echo "You must answer 'yes' or 'no'"
196 conffile="@CFGDIR@/backupninja.conf"
197 if [ ! -r "$conffile" ]; then
198 echo "Configuration file $conffile not found."
203 libdirectory=`grep '^libdirectory' $conffile | awk '{print $3}'`
204 if [ -z "$libdirectory" ]; then
205 if [ -d "@libdir@" ]; then
206 libdirectory="@libdir@"
208 echo "Could not find entry 'libdirectory' in $conffile."
212 if [ ! -d "$libdirectory" ]; then
213 echo "Lib directory $libdirectory not found."
218 # include shared functions
219 . $libdirectory/easydialog
220 . $libdirectory/tools
221 . $libdirectory/vserver
223 # am I running as root?
224 if [ "$UID" != "0" ]; then
225 msgBox "warning" "`basename $0` must be run by root!"
229 # get global config options (second param is the default)
231 getconf configdirectory @CFGDIR@/backup.d
232 if [ ! -d $configdirectory ]; then
233 msgBox "warning" "The backupninja configuration directory $configdirectory does not exist. Ninjahelper cannot run without it!"
236 getconf scriptdirectory @datadir@
238 # load all the helpers
240 for file in `find $scriptdirectory -follow -name '*.helper'`; do
244 echo "An error occurred while loading $file. Hit return to continue."
249 setApplicationTitle "ninjahelper"
252 #####################################################
260 for file in `find $conf/etc/backup.d/ -type f | sort -n`; do
261 menulist="$menulist $i $file"
266 menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \
267 new "create a new backup action" \
268 quit "leave ninjahelper"
270 [ $? = 1 -o $? = 255 ] && exit 0;
273 if [ "$choice" == "new" ]; then
275 elif [ "$choice" == "quit" ]; then
278 action=${actions[$choice]};
279 if [ -f "$action" ]; then
282 msgBox "error" "error: cannot find the file '$action'"