Skip to content

Instantly share code, notes, and snippets.

@kapadia
Created June 2, 2016 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kapadia/a9009159b45fc7d99ad9d100b43890a6 to your computer and use it in GitHub Desktop.
Save kapadia/a9009159b45fc7d99ad9d100b43890a6 to your computer and use it in GitHub Desktop.
#!/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