-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate.sh
79 lines (66 loc) · 1.4 KB
/
update.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
# File Updater
# Copyright © 2022 Stewart Cossey
# Version: 1.3
. ./library.sh
file_env "INTERVAL" 0
file_env "URL1"
file_env "OUTPUTPATH" "/fileoutput"
file_env "IGNORESSL"
file_env "CACERT"
file_env "BEGIN" dfmt=%H%M
validate_env "URL1" req
validate_env "IGNORESSL" bool
log "Output path is $OUTPUTPATH"
CPARA=""
if [ "$IGNORESSL" = "true" ]; then
CPARA=(-k)
log "Ignore invalid SSL certificates"
else
if [ -n "$CACERT" ]; then
log "Use certificate authority ${CACERT}"
CPARA=(--cacert ${CACERT})
fi
fi
if [ ! -d "$OUTPUTPATH" ]; then
mkdir -p "$OUTPUTPATH"
fi
cd $OUTPUTPATH
if [ -z "$BEGIN" ]; then
log "Waiting to begin, Start at $BEGIN"
while [ "$(date +"%H%M")" != "$BEGIN" ]; do
sleep "5s"
done
fi
log "-----------------------------------"
while :; do
time {
TIMEFORMAT=$(log "Completed in %R seconds")
c=1
while :; do
URLVAL=URL$c
NAMEVAL=NAME$c
file_env $URLVAL
file_env $NAMEVAL
if [ -z "${!URLVAL}" ]; then
break
fi
log "Download ${!URLVAL}"
time {
if [ -z "${!NAMEVAL}" ]; then
curl -sS ${CPARA[@]} "${!URLVAL}" --remote-name
else
curl -sS ${CPARA[@]} "${!URLVAL}" --output ${!NAMEVAL}
fi
}
((c++))
done
log "-----------------------------------"
TIMEFORMAT=$(log "Cycle took %R seconds to complete")
}
log "-----------------------------------"
if [ $INTERVAL -eq 0 ]; then
break
else
sleep "${INTERVAL}m"
fi
done