Add a vim modeline with indentation settings.
[matthijs/upstream/backupninja.git] / src / ninjahelper.in
index 01164611b1361cf7d8cf5a4ea42db4bfce918dc0..2a7faa90c6f905b9a29e87c339d8fa88d84a408e 100755 (executable)
@@ -1,26 +1,10 @@
 #!@BASH@
 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
+# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
 
 ####################################################
 ## Functions
 
-function check_perms() {
-   local file=$1
-   local perms=`ls -ld $file`
-   group_w_perm=${perms:5:1}
-   world_w_perm=${perms:8:1}
-   if [ "$group_w_perm" == "w" -o "$world_w_perm" == "w" ]; then
-      echo $perms
-      echo "helper scripts must not be group or world writable! Dying on file $file"
-      exit
-   fi
-   if [ `ls -ld $file | awk '{print $3}'` != "root" ]; then
-      echo "helper scripts must be owned by root! Dying on file $file"
-      exit
-   fi
-}
-
-
 ##
 ## returns the next available file name given a file
 ## in the form @CFGDIR@/backup.d/10.sys
@@ -44,7 +28,7 @@ get_next_filename() {
 require_packages() {
    for pkg in "$@"; do
       installed=`dpkg -s $pkg | grep 'ok installed'`
-      if [ -z "$installed" ]; then 
+      if [ -z "$installed" ]; then
          booleanBox "install $pkg?" "This backup action requires package $pkg. Do you want to install it now?"
          if [ $? = 0 ]; then
             apt-get install $pkg
@@ -71,7 +55,7 @@ donew() {
       listItem $helper_function "$helper_info"
    done
    listDisplay menu
-    
+
    [ $? = 1 ] && return
    result="$REPLY"
    [ "$result" = "return" -o "$result" = "" ] && return
@@ -79,10 +63,10 @@ donew() {
    $run_wizard
    result=$?
    # 0 is ok, 1 is cancel, anything else is bad.
-   if [ $result != 1 -a $result != 0 ]; then    
+   if [ $result != 1 -a $result != 0 ]; then
       echo "An error occurred ($result), bailing out. Hit return to continue."
       read
-   fi 
+   fi
 }
 
 do_rm_action() {
@@ -101,17 +85,17 @@ do_run() {
 do_xedit() {
    if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then
       if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then
-        EDITOR="`readlink /etc/alternatives/editor`"
+    EDITOR="`readlink /etc/alternatives/editor`"
       elif [ -x "`which nano`" ]; then
-        EDITOR="`which nano`"
+    EDITOR="`which nano`"
       elif [ -x "`which vim`" ]; then
-        EDITOR="`which vim`"
+    EDITOR="`which vim`"
       elif [ -x "`which vi`" ]; then
-        EDITOR="`which vi`"
+    EDITOR="`which vi`"
       else
-        echo "No suitable editor found."
-        echo "Please define $EDITOR or configure /etc/alternatives/editor."
-        exit
+    echo "No suitable editor found."
+    echo "Please define $EDITOR or configure /etc/alternatives/editor."
+    exit
       fi
    fi
    $EDITOR $1
@@ -155,17 +139,17 @@ doaction() {
          name "change the filename" \
          run "run this action now" \
          test "do a test run" \
-         kill "remove this action" 
+         kill "remove this action"
       [ $? = 1 ] && return;
       result="$REPLY"
       case "$result" in
-         "view") dialog --textbox $action 0 0;; 
+         "view") dialog --textbox $action 0 0;;
          "xedit") do_xedit $action;;
          "disable") do_disable $action; return;;
          "enable") do_enable $action; return;;
          "name") do_rename $action; return;;
          "run") do_run $action;;
-         "test") do_run_test $action;; 
+         "test") do_run_test $action;;
          "kill") do_rm_action $action; return;;
          "main") return;;
       esac
@@ -195,22 +179,22 @@ fi
 # bootstrap
 conffile="@CFGDIR@/backupninja.conf"
 if [ ! -r "$conffile" ]; then
-   echo "Configuration file $conffile not found." 
+   echo "Configuration file $conffile not found."
    exit 1
 fi
 
 # find $libdirectory
-libdirectory=`grep '^libdirectory' $conffile | awk '{print $3}'`
+libdirectory=`grep '^libdirectory' $conffile | @AWK@ '{print $3}'`
 if [ -z "$libdirectory" ]; then
    if [ -d "@libdir@" ]; then
       libdirectory="@libdir@"
    else
-      echo "Could not find entry 'libdirectory' in $conffile." 
+      echo "Could not find entry 'libdirectory' in $conffile."
       exit 1
    fi
 else
    if [ ! -d "$libdirectory" ]; then
-      echo "Lib directory $libdirectory not found." 
+      echo "Lib directory $libdirectory not found."
       exit 1
    fi
 fi
@@ -238,7 +222,6 @@ getconf scriptdirectory @datadir@
 # load all the helpers
 HELPERS=""
 for file in `find $scriptdirectory -follow -name '*.helper'`; do
-   check_perms $file
    . $file
    if [ $? != 0 ]; then
       echo "An error occurred while loading $file. Hit return to continue."
@@ -257,7 +240,7 @@ while true; do
 menulist=
 action=
 let "i = 1"
-for file in `find -L ${configdirectory} -mindepth 1 -maxdepth 1 -type f ! -name '.*.swp' | sort -n`; do
+for file in `find ${configdirectory} -follow -mindepth 1 -maxdepth 1 -type f ! -name '.*.swp' | sort -n`; do
    menulist="$menulist $i $file"
    actions[$i]=$file
    let "i += 1"
@@ -265,7 +248,7 @@ done
 
 menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \
   new "create a new backup action" \
-  quit "leave ninjahelper" 
+  quit "leave ninjahelper"
 
 [ $? = 1 -o $? = 255 ] && exit 0;