-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·46 lines (35 loc) · 936 Bytes
/
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
#!/bin/bash
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "" ]
then
echo "Usage: FILEPATH METHODNAME USERNAME SECRETKEY [FILENAME]"
else
FILEPATH=$1
METHODNAME=$2
USERNAME=$3
SECRETKEY=$4
FILENAME=$5
URL=https://datalakecadg.mprj.mp.br/api/upload/
TMPNAME=/tmp/$(uuidgen)
echo "Compressing file...\n"
gzip -c -k $FILEPATH > $TMPNAME
echo "Calculating MD5 checksum...\n"
MD5=$(md5sum $TMPNAME | cut -d ' ' -f 1)
if [ "$FILENAME" == "" ]
then
BASENAME=$(basename $FILEPATH)
FILENAME=$(echo "$BASENAME" | sed "s/.csv/_$(date +'%Y%m%d%H%M%S.csv.gz')/")
fi
echo "Sending file..."
#SEND DATA
curl -X POST \
$URL \
-F SECRET=$SECRETKEY \
-F nome=$USERNAME \
-F filename=$FILENAME \
-F method=$METHODNAME \
-F md5=$MD5 \
-F file=@$TMPNAME
echo "\n"
echo "Removing temporary file $TMPNAME"
rm $TMPNAME
fi