#!/bin/bash
rm -rf vm/ vm.squashfs
mkdir -p vm/proc/
mount /proc -o bind vm/proc
multistrap -f ex/vm.conf
ln -s vm/usr/bin/mawk vm/bin/awk
cat > vm/.profile <<EOF
mount -t 9p -o trans=virtio virtfs /mnt
mount -t ramfs ramfs /tmp
mount -t proc proc /proc
mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
echo ':jar:M::PK\x03\x04::/usr/bin/jexec:' > /proc/sys/fs/binfmt_misc/register
[ -e /dev/ttyS1 ] && stty -F /dev/ttyS1 raw -echo
cd /mnt
export PS1="# "
EOF
cat >> vm/etc/sudoers <<EOF
Defaults>nobody closefrom=5
Defaults>nobody !env_check
Defaults>nobody env_keep="ONLINE_JUDGE PATH HOME"
EOF
install gruntmaster-exec gruntmaster-compile vm/usr/bin/
umount vm/proc
mksquashfs vm vm.squashfs -comp lzo
