2012-05-10 10:30:38 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# autoport-chroot
|
2013-04-22 12:28:47 +02:00
|
|
|
# (c) 2012-2013 by Silvan Calarco <silvan.calarco@mambasoft.it>
|
2012-05-10 10:30:38 +02:00
|
|
|
#
|
|
|
|
. /etc/sysconfig/autoport
|
|
|
|
|
|
|
|
CHROOT_TARGET=$1
|
2013-05-04 15:41:57 +02:00
|
|
|
shift
|
|
|
|
CHROOT_COMMAND=$@
|
2012-05-10 10:30:38 +02:00
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "\
|
|
|
|
$0
|
|
|
|
"$"Copyright (C) 2012 Silvan Calarco <silvan.calarco@mambasoft.it>""
|
|
|
|
"$"Released under the terms of the GNU GPL v3 license"
|
|
|
|
echo "
|
|
|
|
"$"Enters autoport chroot environment.""
|
|
|
|
|
|
|
|
"$"Usage"":
|
2013-05-04 15:41:57 +02:00
|
|
|
$me chroot_target [command [args..]]
|
2012-05-10 10:30:38 +02:00
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
[ "$CHROOT_TARGET" ] || {
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
[ "`uname -m`" = "x86_64" ] && HOST_IS_X86_64=1
|
|
|
|
|
|
|
|
for i in `seq 0 ${#AUTOPORT_ARCH[*]}`; do
|
|
|
|
[ "${AUTOPORT_CHROOT[$i]}" = "$CHROOT_TARGET" ] || continue
|
|
|
|
|
|
|
|
if [ "$HOST_IS_X86_64" -a "${AUTOPORT_ARCH[$i]}" != "x86_64" ]; then
|
|
|
|
CMD_PREFIX=linux32
|
|
|
|
else
|
|
|
|
CMD_PREFIX=
|
|
|
|
fi
|
2013-05-04 15:41:57 +02:00
|
|
|
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"
|
2014-04-25 12:12:07 +02:00
|
|
|
hostname=`hostname`
|
|
|
|
grep $hostname /var/autoport/${AUTOPORT_CHROOT[$i]}/etc/hosts >/dev/null || {
|
|
|
|
sed -i "s|\(^127.0.0.1[[:space:]]*\)|\1$hostname |" /var/autoport/${AUTOPORT_CHROOT[$i]}/etc/hosts
|
|
|
|
}
|
2013-05-04 15:41:57 +02:00
|
|
|
[ -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
|
|
|
|
}
|
2014-04-25 12:12:07 +02:00
|
|
|
$CMD_PREFIX /usr/sbin/chroot /var/autoport/${AUTOPORT_CHROOT[$i]} su -l $SU_APPEND ${AUTOPORT_CHROOT_USER[$i]}
|
2013-05-04 15:41:57 +02:00
|
|
|
fi
|
2012-05-10 10:30:38 +02:00
|
|
|
exit 0
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "$CHROOT_TARGET: undefined chroot target"
|
|
|
|
exit 1
|