Approximate copy of chroot code from py3minepi