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.
 
 
 

60 lines
1.4 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. run() {
  10. echo "+" "$1"
  11. chroot ${FS} env -i \
  12. HOME=/root \
  13. PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
  14. TERM=$TERM \
  15. IN_CHROOT=1 \
  16. bash -c "$1"
  17. RET=$?
  18. if [ $RET -ne 0 ] && [ "$1" != "exec bash" ] ; then
  19. printf "%s\n" "----------- WARNING: failed with exit code $RET"
  20. sleep 5
  21. fi
  22. }
  23. set -e
  24. mount -t proc none ${FS}/proc
  25. mount -t sysfs none ${FS}/sys
  26. mount -t devpts none ${FS}/dev/pts
  27. run "echo 'nameserver 8.8.8.8' > /etc/resolv.conf"
  28. run "dbus-uuidgen > /var/lib/dbus/machine-id"
  29. run "dpkg-divert --local --rename --add /sbin/initctl"
  30. run "ln -s /bin/true /sbin/initctl"
  31. run "dpkg-divert --local --rename --add /usr/sbin/update-grub"
  32. run "ln -s /bin/true /usr/sbin/update-grub"
  33. set +e
  34. if [ -z "$1" ] ; then
  35. run "exec bash"
  36. else
  37. run "$1"
  38. fi
  39. run "apt-get clean"
  40. run "rm /sbin/initctl"
  41. run "dpkg-divert --rename --remove /sbin/initctl"
  42. run "rm /usr/sbin/update-grub"
  43. run "dpkg-divert --rename --remove /usr/sbin/update-grub"
  44. run "rm /var/lib/dbus/machine-id"
  45. run "> /etc/resolv.conf"
  46. run "rm -rf /tmp/* /tmp/.??* /root/.bash_history"
  47. umount ${FS}/dev/pts
  48. umount ${FS}/sys/kernel/security || true
  49. umount ${FS}/sys
  50. umount ${FS}/proc
  51. echo "cleaned up"