Created
March 29, 2021 16:01
-
-
Save dmd/910a7473e1fd77ff8d2a50ac73358b9f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# | |
# 2021 ddrucker | |
set -o errexit | |
if [ $# -lt 2 ]; then | |
echo "Usage: $0 xnat_username accessionid [accessionid accessionid ...]" | |
echo "accessionid can be the MGB-generated one, which (typically) starts with E," | |
echo "OR the XNAT-generated one, which starts with XNAT_E." | |
exit 1 | |
fi | |
cleanup() { rm -f "${ACC}.zip"; } | |
trap cleanup INT | |
URL=https://image-test.mclean.harvard.edu | |
WHO=$1 | |
shift | |
## auth to xnat | |
echo "Please enter your XNAT password." | |
JSESSIONID=$(curl -s -u $WHO "$URL/data/JSESSION") | |
if [[ "$JSESSIONID" == *"Unauthorized"* ]]; then | |
echo "Login failed." | |
exit 1 | |
fi | |
## retrieve each one | |
for ACC in $@; do | |
echo "Retrieving $ACC ..." | |
if [[ $ACC == XNAT_S* ]]; then | |
echo "$ACC is an XNAT Subject ID, not a Session id." | |
echo "Session IDs start with XNAT_E." | |
continue | |
fi | |
if [[ $ACC == XNAT_E* ]]; then | |
SESSIONID=$ACC | |
else | |
SESSIONID=$(curl -s -b JSESSIONID=$JSESSIONID "$URL/data/experiments?format=json&label=$ACC" | jq -r '.ResultSet.Result[0].ID' ) | |
if [[ $SESSIONID == null ]]; then | |
echo "Something went wrong trying to get $ACC." | |
continue | |
fi | |
fi | |
curl -b JSESSIONID=$JSESSIONID "$URL/data/experiments/$SESSIONID/scans/ALL/files?format=zip" -o $ACC.zip | |
7z x $ACC.zip | |
rm -f $ACC.zip | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment