-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
executable file
·120 lines (95 loc) · 2.97 KB
/
run.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
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
#!/usr/bin/env bash
usage() {
echo "Usage: $(basename $0) -g glider_name -d mission_directory -m metadata_file_name -p mode(realtime|delayed) [-t CGDACusername]"
}
while getopts ":g:d:m:p:t::" opt; do
case "${opt}" in
g)
glider=${OPTARG}
;;
d)
missionDir=${OPTARG}
;;
m)
metadataFile=${OPTARG}
;;
p)
processingMode=${OPTARG}
;;
t)
CGDAC_username=${OPTARG}
;;
h)
usage
exit 0
;;
:)
echo -e "option requires an argument."
usage
exit 1
;;
?)
echo -e "Invalid command option."
usage
exit 1
;;
*)
usage
exit 1
;;
esac
done
if [[ -z ${glider} ]] || [[ -z ${missionDir} ]] || [[ -z ${metadataFile} ]] || [[ -z ${processingMode} ]]; then
usage
exit 1
fi
script=$(realpath $0)
export scriptsDir=$(dirname ${script})/scripts
######################################################
#### INITIAL CHECKS
bash ${scriptsDir}/check.sh ${scriptsDir} ${missionDir} ${metadataFile} ${processingMode}
if [[ $? -ne 0 ]]; then
exit 1
fi
######################################################
## PREPARE DIRECTORIES
mkdir -p ${missionDir}/${processingMode}/nc
######################################################
## LOWERCASE CACHE FILES (NEEDED BY "dbdreader")
cd ${missionDir}/cache
for f in $(find .); do
ln -s "$f" "$(echo $f | tr '[A-Z]' '[a-z]')" 2>/dev/null
done
######################################################
cd ${missionDir}/${processingMode}/raw
## CHECK IF THERE IS ANY NC FILE OLDER THAN A TXT FILE
newestRAWfile=$(ls -tr ${missionDir}/${processingMode}/raw | tail -1 | xargs -I{} date -r {} +%s)
newestNCfile=$(ls -tr ${missionDir}/${processingMode}/nc | tail -1 | xargs -I{} date -r {} +%s)
if [[ ${newestRAWfile} -gt ${newestNCfile} ]]; then
python3 ${scriptsDir}/bd2nc.py --glider=${glider} --mode=${processingMode} --metadataFile=${metadataFile}
# python3 ${scriptsDir}/bd2nc_oldMissions.py --glider=${glider} --mode=${processingMode} --metadataFile=${metadataFile}
else
echo "No new file to process. Exiting now."
fi
find ${missionDir}/${processingMode}/nc -empty -delete
## UPLOAD NC FILES TO CGDAC
# CREATE A NEW DEPLOYMENT
if [[ ! -z ${CGDAC_username} ]]; then
if [[ ${processingMode} == 'delayed' ]]; then delayedModeBool=true; fi
deplymentDate=$(grep deployment_date ${metadataFile} | awk '{print $2}' | cut -dT -f1 | sed 's/-//g')T0000
curl -X 'POST' \
"https://cgdac.ca/api/deployment/?username=${CGDAC_username}&deployment_name=${glider}&deployment_date=${deplymentDate}&delayed_mode=${delayedModeBool}" \
-H 'accept: application/json' \
-H "X-API-KEY: ${token}" \
-d ''
deploymentName="${glider}-${deplymentDate}"
if [[ ${processingMode} == 'delayed' ]]; then deploymentName="${deploymentName}-delayed"; fi
for f in *.nc; do
curl -X 'POST' \
"https://cgdac.ca/api/deployment_file/?username=${CGDAC_username}&deployment_name=${deploymentDate}" \
-H 'accept: application/json' \
-H "X-API-KEY: ${token}" \
-H 'Content-Type: multipart/form-data' \
-F "file=@${f};type=application/x-netcdf"
done
fi