You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.5 KiB

  1. #!/bin/bash
  2. # make sure this was run as root
  3. if [ $UID -ne 0 ] ; then
  4. echo "Need to be root; trying sudo"
  5. exec sudo $0 "$@"
  6. fi
  7. # enter the chroot and run the command (if supplied) or a shell
  8. . config || exit 0
  9. FAILED=0
  10. run() {
  11. echo "+" "$1"
  12. chroot ${FS} env -i \
  13. HOME=/root \
  14. PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
  15. TERM=$TERM \
  16. IN_CHROOT=1 \
  17. bash -c "$1"
  18. RET=$?
  19. if [ $RET -ne 0 ] && [ "$1" != "exec bash" ] ; then
  20. printf "%s\n" "----------- WARNING: failed with exit code $RET"
  21. FAILED=$RET
  22. sleep 5
  23. fi
  24. }
  25. set -e
  26. mount -t proc none ${FS}/proc
  27. mount -t sysfs none ${FS}/sys
  28. mount -t devpts none ${FS}/dev/pts
  29. run "echo 'nameserver 8.8.8.8' > /etc/resolv.conf"
  30. run "dbus-uuidgen > /var/lib/dbus/machine-id"
  31. run "dpkg-divert --local --rename --add /sbin/initctl"
  32. run "ln -s /bin/true /sbin/initctl"
  33. run "dpkg-divert --local --rename --add /usr/sbin/update-grub"
  34. run "ln -s /bin/true /usr/sbin/update-grub"
  35. set +e
  36. if [ -z "$1" ] ; then
  37. run "exec bash"
  38. else
  39. run "$1"
  40. fi
  41. run "apt-get clean"
  42. run "rm /sbin/initctl"
  43. run "dpkg-divert --rename --remove /sbin/initctl"
  44. run "rm /usr/sbin/update-grub"
  45. run "dpkg-divert --rename --remove /usr/sbin/update-grub"
  46. run "rm /var/lib/dbus/machine-id"
  47. run "> /etc/resolv.conf"
  48. run "rm -rf /tmp/* /tmp/.??* /root/.bash_history"
  49. umount ${FS}/dev/pts
  50. umount ${FS}/sys/kernel/security || true
  51. umount ${FS}/sys
  52. umount ${FS}/proc
  53. echo "cleaned up"
  54. if [ $FAILED -ne 0 ] ; then
  55. exit $FAILED
  56. fi
  57. exit 0