-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatafetch.sh
More file actions
executable file
·78 lines (61 loc) · 1.2 KB
/
Copy pathdatafetch.sh
File metadata and controls
executable file
·78 lines (61 loc) · 1.2 KB
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
#!/bin/bash
source "$(dirname $BASH_SOURCE)/uri_parse.sh"
#ARGS src (http,ftp,s3) md5
SRC=$1
DST=$2
EXPECTED_MD5=$3
EXISTS=$(aws s3 ls $DST)
if [ -z "$EXISTS" ]; then
echo "$DST not found"
else
echo "$DST already exists"
exit 0
fi
URI_PATH=$(parse_path $SRC)
RES_NAME=$(basename $URI_PATH)
rm -rf download_box
mkdir download_box
cd download_box
s3_download() {
local SRC=$1
aws s3 sync $SRC ./$RES_NAME
}
s3_pipe(){
echo "Pipe"
local PIPE_DST=$DST/$RES_NAME
#Replace // if any
PIPE_DST=${PIPE_DST/\/\/$RES_NAME/\/$RES_NAME}
aws s3 sync $SRC $PIPE_DST
}
wget_download() {
local SRC=$1
wget $SRC
}
check_md5() {
local ACTUAL_MD5=($(md5sum ./$RES_NAME))
if [ "$ACTUAL_MD5" != "$EXPECTED_MD5" ]; then
echo "MD5 Validation failed"
exit 1
else
echo "MD5 Validation OK"
fi
}
s3_upload() {
local DST=$1
aws s3 sync ./ $DST $AWS_DST_REGION
}
echo $SRC
if [[ $SRC == s3* ]]; then
if [ -z "$EXPECTED_MD5" ]; then
s3_pipe $SRC $DST
exit 0
else
s3_download $SRC
fi
else
wget_download $SRC
fi
if [ -n "$EXPECTED_MD5" ] && [ -f ./$RES_NAME ]; then
check_md5 $EXPECTED_MD5
fi
s3_upload $DST