#!/bin/sh -e

# The cereal scripts were written by
# Jameson Graef Rollins <jrollins@finestructure.net>
# and
# Daniel Kahn Gillmor <dkg@fifthhorseman.net>.
#
# They are Copyright 2007, and are all released under the GPL, version 3
# or later.

exec 2>./socket 1>&2

SHAREDIR="/usr/share/cereal"
export SHAREDIR
. "$SHAREDIR/common"

# ensure that the socket is available
( [ -p ./socket ] || (rm -f ./socket; mkfifo ./socket) ) || failure "can not create socket."

# find screenrc:    
if [ -e "./screenrc" ] ; then
    SCREENRC="./screenrc"
elif [ -e "$ETC/screenrc" ] ; then
    SCREENRC="$ETC/screenrc"
else
    failure "cereal screenrc file not found."
fi
export SCREENRC

# call the mainrun function (defined in $SHAREDIR/common)
# that actually runs screen
exec chpst -e ./env sh -c ". $SHAREDIR/common && mainrun"
