Created
June 2, 2016 22:44
-
-
Save kapadia/a9009159b45fc7d99ad9d100b43890a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source /etc/profile | |
set -eou pipefail | |
function usage() { | |
echo "" | |
echo "Download a Landsat scene from USGS." | |
echo "" | |
echo "Usage: ./download-landsat [scene id]" | |
echo "" | |
} | |
sceneid=${1:-} | |
if [[ -z $sceneid ]]; then | |
usage; | |
exit 1; | |
fi | |
function onerror() { | |
rm -f /mnt/$sceneid.tar.gz | |
sleep $[ $RANDOM % 10 + 1]s | |
exit 1 | |
} | |
trap onerror EXIT | |
function download_landsat() { | |
local sceneid=$1 | |
echo "Requesting a download url for $sceneid" | |
url=$(usgs download-url --node EE LANDSAT_8 $sceneid --product STANDARD) | |
echo "Downloading $sceneid" | |
dstpath=/mnt/$sceneid.tar.gz | |
curl --silent --fail "$url" -o "$dstpath" | |
echo "Copying $sceneid to $dstpath" | |
aws s3 cp $dstpath s3://landsat-pds/tarq/ --profile landsat | |
rm -f $dstpath | |
} | |
download_landsat $sceneid | |
trap - EXIT | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment