#!/bin/bash

SID=`ps --no-heading -o sess --pid $$`

if [ $SID -ne $$ ]; then
    # Not currently a session leader? Run a copy of ourself in a new
    # session, with copies of stdin/stdout/stderr.
    setsid $0 $@ < /dev/stdin 1> /dev/stdout 2> /dev/stderr &
    FBASH=$!
    trap "kill $FBASH; exit" SIGINT SIGTERM
    wait $FBASH
else
    # Just evaluate the commands (from stdin)
    source /dev/stdin
fi
