Subversion Repositories DevTools

Rev

Rev 6128 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6128 Rev 6129
Line 30... Line 30...
30
    -f, --force             - Delete target and force package download
30
    -f, --force             - Delete target and force package download
31
    -k, --key=keyVar        - Name of the EnvVar that conains the AWS key
31
    -k, --key=keyVar        - Name of the EnvVar that conains the AWS key
32
                              Default is AWSKEY
32
                              Default is AWSKEY
33
    -s, --secret=secretVar  - Name of the EnvVar that conains the AWS secret
33
    -s, --secret=secretVar  - Name of the EnvVar that conains the AWS secret
34
                              Default is AWSSECRET
34
                              Default is AWSSECRET
-
 
35
    -t, --test              - Do not copy, do not request Glacier restore
35
 
36
 
36
   Example:
37
   Example:
37
    getPkgFromS3.sh -p \$GBE_DPKG/AcceptanceTestFramework/1.0.10000.cr
38
    getPkgFromS3.sh -p \$GBE_DPKG/AcceptanceTestFramework/1.0.10000.cr
38
endOfHelp
39
endOfHelp
39
}
40
}
Line 45... Line 46...
45
awsKeyVar=AWSKEY
46
awsKeyVar=AWSKEY
46
awsSecretVar=AWSSECRET
47
awsSecretVar=AWSSECRET
47
bucket=aupera-dpkg-quarantine
48
bucket=aupera-dpkg-quarantine
48
verbose=1
49
verbose=1
49
forceDelete=0
50
forceDelete=0
-
 
51
doOps=true
50
 
52
 
51
# Note that we use `"$@"' to let each command-line parameter expand to a 
53
# Note that we use `"$@"' to let each command-line parameter expand to a 
52
# separate word. The quotes around `$@' are essential!
54
# separate word. The quotes around `$@' are essential!
53
# We need TEMP as the `eval set --' would nuke the return value of getopt.
55
# We need TEMP as the `eval set --' would nuke the return value of getopt.
54
TEMP=$( getopt -n ${ProgName} -o qfvhb:p:k:s: --long quiet,force,verbose,help,bucket:,path:,key:,secret: -- "$@" )
56
TEMP=$( getopt -n ${ProgName} -o qfvhb:p:k:s:t --long quiet,force,verbose,help,bucket:,path:,key:,secret:,test -- "$@" )
55
 
57
 
56
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
58
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
57
 
59
 
58
# Note the quotes around `$TEMP': they are essential!
60
# Note the quotes around `$TEMP': they are essential!
59
eval set -- "$TEMP"
61
eval set -- "$TEMP"
Line 66... Line 68...
66
        -v|--verbose) let verbose++; shift 1;;
68
        -v|--verbose) let verbose++; shift 1;;
67
        -b|--bucket)  bucket="$2" ; shift 2 ;;
69
        -b|--bucket)  bucket="$2" ; shift 2 ;;
68
        -p|--path)    dpkgPath="$2" ; shift 2 ;;
70
        -p|--path)    dpkgPath="$2" ; shift 2 ;;
69
        -k|--key)     awsKeyVar="$2" ; shift 2 ;;
71
        -k|--key)     awsKeyVar="$2" ; shift 2 ;;
70
        -s|--secret)  awsSecretVar="$2" ; shift 2 ;;
72
        -s|--secret)  awsSecretVar="$2" ; shift 2 ;;
-
 
73
        -t|--test)   doOps=false ; shift 1 ;;
71
        --) shift ; break ;;
74
        --) shift ; break ;;
72
        *) echo "Internal error!" ; exit 1 ;;
75
        *) echo "Internal error!" ; exit 1 ;;
73
    esac
76
    esac
74
done
77
done
75
 
78
 
Line 135... Line 138...
135
 
138
 
136
# Force version deletion - more for test.
139
# Force version deletion - more for test.
137
if [ $forceDelete -gt 0 ] ; then 
140
if [ $forceDelete -gt 0 ] ; then 
138
    [ $verbose -gt 0 ] && echo "Force removal of $pkgName/$pkgVer"
141
    [ $verbose -gt 0 ] && echo "Force removal of $pkgName/$pkgVer"
139
    if [ -d $dpkgPath ] ; then
142
    if [ -d $dpkgPath ] ; then
-
 
143
        if $doOps ; then
140
        chmod -R +w $dpkgPath
144
            chmod -R +w $dpkgPath
141
        rm -rf $dpkgPath
145
            rm -rf $dpkgPath
-
 
146
        else
-
 
147
            echo "TestMode: Did not remove: $pkgName/$pkgVer"
-
 
148
        fi     
142
    fi
149
    fi
143
fi
150
fi
144
 
151
 
145
if [  -d $dpkgPath ] ; then
152
if [  -d $dpkgPath ] ; then
146
    echo "Error: Target PV Path already exists: $dpkgPath"
153
    echo "Error: Target PV Path already exists: $dpkgPath"
-
 
154
    echo "TestMode: $doOps"
-
 
155
    if ! $doOps ; then
-
 
156
        echo "TestMode: Error ignored"
-
 
157
    else
147
    exit 1
158
        exit 1
-
 
159
    fi
148
fi
160
fi
149
 
161
 
150
#
162
#
151
#   Create the source file name
163
#   Create the source file name
152
#   Format: Quarantined/PkgName_PkgVersion.tgz
164
#   Format: Quarantined/PkgName_PkgVersion.tgz
Line 181... Line 193...
181
        -H "Host: ${bucket}.s3.amazonaws.com" \
193
        -H "Host: ${bucket}.s3.amazonaws.com" \
182
        -H "Date: ${dateValue}" \
194
        -H "Date: ${dateValue}" \
183
        -H "Authorization: AWS ${aws_access_key_id}:${signature}" \
195
        -H "Authorization: AWS ${aws_access_key_id}:${signature}" \
184
        "https://${bucket}.s3.amazonaws.com/${file}" \
196
        "https://${bucket}.s3.amazonaws.com/${file}" \
185
        )
197
        )
-
 
198
if [ $verbose -gt 2 ] ; then
186
[ $verbose -gt 2 ] && echo "Testing file response: ${results}"
199
    echo "Testing file response"
-
 
200
    echo "$results" | fold -w100 | awk '{print "    " $0}'
-
 
201
fi
-
 
202
 
187
if [[ "$results" =~ "HTTP/1.1 200 OK" ]]; then
203
if [[ "$results" =~ "HTTP/1.1 200 OK" ]]; then
188
    fileTest=1
204
    fileTest=1
189
fi
205
fi
190
 
206
 
191
# Display results
207
# Display results
Line 244... Line 260...
244
 
260
 
245
##############################################################
261
##############################################################
246
#   Initiate a Restore from Glacier
262
#   Initiate a Restore from Glacier
247
#
263
#
248
if $mustRestore ; then
264
if $mustRestore ; then
249
    if [ 1 ] ; then
265
    if $doOps ; then
250
        [ $verbose -gt 0 ] && echo "Initiate restore from Glacier $pkgName/$pkgVer"
266
        [ $verbose -gt 0 ] && echo "Initiate restore from Glacier $pkgName/$pkgVer"
251
 
267
 
252
        # Generate a Restore Request
268
        # Generate a Restore Request
253
        #   And an MD5 over the data
269
        #   And an MD5 over the data
254
        tmpData=$( mktemp )
270
        tmpData=$( mktemp )
Line 296... Line 312...
296
        elif [[ "$results" == "503" ]] ; then
312
        elif [[ "$results" == "503" ]] ; then
297
            message="Glacier expedited retrievals are currently not available"
313
            message="Glacier expedited retrievals are currently not available"
298
        else
314
        else
299
            mesage="Error previously reported"
315
            mesage="Error previously reported"
300
            echo "Glacier restore error code: $results"
316
            echo "Glacier restore error code: $results"
301
            tail -n+2 $tmpResult | fold | awk '{print "    " $0}'
317
            tail -n+2 $tmpResult | fold -w100 | awk '{print "    " $0}'
302
        fi                              
318
        fi                              
303
        set +x
319
        set +x
304
        rm -rf $tmpData $tmpResult
320
        rm -rf $tmpData $tmpResult
305
 
321
 
-
 
322
    else
-
 
323
        echo "TestMode: Do not request Glacier Restore"
306
    fi
324
    fi
307
fi
325
fi
308
 
326
 
309
if ! $canGet; then
327
if ! $canGet; then
310
        echo "${ProgName}: Error cannot access $pkgName/$pkgVer. $message"
328
        echo "${ProgName}: Error cannot access $pkgName/$pkgVer. $message"
Line 334... Line 352...
334
if [  ! -d $dpkgPath ] ; then
352
if [  ! -d $dpkgPath ] ; then
335
    echo "Error: Could not create: $dpkgPath"
353
    echo "Error: Could not create: $dpkgPath"
336
    exit 1
354
    exit 1
337
fi
355
fi
338
 
356
 
339
if [ 1 ] ; then
357
if $doOps ; then
340
[ $verbose -gt 0 ] && echo "Transfer $pkgName/$pkgVer from bucket $bucket"
358
    [ $verbose -gt 0 ] && echo "Transfer $pkgName/$pkgVer from bucket $bucket"
341
#set -x
359
    #set -x
342
    curl -s \
360
        curl -s \
343
        -X GET \
361
            -X GET \
344
         --insecure \
362
             --insecure \
345
        -H "Host: ${bucket}.s3.amazonaws.com" \
363
            -H "Host: ${bucket}.s3.amazonaws.com" \
346
        -H "Date: ${dateValue}" \
364
            -H "Date: ${dateValue}" \
347
        -H "Authorization: AWS ${aws_access_key_id}:${signature}" \
365
            -H "Authorization: AWS ${aws_access_key_id}:${signature}" \
348
        "https://${bucket}.s3.amazonaws.com/${file}" \
366
            "https://${bucket}.s3.amazonaws.com/${file}" \
349
        | tar -xz --strip=2 -C $dpkgPath
367
            | tar -xz --strip=2 -C $dpkgPath
350
fi
-
 
351
 
368
 
352
if [ ! -f "$dpkgPath/descpkg" ] ; then
369
    if [ ! -f "$dpkgPath/descpkg" ] ; then
353
    echo "Error: Target PV did not populate as expected: $dpkgPath"
370
        echo "Error: Target PV did not populate as expected: $dpkgPath"
354
 
371
 
355
    # Remove if not correctly formatted
372
        # Remove if not correctly formatted
356
    chmod -R +w $dpkgPath
373
        chmod -R +w $dpkgPath
357
    rm -rf $dpkgPath
374
        rm -rf $dpkgPath
358
    exit 1
375
        exit 1
-
 
376
    else
-
 
377
        # Package extracted
-
 
378
        # Touch the top directory so that it will not be quarantined immediatly
-
 
379
        chmod +w "$dpkgPath"
-
 
380
        chmod -w "$dpkgPath"
-
 
381
    fi
359
else
382
else
360
    # Package extracted
-
 
361
    # Touch the top directory so that it will not be quarantined immediatly
383
    echo "TestNode: Did not transfer $pkgName/$pkgVer from bucket $bucket"
362
    chmod +w "$dpkgPath"
-
 
363
    chmod -w "$dpkgPath"
-
 
364
fi
384
fi
365
 
385
 
366
[ $verbose -gt 0 ] && echo "Transfer complete"
386
[ $verbose -gt 0 ] && echo "Transfer complete"
367
 
387
 
368
  
388