#! /bin/sh
# 
# Name: lock_cdbs
#
# Description: Inserts a database lock row for a CDBS deliveryNumber.4
#              If the lock cannot be obtained, a listing of the existing
#              lock entries are shown.
#
# Called by:   cdbs_sql_gen.sh
#
# Usage: lock_cdbs deliveryNumber
#
# Returns: 0 = lock acquired (DB entry inserted)
#          1 = failed to acquire lock
#
#--------------------------------------------------------------------------
export CDBS_DB CDBS_SERVER
if test $# -ne 1
then
  echo "usage: lock_cdbs <deliveryNumber>"
  exit 1
fi
if test `lock_cdbs_sql.s $1 | fgrep -i "acquired" | wc -l` -ne 0
then
  echo "lock acquired"
  exit 0
else
  echo "lock denied, existing locks are:"
  # show the existing DB lock entries
  lock_cdbs_sql_a.s
  exit 1
fi
