-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.sh
283 lines (255 loc) · 10.3 KB
/
upload.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/bash
SAT=$1
SAT_NORM=${1// /_} # Substitude space on upload
FILEKEY=$2
AUDIO_DIR=${WX_GROUND_DIR}/audio
IMAGE_DIR=$WX_GROUND_DIR/images
FTP_DIRECTORY=$WX_GROUND_FTP_DIR
# MySQL Database
DB_DATABASE=${WX_GROUND_DB_DATABASE}
DB_HOST=${WX_GROUND_DB_SERVER}
DB_USER=${WX_GROUND_DB_USER}
DB_PASS=${WX_GROUND_DB_PASS}
if [[ "$SAT" == "NOAA 19" || "$SAT" == "NOAA 15" || "$SAT" == "NOAA 18" ]]; then
AUDIO_FILE=${FILEKEY}.wav
AUDIO_FILE_DIR=${AUDIO_DIR}/${FILEKEY}.wav
IQ_FILE=${FILEKEY}.iq
IQ_FILE_DIR=${AUDIO_DIR}/${FILEKEY}.iq
MAP_FILE=${FILEKEY}-map.png
MAP_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-map.png
ZA_FILE=${FILEKEY}-ZA.png
ZA_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-ZA.png
NO_FILE=${FILEKEY}-NO.png
NO_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-NO.png
MSA_FILE=${FILEKEY}-MSA.png
MSA_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-MSA.png
MCIR_FILE=${FILEKEY}-MCIR.png
MCIR_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-MCIR.png
THERM_FILE=${FILEKEY}-THERM.png
THERM_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-THERM.png
MB_FILE=${FILEKEY}-MB.png
MB_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-MB.png
MD_FILE=${FILEKEY}-MD.png
MD_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-MD.png
BD_FILE=${FILEKEY}-BD.png
BD_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-BD.png
CC_FILE=${FILEKEY}-CC.png
CC_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-CC.png
EC_FILE=${FILEKEY}-EC.png
EC_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-EC.png
HE_FILE=${FILEKEY}-HE.png
HE_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-HE.png
HF_FILE=${FILEKEY}-HF.png
HF_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-HF.png
JF_FILE=${FILEKEY}-JF.png
JF_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-JF.png
JJ_FILE=${FILEKEY}-JJ.png
JJ_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-JJ.png
LC_FILE=${FILEKEY}-LC.png
LC_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-LC.png
WV_FILE=${FILEKEY}-WV.png
WV_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-WV.png
MSA_PRECIP_FILE=${FILEKEY}-MSA-precip.png
MSA_PRECIP_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-MSA-precip.png
HVC_FILE=${FILEKEY}-HVC.png
HVC_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-HVC.png
HVCT_FILE=${FILEKEY}-HVCT.png
HVCT_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-HVCT.png
SEA_FILE=${FILEKEY}-sea.png
SEA_FILE_DIR=${IMAGE_DIR}/${FILEKEY}-sea.png
echo "UPLOADING FILES"
echo $IQ_FILE_DIR
echo $MAP_FILE_DIR
echo $ZA_FILE_DIR
echo $NO_FILE_DIR
echo $MSA_FILE_DIR
echo $MCIR_FILE_DIR
echo $THERM_FILE_DIR
echo $MB_FILE_DIR
echo $MD_FILE_DIR
echo $BD_FILE_DIR
echo $CC_FILE_DIR
echo $EC_FILE_DIR
echo $HE_FILE_DIR
echo $HF_FILE_DIR
echo $JF_FILE_DIR
echo $JJ_FILE_DIR
echo $LC_FILE_DIR
echo $WV_FILE_DIR
echo $MSA_PRECIP_FILE_DIR
echo $HVC_FILE_DIR
echo $HVCT_FILE_DIR
echo $SEA_FILE_DIR
DATE=`date +%Y-%m-%d`
HOST=$WX_GROUND_FTP_SERVER
USER=$WX_GROUND_FTP_USER
PASSWD=$WX_GROUND_FTP_PASS
# Upload to FTP
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
mkdir $FTP_DIRECTORY
cd $FTP_DIRECTORY
mkdir $SAT_NORM
cd $SAT_NORM
mkdir $DATE
cd $DATE
binary
put $AUDIO_FILE_DIR $AUDIO_FILE
put $IQ_FILE_DIR $IQ_FILE
put $MAP_FILE_DIR $MAP_FILE
put $ZA_FILE_DIR $ZA_FILE
put $NO_FILE_DIR $NO_FILE
put $MSA_FILE_DIR $MSA_FILE
put $MCIR_FILE_DIR $MCIR_FILE
put $THERM_FILE_DIR $THERM_FILE
put $MB_FILE_DIR $MB_FILE
put $MD_FILE_DIR $MD_FILE
put $BD_FILE_DIR $BD_FILE
put $CC_FILE_DIR $CC_FILE
put $EC_FILE_DIR $EC_FILE
put $HE_FILE_DIR $HE_FILE
put $HF_FILE_DIR $HF_FILE
put $JF_FILE_DIR $JF_FILE
put $JJ_FILE_DIR $JJ_FILE
put $LC_FILE_DIR $LC_FILE
put $WV_FILE_DIR $WV_FILE
put $MSA_PRECIP_FILE_DIR $MSA_PRECIP_FILE
put $HVC_FILE_DIR $HVC_FILE
put $HVCT_FILE_DIR $HVCT_FILE
put $SEA_FILE_DIR $SEA_FILE
quit
END_SCRIPT
# Send web hook to IFTTT
if [[ "$WX_GROUND_IFTTT_WEBHOOK" != "" ]]; then
IMAGE_URL="${WX_GROUND_FTP_URL}/${FTP_DIRECTORY}/${SAT_NORM}/${DATE}/${FILEKEY}-MCIR.png"
HUMAN_TIME=`date +%H:%M`
echo "curl -X POST -H \"Content-Type: application/json\" -d '{\"value1\":\"'\"${SAT}\"'\",\"value2\":\"'\"${HUMAN_TIME}\"'\",\"value3\":\"'\"${IMAGE_URL}\"'\"}' ${WX_GROUND_IFTTT_WEBHOOK}"
curl -X POST -H "Content-Type: application/json" -d '{"value1":"'"${SAT}"'","value2":"'"${HUMAN_TIME}"'","value3":"'"${IMAGE_URL}"'"}' ${WX_GROUND_IFTTT_WEBHOOK}
fi
fi
if [[ "$SAT" == "METEOR-M 2" ]]; then
AUDIO_FILE=${FILEKEY}.wav
AUDIO_FILE_DIR=${AUDIO_DIR}/${FILEKEY}.wav
IQ_FILE=${FILEKEY}.iq
IQ_FILE_DIR=${AUDIO_DIR}/${FILEKEY}.iq
QPSK_FILE=${FILEKEY}.qpsk
QPSK_FILE_DIR=${AUDIO_DIR}/${FILEKEY}.qpsk
DEC_FILE=${FILEKEY}.dec
DEC_FILE_DIR=${AUDIO_DIR}/${FILEKEY}.dec
BMP_FILE=${FILEKEY}.bmp
BMP_FILE_DIR=${IMAGE_DIR}/${FILEKEY}.bmp
IR_BMP_FILE=${FILEKEY}_IR.bmp
IR_BMP_FILE_DIR=${IMAGE_DIR}/${FILEKEY}_IR.bmp
PNG_FILE=${FILEKEY}.png
PNG_FILE_DIR=${IMAGE_DIR}/${FILEKEY}.png
IR_PNG_FILE=${FILEKEY}_IR.png
IR_PNG_FILE_DIR=${IMAGE_DIR}/${FILEKEY}_IR.png
echo "UPLOADING FILES"
echo ${AUDIO_FILE_DIR}
echo ${IQ_FILE_DIR}
echo ${QPSK_FILE_DIR}
echo ${DEC_FILE_DIR}
echo ${BMP_FILE_DIR}
echo ${IR_BMP_FILE_DIR}
echo ${PNG_FILE_DIR}
echo ${IR_PNG_FILE_DIR}
DATE=`date +%Y-%m-%d`
HOST=$WX_GROUND_FTP_SERVER
USER=$WX_GROUND_FTP_USER
PASSWD=$WX_GROUND_FTP_PASS
# Upload to FTP
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
mkdir $FTP_DIRECTORY
cd $FTP_DIRECTORY
mkdir $SAT_NORM
cd $SAT_NORM
mkdir $DATE
cd $DATE
binary
put $AUDIO_FILE_DIR $AUDIO_FILE
put $IQ_FILE_DIR $IQ_FILE
put $QPSK_FILE_DIR $QPSK_FILE
put $DEC_FILE_DIR $DEC_FILE
put $BMP_FILE_DIR $BMP_FILE
put $IR_BMP_FILE_DIR $IR_BMP_FILE
put $PNG_FILE_DIR $PNG_FILE
put $IR_PNG_FILE_DIR $IR_PNG_FILE
END_SCRIPT
# Send web hook to IFTTT
if [[ "$WX_GROUND_IFTTT_WEBHOOK" != "" && -e $PNG_FILE_DIR ]]; then
IMAGE_URL="${WX_GROUND_FTP_URL}/${FTP_DIRECTORY}/${SAT_NORM}/${DATE}/${FILEKEY}.png"
HUMAN_TIME=`date +%H:%M`
echo "curl -X POST -H \"Content-Type: application/json\" -d '{\"value1\":\"'\"${SAT}\"'\",\"value2\":\"'\"${HUMAN_TIME}\"'\",\"value3\":\"'\"${IMAGE_URL}\"'\"}' ${WX_GROUND_IFTTT_WEBHOOK}"
curl -X POST -H "Content-Type: application/json" -d '{"value1":"'"${SAT}"'","value2":"'"${HUMAN_TIME}"'","value3":"'"${IMAGE_URL}"'"}' ${WX_GROUND_IFTTT_WEBHOOK}
fi
fi
#---
# Upload Data to MySQL Database
#---
# Get data from upcoming_passes.txt
NEXT_PASSES=${WX_GROUND_DIR}/upcoming_passes.txt
PASS_DATA=`grep ${FILEKEY} ${NEXT_PASSES}`
DB_PATH="${SAT_NORM}/${DATE}/"
DB_STATION_ID=1
START_TIME=`echo ${PASS_DATA} | awk '{ print $3 }'`
DB_DATE_OBS=`date --date="TZ=\"UTC\" @${START_TIME}" "+%Y-%m-%d %H:%M:%S" -u`
## Insert into archive-images query
MYSQL_CMD="mysql ${DB_DATABASE} -h ${DB_HOST} -u ${DB_USER} -p${DB_PASS}"
DB_INS_IMG_QUERY="INSERT INTO \`archive-images\`(\`PATH\`, \`FILEKEY\`, \`DATE_OBS\`, \`STATION_ID\`) VALUES (\"${DB_PATH}\", \"${FILEKEY}\", \"${DB_DATE_OBS}\", ${DB_STATION_ID}); SELECT LAST_INSERT_ID();"
INSERT_OUTPUT=`eval ${MYSQL_CMD}<<<"${DB_INS_IMG_QUERY}"`
IMAGE_ID=`echo ${INSERT_OUTPUT} | awk '{print $2}'` # Get ID from insert query
DB_NORAD_ID=`echo ${PASS_DATA} | awk '{ print $9 }'`
DURATION=`echo ${PASS_DATA} | awk '{ print $5 }'`
DB_TLE=`/usr/bin/grep "${SAT}" ${WX_GROUND_DIR}/weather.tle -A 2 | tail -2`
DB_AZI_RISE=`echo ${PASS_DATA} | awk '{ print $6 }'`
DB_AZI_SET=`echo ${PASS_DATA} | awk '{ print $7 }'`
DB_END_EPOCH=`expr ${START_TIME} + ${DURATION}`
ELEVATION=`echo ${PASS_DATA} | awk '{ print $4 }'`
DB_RADIO="Airspy HF+ Discovery"
if [[ "$SAT" == "NOAA 19" || "$SAT" == "NOAA 15" || "$SAT" == "NOAA 18" ]]; then
case "$SAT" in
"NOAA 19")
FREQ="137.1"
;;
"NOAA 18")
FREQ="137.912"
;;
"NOAA 15")
FREQ="137.62"
;;
esac
BANDWIDTH="32000"
DEVIATION="32000"
TRANSPONDER="APT"
CODIFICATION="APT"
DECOD_SOFTWARE="wxtoimg V2.10.11"
fi
if [[ "$SAT" == "METEOR-M 2" ]]; then
FREQ="137.1"
BANDWIDTH="90000"
DEVIATION="NaN"
TRANSPONDER="LRPT 1"
CODIFICATION="LRPT"
DECOD_SOFTWARE="meteor_decode @8021339"
fi
# Insert into archive-images-metadata
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 1, \"${SAT}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 2, \"${DB_NORAD_ID}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 3, \"${FREQ}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 4, \"${TRANSPONDER}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 5, \"${BANDWIDTH}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 6, \"${DEVIATION}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 7, \"${CODIFICATION}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 8, \"${DB_TLE}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 9, \"${DB_DATE_OBS}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 10, \"${DB_AZI_RISE}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 11, \"${DB_AZI_SET}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 12, \"${START_TIME}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 13, \"${DB_END_EPOCH}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 14, \"${DURATION}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 15, \"${ELEVATION}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 17, \"${DECOD_SOFTWARE}\" )"
eval ${MYSQL_CMD}<<<"INSERT INTO \`archive-images-metadata\`(\`IMAGE_ID\`, \`METADATA_ID\`, \`VALUE\`) VALUES (${IMAGE_ID}, 18, \"${DB_RADIO}\" )"