#! /bin/bash
set -e

if test "$#" = 0 -o "$1" = "-h"
then me=$0
     echo "usage: ${me##*/} [-yCR{,CR}*] DIR" >&2
     exit 1
fi

case "$1" in
  -y*) a="$1"
       why="--request ${a#-y}"
       shift;
       ;;
    *) why=""
       ;;
esac

if ! test -d $1 ; then mkdir $1 ; fi

top=${SB_TOP%/}
here=$(cd $1 ; pwd)
here=${here#$top}
parent=${here%/*}
parent=${parent:-/}

set -x
sb --dir $parent --lock
sb --dir --create ${here##*/} --remarks "mkdir $here" $why
sb --dir $parent --checkin --remarks "mkdir $here" $why
