source: TI12-security/trunk/esg_wget_script/esg-download.sh @ 7250

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/esg_wget_script/esg-download.sh@7250
Revision 7250, 3.6 KB checked in by pjkersha, 9 years ago (diff)

WGet scripts for ESG data download

Line 
1#
2# ESG Download script wraps wget call with settings for ESG Security
3#
4# @author P J Kershaw 28/07/2010
5#
6# @copyright: (C) 2010 STFC
7#
8# @license: BSD - See top-level LICENCE file for licence details
9#
10# $Id$
11cmdname=$(basename $0)
12cmdline_opt=`getopt -o hO: --long help,output-document:,certificate:,private-key:,ca-directory:,save-cookies:: -n "$cmdname" -- "$@"`
13
14defaultCaDir=$HOME/.globus/certificates/esg
15esgDotDir=$HOME/.esg
16defaultCookieFile=$esgDotDir/cookies.txt
17usage="Usage: $cmdname <data download URI> <options ...>\n
18\n
19Script for Earth System Grid data download.\n\n
20
21   Options\n
22       -h | --help\t\t\t\tDisplays usage\n
23       -O | --output-document\t<filepath>\tLocation of output file (defaults to appropriate file name based on requested URI\n
24       --certificate\t<certificate file>\tSSL certificate to authenticate with (PEM format)\n
25       --private-key\t<private key file>\tfile containing private key for SSL authentication (PEM format)\n
26       --ca-directory\t<directory path>\tDirectory containing the trusted CA (Certificate Authority) certificates used\n
27       \t\t\t\t\tto verify the identity of the server\n
28       \t\t\t\t\t(defaults to $defaultCaDir).  These files can be\n
29       \t\t\t\t\tobtained by a call to MyProxy logon saving 'trust roots'\n
30       \t\t\t\t\tto the selected CA directory.\n
31       --save-cookies\t<cookie file>\t\tSave cookies to this file.  The default location is $defaultCookieFile
32"
33
34if [ $? != 0 ] ; then
35    echo -e $usage >&2 ;
36    exit 1 ;
37fi
38
39eval set -- "$cmdline_opt"
40
41while true ; do
42    case "$1" in
43        -h|--help) echo -e $usage ; exit 0 ;;
44        --certificate) certFile=$2 ; shift 2 ;;
45        --private-key) privateKeyFile=$2 ; shift 2 ;;
46        --ca-directory) caDir=$2 ; shift 2 ;;
47        -O|--output-document) outputFile=$2 ; shift 2 ;;
48        --save-cookies) cookieFile=$2 ; shift 2 ;;
49        --) uri=$2 ; shift 1 ; break ;;
50        *) echo "Error parsing command line" ; exit 1 ;;
51#        *) echo "uri opt: $1" ; uri=$1 ; shift 1 ; break ;;
52    esac
53done
54
55if [ -z $uri ]; then
56    echo "Error: missing download URI." >&2 ;
57    echo -e $usage >&2 ;
58    exit 1 ;
59fi
60   
61# Set-up trust root
62if [ -z $caDir ]; then 
63    if [ ${X509_CERT_DIR} ]; then
64        caDir=${X509_CERT_DIR}
65    elif [ "$username" = "root" ]; then
66        caDir=/etc/grid-security/certificates
67    else
68        caDir=${HOME}/.globus/certificates/esg
69    fi
70fi
71
72# Set-up client certificate and private key
73if [ -z $certFile ]; then
74    if [ ${X509_USER_PROXY} ]; then
75        # This environment variable setting means both cert and key are
76        # concatenated together in the same file
77        certFile=${X509_USER_PROXY}
78        privateKeyFile=${X509_USER_PROXY}
79       
80    elif [ ${X509_USER_CERT} ]; then
81        certFile=${X509_USER_CERT}   
82    fi
83   
84    # No check for cert not set because this is a valid condition if the data
85    # requested is not secured.
86fi
87
88if [ -z $privateKeyFile ]; then
89    if [ ${X509_USER_KEY} ]; then
90        privateKeyFile=${X509_USER_KEY}
91    fi
92   
93    # No check for key not set because this is a valid condition if the data
94    # requested is not secured
95fi
96
97# Set-up the cookie file path
98if [ -z $cookieFile ]; then
99    cookieFile=$defaultCookieFile
100    if [ ! -d $esgDotDir ]; then
101        mkdir $esgDotDir ;
102    fi
103fi
104
105if [ $outputFile ]; then
106    outputFileSetting=--output-document=$outputFile
107else
108    outputFileSetting=
109fi
110
111# Make the call
112wget --secure-protocol=SSLv3 \
113 --ca-directory=$caDir \
114 --certificate=$certFile \
115 --private-key=$privateKeyFile \
116 --keep-session-cookies \
117 --save-cookies=$cookieFile \
118 --cookies=on \
119 $outputFileSetting \
120 $uri
Note: See TracBrowser for help on using the repository browser.