-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecksum.template
executable file
·177 lines (132 loc) · 3.39 KB
/
checksum.template
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
echo
echo "Begin debug messages from checksum.template"
echo
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 "INPUT"
echo
echo "UUID: ${UUID}"
echo "SRA_NUM: ${SRA}"
echo "AGAVE_FILE: ${AGAVE_URL}"
echo "EXTERNAL_URL: ${URL}"
echo
echo "DEBUG"
echo
# internal agave file provided
if [ ${AGAVE_FILE} != "" ]; then
echo "Internal agave file provided."
echo "FILE_PATH: ${AGAVE_FILE}"
echo
FILE_PATH=${AGAVE_FILE}
else
# SRA number provided
if [ ${SRA_NUM} != "" ];then
echo "SRA number provided."
echo "SRA_NUM: ${SRA_NUM}"
echo
echo "Make aspera executable."
echo "$ chmod 755 ./bin/aspera.sh"
echo
chmod 755 ./bin/aspera.sh
echo "Download SRA data using aspera."
echo "$ ./bin/aspera.sh ${SRA_NUM} ${SRA_PATH}"
echo
# Downloading file
./bin/aspera.sh ${SRA_NUM} ${SRA_PATH}
# Running checksum and update metadata
if [ $? -eq 0 ]; then
echo "Aspera exited successfully."
echo
FILE_PATH="./SRA/${SRA_NUM}.sra"
else
echo "Aspera did not exit successfully."
echo "Exiting job with error code ${?}"
echo
echo "End debug messages from checksum.template"
echo
exit $?
fi
else
# external file URL provided
if [ ${EXTERNAL_URL} != "" ]; then
echo "External URL provided."
echo "EXTERNAL_URL: ${EXTERNAL_URL}"
echo
echo "Download external data."
echo "$ wget ${EXTERNAL_URL}"
echo
# Download external file
wget ${EXTERNAL_URL}
if [ $? -eq 0 ]; then
echo "wget exited successfully."
echo
FILE_PATH="${EXTERNAL_URL##*/}"
else
echo "wget did not exit successfully."
echo "Exiting job with error code ${?}"
echo
echo "End debug messages from checksum.template"
echo
exit $?
fi
else
echo 'No input of file match!'
echo
echo "End debug messages from checksum.template"
echo
exit 1
fi
fi
fi
echo "FILE_PATH: ${FILE_PATH}"
echo
if [ ! -f "${FILE_PATH}" ]; then
echo 'File not found! Please confirm the input.'
echo "Exiting with error code 1"
echo
echo "End debug messages from checksum.template"
echo
exit 1
fi
md5=($(md5sum ${FILE_PATH}))
lastChecksumUpdated=$(date '+%Y-%m-%d %X')
echo "checksum: ${md5}"
echo "lastChecksumUpdated: ${lastChecksumUpdated}"
echo
# echo "Post the checksum to requestbin."
# echo "$ curl -k --data \"UUID=${UUID}&checksum=${md5}&lastChecksumUpdated=${lastChecksumUpdated}\" http://requestb.in/v0cdvwv0"
# echo
# post to requestbin, used for development
# curl -k --data "UUID=${UUID}&checksum=${md5}&lastChecksumUpdated=${lastChecksumUpdated}" http://requestb.in/v0cdvwv0
echo "Post the checksum to webhook."
echo "$ curl -k --data \"UUID=${UUID}&checksum=${md5}&lastChecksumUpdated=${lastChecksumUpdated}\" https://identifierservices.org/webhook/update_checksum"
echo
# post the checksum to webhook
curl -k --data "UUID=${UUID}&checksum=${md5}&lastChecksumUpdated=${lastChecksumUpdated}" https://identifierservices.org/webhook/update_checksum
if [ $? -eq 0 ]; then
echo "curl exited successfully."
echo
else
echo "curl did not exit successfully."
echo
fi
echo "Removing file."
echo "rm ${FILE_PATH}"
echo
rm ${FILE_PATH}
echo "Removing directory."
echo "rm -rf SRA"
echo
rm -rf SRA
echo "Exiting error code 0"
echo
echo "End debug messages from checksum.template"
echo
exit 0