summaryrefslogtreecommitdiff
path: root/asp-cp
blob: 86318e9b9ab49178040d3095aa38b4cdb1ba5c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh
DATAPATH="$1"
APPPATH=
# KEYPATH=
KEYNAME=asperaweb_id_dsa.openssh

case "`uname -s`" in
  Darwin )
    sysdir='/Applications/Aspera Connect.app/Contents/Resources'
    sysdir2=/bin
    userdir=$HOME$sysdir
    ;;
  CYGWIN_NT* )
    sysdir='/cygdrive/c/Program Files/Aspera/Aspera Connect/bin'
    sysdir2='/cygdrive/c/Program Files (x86)/Aspera/Aspera Connect/bin'
    userdir="`cygpath -H`/$USER/AppData/Local/Programs/Aspera/Aspera Connect/bin"
    ;;
  * )
    sysdir=/opt/aspera/bin
    sysdir2=/bin
    userdir=$HOME/.aspera/connect/bin
    ;;
esac
for d in "$sysdir" "$sysdir2" "$userdir"
do
  if "$d/ascp" --version 2>&1 | grep '^Aspera' >/dev/null
  then
    APPPATH=$d
    break
  fi
done
if [ -z "$APPPATH" ]  &&  ascp --version 2>&1 | grep '^Aspera' >/dev/null
then
  APPPATH=`type -path ascp`
  APPPATH=`dirname "$APPPATH"`
fi
if [ -z "$APPPATH" ]
then
  cat >&2 <<EOF

Unable to find an Aspera ascp executable in any of the following locations:
$sysdir
$sysdir2
$userdir
$PATH

If you have an installation in some other location, please add the path to
that executable to your PATH environment variable and try again.

EOF
  exit 2
fi

for d in "$APPPATH" "$sysdir" "$sysdir2" "$userdir"
do
  if [ -f "$d/../etc/$KEYNAME" ]
  then
    KEYPATH=$d/../etc
    break
  elif [ -f "$d/$KEYNAME" ]
  then
    KEYPATH=$d
    break
  fi
done
if [ -z "$KEYPATH" ]
then
  cat >&2 <<EOF

Unable to find $KEYNAME in any of the following locations:
$APPPATH/../etc
$APPPATH
$sysdir/../etc
$sysdir
$sysdir2/../etc
$sysdir2
$userdir/../etc
$userdir

If you have this file in some other location, please set the KEYPATH
environment variable accordingly and try again.

EOF
  exit 3
fi

failed=""
if [ "$#" -gt 1 ]
then
  fl="$2"
  if [ ! -f "$fl" ]
  then
    "$APPPATH/ascp" -T -q -k 1 -l 500m -i "$KEYPATH/$KEYNAME" \
    "anonftp@ftp.ncbi.nlm.nih.gov:/$DATAPATH/$fl" "."
  fi
  if [ ! -f "$fl" ]
  then
    failed="$failed\n$fl"
  fi
else
  while read fl
  do
    if [ ! -f "$fl" ]
    then
      echo "$fl"
      "$APPPATH/ascp" -T -q -k 1 -l 500m -i "$KEYPATH/$KEYNAME" \
      "anonftp@ftp.ncbi.nlm.nih.gov:/$DATAPATH/$fl" "."
    fi
    if [ ! -f "$fl" ]
    then
      failed="$failed\n$fl"
    fi
  done
fi
if [ -n "$failed" ]
then
  echo -e "\nFAILED TO DOWNLOAD:\n$failed\n" >&2
  exit 1
fi