autoport-chroot: allow to specify a chroot command instead of running default shell from command line

This commit is contained in:
Silvan Calarco 2013-05-04 15:41:57 +02:00
parent d7f48ae5af
commit 1471140bd4

View File

@ -6,6 +6,8 @@
. /etc/sysconfig/autoport . /etc/sysconfig/autoport
CHROOT_TARGET=$1 CHROOT_TARGET=$1
shift
CHROOT_COMMAND=$@
function usage() { function usage() {
echo "\ echo "\
@ -16,7 +18,7 @@ $0
"$"Enters autoport chroot environment."" "$"Enters autoport chroot environment.""
"$"Usage"": "$"Usage"":
$me chroot_target $me chroot_target [command [args..]]
" "
} }
@ -35,11 +37,15 @@ for i in `seq 0 ${#AUTOPORT_ARCH[*]}`; do
else else
CMD_PREFIX= CMD_PREFIX=
fi fi
if [ "$CHROOT_COMMAND" ]; then
$CMD_PREFIX /usr/sbin/chroot /var/autoport/${AUTOPORT_CHROOT[$i]} su -l $SU_APPEND ${AUTOPORT_CHROOT_USER[$i]} -c "${CHROOT_COMMAND}"
else
echo "Entering ${AUTOPORT_CHROOT[$i]} autoport chroot environment" echo "Entering ${AUTOPORT_CHROOT[$i]} autoport chroot environment"
[ -e /var/autoport/${AUTOPORT_CHROOT[$i]}/etc/profile.d/autoport.sh ] || { [ -e /var/autoport/${AUTOPORT_CHROOT[$i]}/etc/profile.d/autoport.sh ] || {
echo "PS1='[\u@${AUTOPORT_CHROOT[$i]} \W]\$ '" > /var/autoport/${AUTOPORT_CHROOT[$i]}/etc/profile.d/autoport.sh echo "PS1='[\u@${AUTOPORT_CHROOT[$i]} \W]\$ '" > /var/autoport/${AUTOPORT_CHROOT[$i]}/etc/profile.d/autoport.sh
} }
$CMD_PREFIX /usr/sbin/chroot /var/autoport/${AUTOPORT_CHROOT[$i]} su -l ${AUTOPORT_CHROOT_USER[$i]} $CMD_PREFIX /usr/sbin/chroot /var/autoport/${AUTOPORT_CHROOT[$i]} su -l $SU_APPEND ${AUTOPORT_CHROOT_USER[$i]}
fi
exit 0 exit 0
done done