3 ####################################################
6 function check_perms() {
8 local perms=`ls -ld $file`
10 if [[ "$perms" != "------" && "$perms" != "r--r--" ]]; then
12 echo "helper scripts must not be group or world writable! Dying on file $file"
15 if [ `ls -ld $file | awk '{print $3}'` != "root" ]; then
16 echo "helper scripts must be owned by root! Dying on file $file"
23 ## returns the next available file name given a file
24 ## in the form /etc/backup.d/10.sys
25 ## sets variable $returned_filename
29 dir=`dirname $next_filename`
30 file=`basename $next_filename`
33 while [ -f $next_filename ]; do
35 next_filename="$dir/$number.$suffix"
40 ## installs packages (passed in as $@) if not present
44 installed=`dpkg -s $pkg | grep 'ok installed'`
45 if [ -z "$installed" ]; then
46 booleanBox "install $pkg?" "This backup action requires package $pkg. Do you want to install it now?"
49 echo "hit return to continue...."
57 ## menu for the wizards
60 listBegin "new action menu" "select an action to create"
61 listItem return "return to main menu"
62 for data in $HELPERS; do
64 helper_function=${data%%:*}
65 helper_info=${data##*:}
66 listItem $helper_function "$helper_info"
72 [ "$result" = "return" ] && return
73 result=${result}_wizard
78 booleanBox "remove action" "Are you sure you want to remove action file $1?"
86 echo "Hit return to continue..."
91 backupninja --test --run $1
92 echo "Hit return to continue..."
106 filename=`basename $1`
107 inputBox "rename action" "enter a new filename" $filename
108 mv $dir/$filename $dir/$REPLY
113 base=`basename $action`
114 if [ "${base##*.}" == "disabled" ]; then
120 menuBox "action menu" "$action $first" \
121 main "return to main menu" \
122 view "view configuration" \
123 xedit "launch external editor" \
124 $enable "$enable action" \
125 name "change the filename" \
126 run "run this action now" \
127 test "do a test run" \
128 kill "remove this action"
129 [ $? = 1 ] && return;
132 "view") dialog --textbox $action 0 0;;
133 "xedit") $EDITOR $action;;
134 "disable") do_disable $action; return;;
135 "enable") do_enable $action; return;;
136 "name") do_rename $action; return;;
137 "run") do_run $action;;
138 "test") do_run_test $action;;
139 "kill") do_rm_action $action; return;;
145 #####################################################
148 conffile="/etc/backupninja.conf"
149 if [ ! -r "$conffile" ]; then
150 echo "Configuration file $conffile not found."
153 scriptdir=`grep scriptdirectory $conffile | awk '{print $3}'`
154 if [ ! -n "$scriptdir" ]; then
155 echo "Cound not find entry 'scriptdirectory' in $conffile"
158 if [ ! -d "$scriptdir" ]; then
159 echo "Script directory $scriptdir not found."
162 configdirectory=`grep configdirectory $conffile | awk '{print $3}'`
163 if [ ! -n "$configdirectory" ]; then
164 echo "Cound not find entry 'configdirectory' in $conffile"
167 if [ ! -d "$configdirectory" ]; then
168 echo "Configuration directory $configdirectory not found."
172 . $scriptdir/easydialog.sh
174 if [ "$UID" != "0" ]; then
175 msgBox "warning" "ninjahelper must be run by root!"
179 # load all the helpers
181 for file in `find $scriptdir -follow -name '*.helper'`; do
186 setApplicationTitle "ninjahelper"
189 #####################################################
197 for file in `find $conf/etc/backup.d/ -type f | sort -n`; do
198 menulist="$menulist $i $file"
203 menuBox "main menu" "select an action to edit" $menulist \
204 new "create a new backup action" \
205 quit "leave ninjahelper"
207 [ $? = 1 -o $? = 255 ] && exit 0;
210 if [ "$choice" == "new" ]; then
212 elif [ "$choice" == "quit" ]; then
215 action=${actions[$choice]};
216 if [ -f "$action" ]; then
219 msgBox "error" "error: cannot find the file '$action'"