updated autotools abstraction to properly pick up different awk, sed,
[matthijs/upstream/backupninja.git] / handlers / sys
index 8059866cea70affe63b32cbc88f9a64b44614fa4..ce9c5b03e2d523f267d950dc2186078c9e60aacf 100755 (executable)
@@ -37,18 +37,19 @@ if [ $os = "debian" ]
 then
    getconf packagesfile /var/backups/dpkg-selections.txt
    getconf packagemgr   `which dpkg`
-   getconf packagemgroptions " --get-selections \*"
+   getconf packagemgroptions ' --get-selections *'
 elif [ $os = "redhat" ]
 then
    getconf packagesfile  /var/backups/rpmpackages.txt 
    getconf packagemgr  `which rpm`
-   getconf packagemgroptions   " -qa "
+   getconf packagemgroptions   ' -qa '
 
    getconf SYSREPORT `which sysreport`
-   getconf sysreport_options " -norpm "
+   getconf sysreport_options ' -norpm '
 else
    getconf packagesfile /var/backups/unknownOS.txt
 fi
+packagemgroptions="${packagemgroptions//__star__/*}"
 
 getconf partitions yes
 getconf partitionsfile /var/backups/partitions.__star__.txt
@@ -79,47 +80,41 @@ fi
 #
 
 if [ "$packages" == "yes" ]; then
-       if [ $usevserver = yes ]
-       then
-               nodpkg="lost+found|ARCHIVES"
-               info "vserver root directory set to: $VROOTDIR"
-               for vserver in $found_vservers
-               do
-                       info "examining vserver: $vserver"
-                       running=`$VSERVERINFO $vserver RUNNING`
-                       if [ "$running" = "1" ]; then
-                           if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
-                              warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
-                              nodpkg="$nodpkg|$vserver"
-                           fi
-                       else
-                           nodpkg="$nodpkg|$vserver"
-                       fi
-
-               done
-       else
-               if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then 
-                       warning "can't find ${packagemgr}, skipping installed packages report."
-                       packages="no"
-               fi
-       fi
-fi
 
-if [ "$packages" == "yes" ]; then
-   if [ $usevserver = yes ]
-   then
-      for vserver in `ls $VROOTDIR | grep -E -v $nodpkg`
-      do
+   if [ $usevserver = yes ]; then
+      info "vserver root directory set to: $VROOTDIR"
+      for vserver in $found_vservers; do
+         info "examining vserver: $vserver"
+         # is it running ?
+         $VSERVERINFO -q $vserver RUNNING
+         if [ $? -ne 0 ]; then
+            warning "The vserver $vserver is not running."
+            continue
+         fi
+         # is $packagemgr available inside $vserver ?
+         if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
+            warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
+            continue
+         fi
+         # don't expand * since it can be used in $packagemgroptions
+         set -o noglob
         debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
         $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
+         set +o noglob
       done
    fi
    
-# We want to perform this on the host as well
-   if [ "$packages" == "yes" ]; then
+   # We want to perform this on the host as well
+   if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then 
+      warning "can't find ${packagemgr}, skipping installed packages report."
+   else
+      # don't expand * since it can be used in $packagemgroptions
+      set -o noglob
       debug "$packagemgr $packagemgroptions > $packagesfile"
       $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
+      set +o noglob
    fi
+
 fi
 
 ## System report ##############################
@@ -193,7 +188,7 @@ elif [ $os = "debian" ]; then
        echo "Level: $level" >> $sysreportfile
        for f in /etc/rc${level}.d/*; do
        # Remove /etc/Knn or Snn from beginning
-          ff=$(echo $f | sed 's_/etc/rc..d/[KS][0-9][0-9]__')
+          ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
           if [ $f != $ff ]; then
              echo $ff >> $sysreportfile
           fi
@@ -284,7 +279,7 @@ catiffile "/proc/stat"
 STATUS="Gathering information about your partitions:"
 catiffile "/proc/partitions"
 
-STATUS="Gathering information about your ksysms:"
+STATUS="Gathering information about your ksyms:"
 catiffile "/proc/ksyms"
 
 STATUS="Gathering information about slabinfo:"
@@ -448,17 +443,21 @@ fi
 # these files can be used to directly partition a disk of the same size.
 
 if [ "$partitions" == "yes" ]; then
-       devices=`$SFDISK -l | grep "^Disk /dev" | cut -d/  -f2,3 | cut -d: -f1`
+       devices=`$SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
        if [ "$devices" == "" ]; then 
           warning "No harddisks found" 
        fi
        for dev in $devices; do
+                debug "$SFDISK will try to backup partition tables for device $dev"
                [ -b $dev ] || continue
                label=${dev#/dev/}
                label=${label//\//-}
                outputfile=${partitionsfile//__star__/$label}
-               debug "$SFDISK $sfdisk_options -d /$dev > $outputfile"
-               $SFDISK $sfdisk_options -d /$dev > $outputfile
+               debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
+               $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
+                if [ $? -ne 0 ]; then
+                   warning "The partition table for $dev could not be saved."
+                fi
        done
 fi