#! /bin/bash -ue
# Last edited on 2025-05-04 22:46:06 by stolfi

# Sets link "{dir}/{link}" to point to "${srcdir}" 

dir="$1"; shift    # Directory where to place the link.
link="$1"; shift   # Name of link.
srcdir="$1"; shift # Directory {BANK}/{LANG}/{BOOK} of source, rel to {dir}.

if [[ -h ${dir}/${link} ]]; then
  # Remove old link:
  rm -f ${dir}/${link}
elif [[ -s ${dir}/${link} ]]; then
  echo "** ${dir}/${link} exists and is not a symbolic link" 1>&2 ; exit 1
fi

( cd ${dir} && ln -s ${srcdir} ${link} )

srcfile="${srcdir}/main.src"
if [[ ! ( -s ${dir}/${srcfile} ) ]]; then
  echo "** file  ${dir}/${srcfile} not found" 1>&2 ; exit 1
fi
  
