#!/bin/sh
#
# sam-t-configure perl5-path
#
# Script to set the path to the perl executable in the SAM/Target99 scripts.
# Must be executed in the directory containing the scripts.
#
#
set -e  
PERL_SCRIPTS="target99 target2k build-weighted-model wu-blast-prefilter ncbi-blast-prefilter pick-key-residues select-by-key-residues select-by-gapless-regions w0.5 w0.7 w1.0"

if [ $# != 1 ] ; then
    echo "wrong # args: $0 perl5-path" >&2
    exit 1
fi
PERL=$1
if [ ! -r ${PERL} ] ; then
    echo "Error: specified perl5 interpreter does not exist: ${PERL}"
    exit 1
fi

tmps="sam-t-script.tmp"
for ps in ${PERL_SCRIPTS} ; do
    if [ ! -r $ps ] ; then
        echo "Error: perl script \"$ps\" not found in current directory." >&2
        echo "You must cd to the directory containing the Sam-target scripts." >&2
        exit 1
    fi
    sed -e "1s%^#!.*\$%#!${PERL} -w%" $ps >$tmps
    mv -f $tmps $ps
    chmod a=rx $ps
done
