#!/bin/ksh
#
# get_userlist keyfile
#
# default:
#    get_userlist userlist
#
# other options
#    get_userlist disks.txt
#    get_userlist userdisk.txt
#    get_userlist misc.txt
#
# The remote directory
#        /fmri2/fmri/ref_functions/mojoe_users
# will be searched for the specified keyfile name.
#
# A specific file will be searched for in the generic subdirectory 
# within the remote directory.
#
# For example,
#    get_userlist userlist
# looks for generic/userlist
#
#    
. ./settings.ksh
keyfile=${1:-"userlist"}
mojoe_dir=$MOJOE_DIR
if (test ${#mojoe_dir} -lt 1)
    then
    mojoe_dir=$HOME/mojoe
fi
details_dir=$MOJOE_DETAILS
if (test ${#details_dir} -lt 1)
    then
    details_dir=generic
fi
#
fname=$details_dir/$keyfile
listdir=$ref_dir/mojoe_users
listfile=$listdir/$fname
reply=`ssh -n -l $sshuser $sshserver ls -1 $listfile 2>/dev/null`
ftp_action=1
if (test ${#reply} -lt 1) then
    echo ... network $listfile list not available
    if (test -f $mojoe_dir/user_details/$keyfile) then
        echo ... using local copy of $keyfile
    else
        echo ... Error! Error! Error!
        echo ... MoJoe cannot run without $keyfile!
        echo ... Cannot find a remote or local copy!
    fi
    ftp_action=0
fi
if (test ftp_action -eq 1) then
    { echo "open $ftpserver
    user $ftpuser $ftppass
    hash
    binary
    get $listfile $mojoe_dir/user_details/$keyfile
    close"
    }|ftp -i -n -v 2>&1 | tee $mojoe_dir/user_details/"$keyfile"_ftp.log
fi
