-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdeliver_project_to_user.sh
executable file
·80 lines (68 loc) · 2.19 KB
/
deliver_project_to_user.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /bin/bash -l
###
# This is a simple wrapper around the deliver.py script, which should facilitate the delivery for the SNP platform
###
# Expects project id, email address and "sensitive" or "not-sensitive" as arguments. Optionally, specify a ";"-delimited list of members email addresses
PROJECT=$1
EMAIL=$2
SENSITIVE="--$3"
MEMBERS="$4"
# display usage instructions when invoked without arguments
if [[ -z "$PROJECT" ]]
then
echo ""
echo "Deliver SNP genotyping data to SNIC users via GRUS"
echo ""
echo " usage: ${0} <PROJECT ID> <PI EMAIL> {sensitive|not-sensitive} ['[email protected];[email protected]']"
echo ""
exit 1
fi
# Add members
MEMBER_ARG=""
if [[ ! -z "$MEMBERS" ]]
then
MEMBER_ARG="--member_email"
for a in $(echo "$MEMBERS" |sed -re 's/;/ /g')
do
MEMBER_ARG="$MEMBER_ARG $a"
done
fi
# set up paths
GENOTYPEDIR="/proj/ngi2016001/incoming/GENOTYPING"
STAGINGDIR="$GENOTYPEDIR/staging"
SUPRCREDS="$GENOTYPEDIR/supr_creds.txt"
PROJPATH="$GENOTYPEDIR/$PROJECT"
LOGFILE=${0}.log
OUTFILE=${0}.out
ERRFILE=${0}.err
TSTAMP=$(date +%s)
MD5FILE="$GENOTYPEDIR/${PROJECT}.${TSTAMP}.md5"
ORIGINAL_CWD="$(pwd)"
# make the genotypedir the cwd
cd "$GENOTYPEDIR"
# File containing the SUPR credentails
URL=$(cut -f 1 "$SUPRCREDS")
USR=$(cut -f 2 "$SUPRCREDS")
PASS=$(cut -f 3 "$SUPRCREDS")
# Command to launch the delivery script
CMD=$(echo /vulpes/ngi/production/latest/sw/anaconda/envs/ugc_delivery_script/bin/python \
/vulpes/ngi/production/latest/sw/ugc_delivery_src/deliver.py \
--supr_url $URL \
--supr_api_user $USR \
--supr_api_key $PASS \
--staging_area $STAGINGDIR \
--path $PROJPATH \
--project $PROJECT \
--email $EMAIL \
--path-to-mover /usr/local/bin \
$SENSITIVE $MEMBER_ARG)
# Calculate MD5 sums of all delivered files
find $PROJECT -type f -exec md5sum {} \; > $MD5FILE
mv $MD5FILE $PROJPATH/
# Log the delivery
MSG="$TSTAMP "$(date -d @$TSTAMP --utc +"%Y-%m-%dT%H:%M:%SZ")" $(hostname) ${USER} ${PROJPATH}/$(basename $MD5FILE) "$(echo $CMD |sed -re "s/$PASS/**************/")
echo "$MSG" |tee -a $LOGFILE $OUTFILE $ERRFILE
# Execute the command, duplicating stdout and stderr to files
$CMD 1> >(tee -a $OUTFILE) 2> >(tee -a $ERRFILE >&2)
# change the cwd back
cd "$ORIGINAL_CWD"