OpenPKG CVS Repository
  http://cvs.openpkg.org/
  ____________________________________________________________________________

  Server: cvs.openpkg.org                  Name:   Ralf S. Engelschall
  Root:   /e/openpkg/cvs                   Email:  [EMAIL PROTECTED]
  Module: openpkg-src                      Date:   15-Jul-2003 15:44:11
  Branch: HEAD                             Handle: 2003071514441100

  Modified files:
    openpkg-src/openpkg     HISTORY rc

  Log:
    work-off run-command processor again:
    - separately capture stdout and stderr from scripts
    - add -o/--output to script header command line ("%<name> -o")
      which appends the stdout of the executed script (if successfully) to a
      globally captured output which in turn is printed to stdout after the
      current command of all scripts were executed.
    - exit with a global return value which is 0 if all(!) scripts
      executed successfully or 1 if any script failed
    - perform a better cleanup in case of "rc all foo" and no
      scripts contain a "foo" command script.

  Summary:
    Revision    Changes     Path
    1.14        +1  -0      openpkg-src/openpkg/HISTORY
    1.36        +33 -15     openpkg-src/openpkg/rc
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: openpkg-src/openpkg/HISTORY
  ============================================================================
  $ cvs diff -u -r1.13 -r1.14 HISTORY
  --- openpkg-src/openpkg/HISTORY       15 Jul 2003 08:48:08 -0000      1.13
  +++ openpkg-src/openpkg/HISTORY       15 Jul 2003 13:44:11 -0000      1.14
  @@ -2,6 +2,7 @@
   2003
   ====
   
  +20030715 work-off "rc" again: add -o/--output options, better cleanup, global 
return code
   20030715 add to "rc" the -v/--verbose option again and provide terminal-detection
   20030714 reduce run-time of "rc" --eval/--print operations by parsing %config 
sections just once
   20030714 add convinience macros %l_rc and %l_rpm; resolve conflict with openpkg-rc 
package
  @@ .
  patch -p0 <<'@@ .'
  Index: openpkg-src/openpkg/rc
  ============================================================================
  $ cvs diff -u -r1.35 -r1.36 rc
  --- openpkg-src/openpkg/rc    15 Jul 2003 08:48:08 -0000      1.35
  +++ openpkg-src/openpkg/rc    15 Jul 2003 13:44:11 -0000      1.36
  @@ -120,7 +120,9 @@
   #   set a reasonable temporary location
   tmpdir="/tmp"
   tmpfile="$tmpdir/rc.$$.tmp"
  -logfile="$tmpdir/rc.$$.log"
  +outfile="$tmpdir/rc.$$.out"
  +errfile="$tmpdir/rc.$$.err"
  +allfile="$tmpdir/rc.$$.all"
   TMPDIR="$tmpdir";  export TMPDIR
   TEMPDIR="$tmpdir"; export TEMPDIR
   
  @@ -241,8 +243,13 @@
   fi
   
   #   iterate over the commands
  +rv=0
   cmds="$*"
   for cmd in $cmds; do
  +    if [ ".$print" = .0 -a ".$eval" = .0 ]; then
  +        rm -f $allfile
  +        touch $allfile
  +    fi
   
       #   find scripts which contain the command and determine
       #   their individual user/prio settings
  @@ -259,6 +266,7 @@
           fi
   
           #   check script options
  +        #   (currently unused in OpenPKG)
           shebangline=`head -1 $rcdir/rc.$s_name | grep "^#!rc"`
           if [ ".$shebangline" != . ]; then
               shebangopts=`echo "$shebangline" | sed -e "s;^#!rc *;;"`
  @@ -290,6 +298,7 @@
               cmdopts=`echo "$cmdline" | sed -e "s;^%$cmd *;;"`
               s_user=$user
               s_prio=500
  +            s_output=no
               set -- $cmdopts;
               prev=''
               for opt
  @@ -307,6 +316,7 @@
                       -u|-p         ) prev=$opt    ;;
                       -e|--enable   ) enable=yes   ;;
                       -d|--disable  ) enable=no    ;;
  +                    -o|--output   ) s_output=yes ;;
                       -u*|--user=*  ) s_user=$arg  ;;
                       -p*|--prio=*  ) s_prio=$arg  ;;
                       *             ) echo "openpkg:rc:WARNING: invalid option 
\"$opt\" in \"$rcdir/rc.$s_name:%$cmd\""; break ;;
  @@ -321,7 +331,7 @@
               if [ ".$enable" != .yes ]; then
                   continue
               fi
  -            list="$list,$s_prio:$s_name:$s_user"
  +            list="$list,$s_prio:$s_name:$s_user:$s_output"
           else
               if [ ".$isall" = .0 ]; then
                   echo "openpkg:rc:ERROR: $s_name: command \"$cmd\" not found" 1>&2
  @@ -335,7 +345,8 @@
                   ;;
               * ) 
                   echo "openpkg:rc:ERROR: command \"$cmd\" not found in any script" 
1>&2
  -                exit 1
  +                rv=1
  +                break
                   ;;
           esac
       fi
  @@ -360,7 +371,7 @@
       verbose_pos=0
       for entry in `echo $list | tr ',' '\012' | sort -n`; do
           test ".$entry" = . && continue
  -        eval `echo $entry | sed -e 's%^[0-9]*:\(.*\):\(.*\)$%s_name="\1"; 
s_user="\2"%'`
  +        eval `echo $entry | sed -e 's%^[0-9]*:\(.*\):\(.*\):\(.*\)$%s_name="\1"; 
s_user="\2"; s_output="\3";%'`
           if [ ".$print" = .0 -a ".$eval" = .0 ]; then
               if [ $verbose_pos -gt 70 ]; then
                   verbose_pos=0
  @@ -393,10 +404,8 @@
               sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d'
               continue
           fi
  -        rm -f $tmpfile
  -        touch $tmpfile
  -        rm -f $logfile
  -        touch $logfile
  +        rm -f $tmpfile $outfile $errfile
  +        touch $tmpfile $outfile $errfile
           if [ ".$debug" = .1 ]; then
               echo "set -x" >>$tmpfile
           fi
  @@ -411,10 +420,10 @@
           sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d'
           sh="@l_prefix@/lib/openpkg/bash"
           if [ ".$user" != ".$s_user" ]; then
  -            su - $s_user -c "PATH=\"$PATH\"; $sh $tmpfile" >$logfile 2>&1
  +            su - $s_user -c "PATH=\"$PATH\"; $sh $tmpfile" >$outfile 2>$errfile
               rc=$?
           else
  -            $sh $tmpfile >$logfile 2>&1
  +            $sh $tmpfile >$outfile 2>$errfile
               rc=$?
           fi
           if [ $rc -ne 0 ]; then
  @@ -422,14 +431,19 @@
                   echo ":FAILED" 1>&2
               fi
               echo "openpkg:rc:WARNING: @l_prefix@:$s_name:%$cmd: failed with return 
code $rc" 1>&2
  -            if [ ".`cat $logfile`" != . ]; then
  -                ( echo 
"+----Output:-----------------------------------------------------------"
  -                  cat $logfile | sed -e 's;^;| ;'
  +            if [ ".`cat $outfile $errfile`" != . ]; then
  +                ( echo 
"+----Log:--------------------------------------------------------------"
  +                  cat $outfile $errfile | sed -e 's;^;| ;'
                     echo 
"+----------------------------------------------------------------------"
                   ) 1>&2
               fi
               verbose_first=1
               verbose_pos=0
  +            rv=1
  +        else
  +            if [ ".$s_output" = .yes ]; then
  +                cat $outfile >>$allfile
  +            fi
           fi
       done
       if [ ".$print" = .1 -o ".$eval" = .1 ]; then
  @@ -442,12 +456,16 @@
           if [ ".$silent" != .1 -a ".$verbose_output" = .1 -a $verbose_pos -gt 0 ]; 
then
               echo "." 1>&2
           fi
  +        cat $allfile
       fi
   done
   
  -#   cleanup
  -rm -f $logfile >/dev/null 2>&1 || true
  +#   cleanup temporary files
  +rm -f $outfile $errfile $allfile >/dev/null 2>&1 || true
   if [ ".$eval" = .0 ]; then
       rm -f $tmpfile >/dev/null 2>&1 || true
   fi
  +
  +#   exit gracefully with global return value
  +exit $rv
   
  @@ .
______________________________________________________________________
The OpenPKG Project                                    www.openpkg.org
CVS Repository Commit List                     [EMAIL PROTECTED]

Reply via email to