#!/bin/csh -f
set basedir=`dirname $0`
cd $basedir
# determine which Ex Libris application
source util_sp_set_app
if (! -e $sp_conf) then
    echo "initial setup - running configuration utility"
    csh -f $util_proc/util_sp_01_01
else
    source $util_proc/util_sp_get_conf
endif
# set ftp_servers=(ftp.exlibris-usa.com ftp.exlibrisgroup.com ftp.exl.de il-ftp01)
# set ftp_desc=("USA/Asia Pacific" "HQ/Middle east" "Europe" "internal HQ")
set ftp_servers=(downloads-eu.hosted.exlibrisgroup.com downloads-na.hosted.exlibrisgroup.com downloads-ap.hosted.exlibrisgroup.com downloads-ca.hosted.exlibrisgroup.com downloads-cn.hosted.exlibrisgroup.com) 
set ftp_desc=("Europe" "USA/Asia Pacific" "Asia" "Canada" "China") 




source $sp_conf
set ftp_pass=`cat $sp_passfile`
clear

echo "SP FTP settings"
echo "--------------------------"
echo "Enter new values or press <Enter> to keep existing"
echo ""
echo "Select FTP server number for SP download:"
echo ""
set ans="X"
while ("$ans" == "X")
set i=0
foreach s ($ftp_servers)
    @ i++
    printf "%d) %-20.20s%s\n" $i "$ftp_desc[$i]" "$ftp_servers[$i]"
end
echo "<Enter> to keep current ($ftp_server)"
set ans="$<"
if ("$ans" != "") then
    echo $ans | grep -v '[0-4]' >& /dev/null
    if ($status) then
        set ftp_server=$ftp_servers[$ans]
        set touched
    else
        echo "illegal answer"
        set ans="X"
    endif
endif
end
echo "FTP user for SP download [$ftp_user]:"
set ans="$<"
if ("$ans" != "") then
    set ftp_user=$ans
    set touched
endif
# echo "FTP special options [$ftp_opts]:"
# echo "*** for firewall connection problems try 'passive'"
# echo "For details check the utility documentation"
# set ans="$<"
# if ("$ans" != "") then
#     set ftp_opts=$ans
#     set touched
# endif




echo ""
echo "Configuration summary:"
echo "----------------------"
echo "FTP server:                $ftp_server"
echo "FTP user:                  $ftp_user"
echo "FTP options:               $ftp_opts"

#echo "Press <Enter> to continue"
#set ans="$<"
if ($?touched) then
    echo "Configuration has changed, do you want to save it?[y/n]"
    set ans="$<"
    set ans=`echo $ans | tr '[A-Z]' '[a-z]'`
    while ( "$ans" != "y" && "$ans" != "n" )
        echo "Do you want to save [y/n]?"
        set ans="$<"
    end
    if ("$ans" == "y" || $ans == "Y") then
      source $util_proc/util_sp_write_config
      unset touched
    else
        echo "All changes will be discarded"
    endif
endif
echo ""
# echo "If you want to insert new FTP password please type it now"
# echo "Or press ENTER to keep current password"
#stty -echo 
# set ans="$<"
#stty echo
# if ("$ans" != "") then
#     clear
#     set ftp_pass=$ans
#     echo "Do you want to save the new password?[Y/N]"
#     set ans="$<"
#     if ("$ans" == "Y" || "$ans" == "y") then
#         echo $ftp_pass > $sp_passfile && echo "Password saved"
#     else
#         echo "Password discarded"
#     endif
# endif


exit:
echo "Press <Enter> to continue"
set ans="$<"
