@ -110,7 +110,11 @@ fi
rcconf="`echo $rcdir | sed -e 's;/rc.d$;/rc.conf;'`"
rcfunc="`echo $rcdir | sed -e 's;/rc.d$;/rc.func;'`"
# path to GNU Bash
bash="@l_prefix@/lib/openpkg/bash"
# extend run-time environment with local OpenPKG tools (shtool, rpmtool, etc)
PATH_ORIG="$PATH"
PATH="@l_prefix@/bin:$PATH"
PATH="@l_prefix@/sbin:$PATH"
PATH="@l_prefix@/lib/openpkg:$PATH"
@ -128,8 +132,9 @@ if [ $i -eq 10 ]; then
exit 1
fi
declare -r tmpdir
TMPDIR="$tmpdir"; export TMPDIR
TEMPDIR="$tmpdir"; export TEMPDIR
TMPDIR_ORIG="$TMPDIR"
TMPDIR="$tmpdir"
export TMPDIR
trap "trap - EXIT INT ABRT QUIT TERM; rm -rf $tmpdir >/dev/null 2>&1 || true" EXIT INT ABRT QUIT TERM
# determine reasonable temporary files
@ -411,6 +416,11 @@ for cmd in $cmds; do
# generate: inclusion of the application of override variables
echo ". $rcconf" >>$tmpfile
# for --eval redirect stderr and stdout (but remember stdout)
if [ ".$eval" = .1 ]; then
echo "exec 3<&1- 1>/dev/null 2>/dev/null" >>$tmpfile
fi
fi
# iterate over all packages (in priority order!) where the command
@ -447,12 +457,24 @@ for cmd in $cmds; do
fi
# now operate on the particular script
if [ ".$print" = .1 -o ".$eval" = .1 ]; then
# special case: under --print and --eval we just add the
# %common and command scripts to the generated output script
# and do not execute anything at this point.
if [ ".$print" = .1 ]; then
# special case: under --print we just add the %common and
# command scripts to the generated output script and do
# not execute anything at this point.
sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%common/d" -e '/^%.*/,$d'
sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d'
elif [ ".$eval" = .1 ]; then
# special case: under --eval we just add the %common and
# command scripts to the generated output script and do
# not execute anything at this point. Additionally, we
# emulate a real sub-shell environment.
sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%common/d" -e '/^%.*/,$d'
echo "while [ 1 ]; do" >>$tmpfile
sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d' \
-e 's/^exit[^;]*/break 99/' -e 's/\([^a-zA-Z0-9_]\)exit[^;]*/\1break 99/g' \
-e 's/^return[^;]*/break 99/' -e 's/\([^a-zA-Z0-9_]\)return[^;]*/\1break 99/g'
echo "break" >>$tmpfile
echo "done" >>$tmpfile
else
# the regular case of executing the command script directly
@ -487,14 +509,13 @@ for cmd in $cmds; do
sed <$rcdir/rc.$s_name >>$tmpfile -e "1,/^%$cmd/d" -e '/^%.*/,$d'
# execute the generated script with GNU Bash
sh="@l_prefix@/lib/openpkg/bash"
if [ ".$user" != ".$s_user" ]; then
# execute as different user
su - $s_user -c "PATH=\"$PATH\"; $sh $tmpfile" >$outfile 2>$errfile
su - $s_user -c "PATH=\"$PATH\"; $ba sh $tmpfile" >$outfile 2>$errfile
rc=$?
else
# execute as current user
$sh $tmpfile >$outfile 2>$errfile
$ba sh $tmpfile >$outfile 2>$errfile
rc=$?
fi
if [ $rc -ne 0 ]; then
@ -525,16 +546,58 @@ for cmd in $cmds; do
# post-processing for each command
if [ ".$print" = .1 ]; then
# for --print just print the resulting script
# for --print just print the resulting script to stdout
cat $tmpfile
elif [ ".$eval" = .1 ]; then
# finish generation of temporary script by restoring stdout
# and printing the exported environment variables into a format
# suitable for evaluation by the callers shell.
echo "exec 1<&3-" >>$tmpfile
echo "unset PWD SHLVL" >>$tmpfile
echo "env |\\" >>$tmpfile
echo "egrep '^[A-Z]*=.' |\\" >>$tmpfile
echo "sed -e 's/\\\\/\\\\\\\\/g' -e 's/\"/\\\\\"/g' \\" >>$tmpfile
case $SHELL in
csh|*/csh|tcsh|*/tcsh )
echo "-e 's/^\\([^=]*\\)=\\(.*\\)\$/setenv \\1 \"\\2\"/'" >>$tmpfile
;;
* )
echo "-e 's/^\\([^=]*\\)=\\(.*\\)\$/\\1=\"\\2\"; export \\1/'" >>$tmpfile
;;
esac
# prepare temporary files
rm -f $outfile $errfile
touch $outfile $errfile
# now replace temporary script with 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" \
TMPDIR="$TMPDIR_ORIG" \
$bash --norc --noprofile --posix \
$tmpfile >$outfile 2>/dev/null
cp $outfile $tmpfile
# for --eval we cannot just print the resulting script because
# not all Bourne-Shell implementations like to "eval" large
# multi-line outputs. Hence we output a little one-liner which
# "sources" the script instead and cleans up. To make sure the
# "rm -rf $tmpdir" is not run by the automatic cleanup code,
# remove the EXIT trap.
echo ". $tmpfile; rm -rf $tmpdir 2>/dev/null || true"
# "sources" the script instead and cleans up.
case $SHELL in
csh|*/csh|tcsh|*/tcsh )
echo "source $tmpfile; rm -rf $tmpdir 2>/dev/null || true"
;;
* )
echo ". $tmpfile; rm -rf $tmpdir 2>/dev/null || true"
;;
esac
else
# for the execution situation just make sure we
# terminate the verbose message output.