nilmbuntu/enter.sh
2013-08-18 21:29:01 -04:00

66 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# make sure this was run as root
if [ $UID -ne 0 ] ; then
echo "Need to be root; trying sudo"
exec sudo env BUILD_CONFIG=$BUILD_CONFIG $0 "$@"
fi
# enter the chroot and run the command (if supplied) or a shell
. config || exit 0
FAILED=0
run() {
echo "+" "$1"
chroot ${FS} env -i \
HOME=/root \
PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
TERM=$TERM \
IN_CHROOT=1 \
bash -c "$1"
RET=$?
if [ $RET -ne 0 ] && [ "$1" != "exec bash" ] ; then
printf "%s\n" "----------- WARNING: failed with exit code $RET"
FAILED=$RET
sleep 5
fi
}
set -e
mount -t proc none ${FS}/proc
mount -t sysfs none ${FS}/sys
mount -t devpts none ${FS}/dev/pts
run "echo 'nameserver 8.8.8.8' > /etc/resolv.conf"
run "dbus-uuidgen > /var/lib/dbus/machine-id"
run "dpkg-divert --local --rename --add /sbin/initctl"
run "ln -s /bin/true /sbin/initctl"
run "dpkg-divert --local --rename --add /usr/sbin/update-grub"
run "ln -s /bin/true /usr/sbin/update-grub"
set +e
if [ -z "$1" ] ; then
run "exec bash"
else
run "$1"
fi
run "apt-get clean"
run "rm /sbin/initctl"
run "dpkg-divert --rename --remove /sbin/initctl"
run "rm /usr/sbin/update-grub"
run "dpkg-divert --rename --remove /usr/sbin/update-grub"
run "rm /var/lib/dbus/machine-id"
run "> /etc/resolv.conf"
run "rm -rf /tmp/* /tmp/.??* /root/.bash_history"
umount ${FS}/dev/pts
umount ${FS}/sys/kernel/security || true
umount ${FS}/sys
umount ${FS}/proc
echo "cleaned up"
if [ $FAILED -ne 0 ] ; then
exit $FAILED
fi
exit 0