|
@@ -64,6 +64,7 @@ silent=0
|
|
|
verbose=0
|
|
verbose=0
|
|
|
debug=0
|
|
debug=0
|
|
|
help=0
|
|
help=0
|
|
|
|
|
+keep=0
|
|
|
print=0
|
|
print=0
|
|
|
eval=0
|
|
eval=0
|
|
|
config=0
|
|
config=0
|
|
@@ -81,6 +82,7 @@ while [ $# -gt 0 ]; do
|
|
|
-v|--verbose ) verbose=1 ;;
|
|
-v|--verbose ) verbose=1 ;;
|
|
|
-d|--debug ) debug=1 ;;
|
|
-d|--debug ) debug=1 ;;
|
|
|
-h|--help ) help="Usage" ;;
|
|
-h|--help ) help="Usage" ;;
|
|
|
|
|
+ -k|--keep ) keep=1 ;;
|
|
|
-p|--print ) print=1 ;;
|
|
-p|--print ) print=1 ;;
|
|
|
-e|--eval ) eval=1 ;;
|
|
-e|--eval ) eval=1 ;;
|
|
|
-c|--config ) config=1 ;;
|
|
-c|--config ) config=1 ;;
|
|
@@ -96,7 +98,7 @@ if [ ".$help" != .0 ]; then
|
|
|
if [ ".$help" != ".Usage" ]; then
|
|
if [ ".$help" != ".Usage" ]; then
|
|
|
echo "$progname:ERROR: $help" 1>&2
|
|
echo "$progname:ERROR: $help" 1>&2
|
|
|
fi
|
|
fi
|
|
|
- echo "Usage: $progname [-s|--silent] [-v|--verbose] [-d|--debug] [-h|--help]" 1>&2
|
|
|
|
|
|
|
+ echo "Usage: $progname [-s|--silent] [-v|--verbose] [-d|--debug] [-k|--keep] [-h|--help]" 1>&2
|
|
|
echo " [-p|--print] [-e|--eval] [-c|--config] [-q|--query]" 1>&2
|
|
echo " [-p|--print] [-e|--eval] [-c|--config] [-q|--query]" 1>&2
|
|
|
echo " <package> <command> [<command> ...]" 1>&2
|
|
echo " <package> <command> [<command> ...]" 1>&2
|
|
|
if [ ".$help" != ".Usage" ]; then
|
|
if [ ".$help" != ".Usage" ]; then
|
|
@@ -411,8 +413,13 @@ for cmd in $cmds; do
|
|
|
echo ". $rcconf" >>$tmpfile
|
|
echo ". $rcconf" >>$tmpfile
|
|
|
|
|
|
|
|
# for --eval redirect stderr and stdout (but remember stdout)
|
|
# for --eval redirect stderr and stdout (but remember stdout)
|
|
|
|
|
+ # (let stderr pass unfiltered in case of debug mode)
|
|
|
if [ ".$eval" = .1 ]; then
|
|
if [ ".$eval" = .1 ]; then
|
|
|
- echo "exec 3<&1- 1>/dev/null 2>/dev/null" >>$tmpfile
|
|
|
|
|
|
|
+ if [ ".$debug" = .1 ]; then
|
|
|
|
|
+ echo "exec 3<&1- 1>/dev/null" >>$tmpfile
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "exec 3<&1- 1>/dev/null 2>/dev/null" >>$tmpfile
|
|
|
|
|
+ fi
|
|
|
fi
|
|
fi
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
@@ -507,9 +514,17 @@ for cmd in $cmds; do
|
|
|
# execute the generated script with GNU Bash
|
|
# execute the generated script with GNU Bash
|
|
|
if [ ".$user" != ".$s_user" ]; then
|
|
if [ ".$user" != ".$s_user" ]; then
|
|
|
# execute as different user
|
|
# execute as different user
|
|
|
|
|
+ if [ ".$verbose" = .1 ]; then
|
|
|
|
|
+ echo "openpkg:rc:NOTICE: $prefix:$s_name:%$cmd: executing as user $s_user"
|
|
|
|
|
+ fi
|
|
|
if [ ".$user" = ".@l_susr@" -a ".@l_susr@" = ".root" ]; then
|
|
if [ ".$user" = ".@l_susr@" -a ".@l_susr@" = ".root" ]; then
|
|
|
- su - $s_user -c "PATH=\"$PATH\"; $bash $tmpfile" >$outfile 2>$errfile
|
|
|
|
|
- rc=$?
|
|
|
|
|
|
|
+ if [ ".$debug" = .1 ]; then
|
|
|
|
|
+ su - $s_user -c "PATH=\"$PATH\"; $bash $tmpfile" >$outfile
|
|
|
|
|
+ rc=$?
|
|
|
|
|
+ else
|
|
|
|
|
+ su - $s_user -c "PATH=\"$PATH\"; $bash $tmpfile" >$outfile 2>$errfile
|
|
|
|
|
+ rc=$?
|
|
|
|
|
+ fi
|
|
|
elif [ ".@l_susr@" != ".root" ]; then
|
|
elif [ ".@l_susr@" != ".root" ]; then
|
|
|
# do not complain if we would not have any chance
|
|
# do not complain if we would not have any chance
|
|
|
# at all to switch the user because we are running
|
|
# at all to switch the user because we are running
|
|
@@ -523,8 +538,16 @@ for cmd in $cmds; do
|
|
|
fi
|
|
fi
|
|
|
else
|
|
else
|
|
|
# execute as current user
|
|
# execute as current user
|
|
|
- $bash $tmpfile >$outfile 2>$errfile
|
|
|
|
|
- rc=$?
|
|
|
|
|
|
|
+ if [ ".$verbose" = .1 ]; then
|
|
|
|
|
+ echo "openpkg:rc:NOTICE: $prefix:$s_name:%$cmd: executing as user $user"
|
|
|
|
|
+ fi
|
|
|
|
|
+ if [ ".$debug" = .1 ]; then
|
|
|
|
|
+ $bash $tmpfile >$outfile
|
|
|
|
|
+ rc=$?
|
|
|
|
|
+ else
|
|
|
|
|
+ $bash $tmpfile >$outfile 2>$errfile
|
|
|
|
|
+ rc=$?
|
|
|
|
|
+ fi
|
|
|
fi
|
|
fi
|
|
|
if [ $rc -ne 0 ]; then
|
|
if [ $rc -ne 0 ]; then
|
|
|
if [ ".$silent" = .0 ]; then
|
|
if [ ".$silent" = .0 ]; then
|
|
@@ -533,17 +556,33 @@ for cmd in $cmds; do
|
|
|
verbose_pos=0
|
|
verbose_pos=0
|
|
|
fi
|
|
fi
|
|
|
# give details of execution failure
|
|
# give details of execution failure
|
|
|
- ( echo "openpkg:rc:WARNING: $prefix:$s_name:%$cmd: failed with return code $rc" 1>&2
|
|
|
|
|
|
|
+ ( echo "openpkg:rc:WARNING: $prefix:$s_name:%$cmd: failed with return code $rc"
|
|
|
if [ ".`cat $outfile $errfile`" != . ]; then
|
|
if [ ".`cat $outfile $errfile`" != . ]; then
|
|
|
- echo "+----Log:--------------------------------------------------------------"
|
|
|
|
|
|
|
+ echo "openpkg:rc:NOTICE: output from stdout/stderr is following:"
|
|
|
|
|
+ echo "+----------------------------------------------------------------------"
|
|
|
cat $outfile $errfile | sed -e 's;^;| ;'
|
|
cat $outfile $errfile | sed -e 's;^;| ;'
|
|
|
echo "+----------------------------------------------------------------------"
|
|
echo "+----------------------------------------------------------------------"
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "openpkg:rc:NOTICE: no output occurred on stdout/stderr"
|
|
|
fi
|
|
fi
|
|
|
) 1>&2
|
|
) 1>&2
|
|
|
|
|
|
|
|
# enforce global return value
|
|
# enforce global return value
|
|
|
rv=1
|
|
rv=1
|
|
|
else
|
|
else
|
|
|
|
|
+ # give details of execution success in case verbose operation is requested
|
|
|
|
|
+ if [ ".$verbose" = .1 ]; then
|
|
|
|
|
+ ( echo "openpkg:rc:NOTICE: $prefix:$s_name:%$cmd: succeeded with return code $rc"
|
|
|
|
|
+ if [ ".`cat $outfile $errfile`" != . ]; then
|
|
|
|
|
+ echo "openpkg:rc:NOTICE: output from stdout/stderr is following:"
|
|
|
|
|
+ echo "+----------------------------------------------------------------------"
|
|
|
|
|
+ cat $outfile $errfile | sed -e 's;^;| ;'
|
|
|
|
|
+ echo "+----------------------------------------------------------------------"
|
|
|
|
|
+ else
|
|
|
|
|
+ echo "openpkg:rc:NOTICE: no output occurred on stdout/stderr"
|
|
|
|
|
+ fi
|
|
|
|
|
+ ) 1>&2
|
|
|
|
|
+ fi
|
|
|
if [ ".$s_output" = .yes ]; then
|
|
if [ ".$s_output" = .yes ]; then
|
|
|
# accumulate script output for later display
|
|
# accumulate script output for later display
|
|
|
cat $outfile >>$allfile
|
|
cat $outfile >>$allfile
|
|
@@ -580,17 +619,32 @@ for cmd in $cmds; do
|
|
|
|
|
|
|
|
# now replace temporary script with its output
|
|
# now replace temporary script with its output
|
|
|
# by executing it and capturing its output
|
|
# by executing it and capturing its output
|
|
|
- env -i \
|
|
|
|
|
- HOME="$HOME" \
|
|
|
|
|
- USER="$USER" \
|
|
|
|
|
- LOGNAME="$LOGNAME" \
|
|
|
|
|
- TERM="$TERM" \
|
|
|
|
|
- PATH="$PATH_ORIG" \
|
|
|
|
|
- MANPATH="$MANPATH" \
|
|
|
|
|
- INFOPATH="$INFOPATH" \
|
|
|
|
|
- LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
|
|
|
|
|
- $bash --norc --noprofile --posix \
|
|
|
|
|
- $tmpfile >$outfile 2>/dev/null
|
|
|
|
|
|
|
+ # (let stderr pass unfiltered in case of debug mode)
|
|
|
|
|
+ if [ ".$debug" = .1 ]; then
|
|
|
|
|
+ env -i \
|
|
|
|
|
+ HOME="$HOME" \
|
|
|
|
|
+ USER="$USER" \
|
|
|
|
|
+ LOGNAME="$LOGNAME" \
|
|
|
|
|
+ TERM="$TERM" \
|
|
|
|
|
+ PATH="$PATH_ORIG" \
|
|
|
|
|
+ MANPATH="$MANPATH" \
|
|
|
|
|
+ INFOPATH="$INFOPATH" \
|
|
|
|
|
+ LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
|
|
|
|
|
+ $bash --norc --noprofile --posix \
|
|
|
|
|
+ $tmpfile >$outfile
|
|
|
|
|
+ else
|
|
|
|
|
+ env -i \
|
|
|
|
|
+ HOME="$HOME" \
|
|
|
|
|
+ USER="$USER" \
|
|
|
|
|
+ LOGNAME="$LOGNAME" \
|
|
|
|
|
+ TERM="$TERM" \
|
|
|
|
|
+ PATH="$PATH_ORIG" \
|
|
|
|
|
+ MANPATH="$MANPATH" \
|
|
|
|
|
+ INFOPATH="$INFOPATH" \
|
|
|
|
|
+ LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
|
|
|
|
|
+ $bash --norc --noprofile --posix \
|
|
|
|
|
+ $tmpfile >$outfile 2>/dev/null
|
|
|
|
|
+ fi
|
|
|
cp $outfile $tmpfile
|
|
cp $outfile $tmpfile
|
|
|
|
|
|
|
|
# for --eval we cannot just print the resulting script because
|
|
# for --eval we cannot just print the resulting script because
|
|
@@ -622,10 +676,13 @@ done
|
|
|
|
|
|
|
|
# cleanup temporary files except the result script in
|
|
# cleanup temporary files except the result script in
|
|
|
# case of --eval (which is then removed by the caller).
|
|
# case of --eval (which is then removed by the caller).
|
|
|
-rm -f $outfile $errfile $allfile >/dev/null 2>&1 || true
|
|
|
|
|
-if [ ".$eval" = .0 ]; then
|
|
|
|
|
- rm -f $tmpfile >/dev/null 2>&1 || true
|
|
|
|
|
- rm -rf $tmpdir >/dev/null 2>&1 || true
|
|
|
|
|
|
|
+# keep those files for debugging purposes if requested.
|
|
|
|
|
+if [ ".$keep" = .0 ]; then
|
|
|
|
|
+ rm -f $outfile $errfile $allfile >/dev/null 2>&1 || true
|
|
|
|
|
+ if [ ".$eval" = .0 ]; then
|
|
|
|
|
+ rm -f $tmpfile >/dev/null 2>&1 || true
|
|
|
|
|
+ rm -rf $tmpdir >/dev/null 2>&1 || true
|
|
|
|
|
+ fi
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
# now clean the exit trap and exit with the global return value
|
|
# now clean the exit trap and exit with the global return value
|