#!/bin/sh slot=$1 release=$2 ports=$3 #Audit slot and release names case $slot in *[^a-zA-Z0-9]* ) echo "Non-alphanumeric slot $slot"; exit 1 esac case $release in *[^a-zA-Z0-9/-]* ) echo "Non-alphanumeric release $release"; exit 1 esac case $ports in *[^a-zA-Z0-9/-]* ) echo "Non-alphanumeric ports $ports"; exit 1 esac if [ -z "$slot" -o -z "$release" ]; then echo "Zero-length slot or release" exit 1 fi if [ -d /scratch/$slot ]; then echo "Pre-existing file system for this slot!" /pkgscripts/reapbuildjail $slot fi cleanup() { rm -f /scratch/$slot.lock /pkgscripts/reapbuildjail $slot exit 1 } set -e trap cleanup EXIT #TODO: localhost networking set -o noclobber echo > /scratch/$slot.lock set +o noclobber cat << EOF > /scratch/$slot.conf $slot { path="/scratch/$slot"; host.hostname="$slot.`hostname`"; persist="true"; mount.devfs="true"; mount.fstab="/scratch/$slot.fstab"; } EOF # TODO: Setting nosuid seems to break "below" echo "/scratch/$release /scratch/$slot unionfs below,noatime 0 0" > /scratch/$slot.fstab if [ -n "$ports" ]; then mkdir -p /scratch/$slot/$ports echo "$ports /scratch/$slot/$ports nullfs ro 0 0" >> /scratch/$slot.fstab fi mkdir -p /scratch/$slot jail -f /scratch/$slot.conf -c $slot ls /scratch/$slot/dev > /dev/null # Hack around unionfs bugs if [ -n "$ports" ]; then ls /scratch/$slot/$ports > /dev/null # And once more fi trap true EXIT rm /scratch/$slot.lock