Skip to content

Instantly share code, notes, and snippets.

@andrewmagill
Created May 24, 2016 22:25
Show Gist options
  • Save andrewmagill/0900a7a90004e129174e5695621fe2ec to your computer and use it in GitHub Desktop.
Save andrewmagill/0900a7a90004e129174e5695621fe2ec to your computer and use it in GitHub Desktop.
#!/bin/bash
export PATH=$PATH:"$HOME/.aspera/connect/bin"
# get UUID and SRA number
UUID=${UUID}
SRA_NUM=${SRA}
AGAVE_FILE=${AGAVE_URL}
EXTERNAL_URL=${URL}
SRA_PATH="./SRA/"
FILE_PATH=""
echo ${AGAVE_FILE}
# internal agave file provided
if [ ${AGAVE_FILE} != "" ]; then
FILE_PATH=${AGAVE_FILE}
else
# SRA number provided
if [ ${SRA_NUM} != "" ];then
# Downloading file
chmod 755 ./bin/aspera.sh
./bin/aspera.sh ${SRA_NUM} ${SRA_PATH}
# Running checksum and update metadata
if [ $? -eq 0 ]; then
FILE_PATH="./SRA/${SRA_NUM}.sra"
else
exit 1
fi
else
# external file URL provided
if [ ${EXTERNAL_URL} != "" ]; then
# Download external file
wget ${EXTERNAL_URL}
if [ $? -eq 0 ]; then
FILE_PATH="${EXTERNAL_URL##*/}"
else
exit 1
fi
else
echo 'No input of file match!'
exit 1
fi
fi
fi
echo ${FILE_PATH}
if [ ! -f "${FILE_PATH}" ]; then
echo 'File not found! Please confirm the input.'
exit 1
fi
md5=($(md5sum ${FILE_PATH}))
lastChecksumUpdated=$(date '+%Y-%m-%d %X')
echo ${md5}
# post the checksum to webhook
curl -k --data "UUID=${UUID}&checksum=${md5}&lastChecksumUpdated=${lastChecksumUpdated}" http://requestb.in/v0cdvwv0
curl -k --data '{"UUID":${UUID},"checksum":${md5}}' https://identifierservices.org/webhook/update_checksum
rm ${FILE_PATH}
rm -rf SRA
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment