#! /bin/sh

test -z "${BIN_DIR}" && BIN_DIR=website/cgi-bin

set -ue
## set -x

BASENAME=$(basename $0 .pl)
TMP_TEST_DB=$(echo tmpNonexistent${BASENAME}$$ | sed 's/[^-0-9a-zA-Z]//g').db

DB_DIR=db
TMP_DB_FILE=${DB_DIR}/${TMP_TEST_DB}

touch ${TMP_DB_FILE}
chmod 000 ${TMP_DB_FILE}

export REQUEST_URI="/~saulius/restful/website/${TMP_TEST_DB}/bibliography/1"
export HTTP_HOST=${TMP_TEST_DB}.domain.net
export REQUEST_METHOD=POST
export REMOTE_USER=tester

TMP_DB_BASE=$(basename ${TMP_DB_FILE})

${BIN_DIR}/modify.pl 2>&1 | sed "s/${TMP_DB_BASE}/tmpNonexistent/"

chmod 640 ${TMP_DB_FILE}
rm -f ${TMP_DB_FILE}
