#!/bin/sh

set -e

# Read command-line parameters:
CHROOTDIR=/var/lib/domjudge/javachroot
# To prevent (libc6) upgrade questions:
export DEBIAN_FRONTEND=noninteractive

if [ `id -u` != 0 ]; then
    echo "Warning: you probably need to run this program as root."
fi

# Prevent perl locale warnings in the chroot:
export LC_ALL=C

chroot "$CHROOTDIR" /bin/sh -c "apt-get update && apt-get upgrade"
chroot "$CHROOTDIR" /bin/sh -c "apt-get clean"
# Remove unnecessary setuid bits
chroot "$CHROOTDIR" /bin/sh -c "chmod a-s /usr/bin/wall /usr/bin/newgrp \
	/usr/bin/chage /usr/bin/chfn /usr/bin/chsh /usr/bin/expiry \
	/usr/bin/gpasswd /usr/bin/passwd /usr/lib/pt_chown \
	/bin/su /bin/mount /bin/umount /sbin/unix_chkpwd"

exit 0
