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 /etc/backup.d/10.sys
26 ## sets variable $returned_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 listBegin "new action menu" "select an action to create"
62 listItem return "return to main menu"
63 for data in $HELPERS; do
65 helper_function=${data%%:*}
66 helper_info=${data##*:}
67 listItem $helper_function "$helper_info"
73 [ "$result" = "return" ] && return
74 result=${result}_wizard
79 booleanBox "remove action" "Are you sure you want to remove action file $1?"
87 echo "Hit return to continue..."
92 if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then
93 if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then
94 EDITOR="`readlink /etc/alternatives/editor`"
95 elif [ -x "`which nano`" ]; then
97 elif [ -x "`which vim`" ]; then
99 elif [ -x "`which vi`" ]; then
102 echo "No suitable editor found."
103 echo "Please define $EDITOR or configure /etc/alternatives/editor."
111 backupninja --test --run $1
112 echo "Hit return to continue..."
126 filename=`basename $1`
127 inputBox "rename action" "enter a new filename" $filename
128 mv $dir/$filename $dir/$REPLY
133 base=`basename $action`
134 if [ "${base##*.}" == "disabled" ]; then
140 menuBox "action menu" "$action $first" \
141 main "return to main menu" \
142 view "view configuration" \
143 xedit "launch external editor" \
144 $enable "$enable action" \
145 name "change the filename" \
146 run "run this action now" \
147 test "test connections and passwords only" \
148 kill "remove this action"
149 [ $? = 1 ] && return;
152 "view") dialog --textbox $action 0 0;;
153 "xedit") do_xedit $action;;
154 "disable") do_disable $action; return;;
155 "enable") do_enable $action; return;;
156 "name") do_rename $action; return;;
157 "run") do_run $action;;
158 "test") do_run_test $action;;
159 "kill") do_rm_action $action; return;;
165 #####################################################
168 if [ ! -x "`which dialog`" ]; then
169 echo "ninjahelper is a menu based wizard for backupninja."
170 echo "It requires 'dialog' in order to run. Do you want to install dialog now?"
174 if [ "$install" == "yes" ]; then
175 apt-get install dialog
177 elif [ "$install" == "no" ]; then
180 echo "You must answer 'yes' or 'no'"
185 conffile="/etc/backupninja.conf"
186 if [ ! -r "$conffile" ]; then
187 echo "Configuration file $conffile not found."
190 scriptdir=`grep scriptdirectory $conffile | awk '{print $3}'`
191 if [ ! -n "$scriptdir" ]; then
192 echo "Cound not find entry 'scriptdirectory' in $conffile"
195 if [ ! -d "$scriptdir" ]; then
196 echo "Script directory $scriptdir not found."
199 configdirectory=`grep configdirectory $conffile | awk '{print $3}'`
200 if [ ! -n "$configdirectory" ]; then
201 echo "Cound not find entry 'configdirectory' in $conffile"
204 if [ ! -d "$configdirectory" ]; then
205 echo "Configuration directory $configdirectory not found."
209 . $scriptdir/easydialog.sh
211 if [ "$UID" != "0" ]; then
212 msgBox "warning" "ninjahelper must be run by root!"
216 # load all the helpers
218 for file in `find $scriptdir -follow -name '*.helper'`; do
223 setApplicationTitle "ninjahelper"
226 #####################################################
234 for file in `find $conf/etc/backup.d/ -type f | sort -n`; do
235 menulist="$menulist $i $file"
240 menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \
241 new "create a new backup action" \
242 quit "leave ninjahelper"
244 [ $? = 1 -o $? = 255 ] && exit 0;
247 if [ "$choice" == "new" ]; then
249 elif [ "$choice" == "quit" ]; then
252 action=${actions[$choice]};
253 if [ -f "$action" ]; then
256 msgBox "error" "error: cannot find the file '$action'"