-
Notifications
You must be signed in to change notification settings - Fork 36
/
fetch-updates.sh
executable file
·82 lines (72 loc) · 1.87 KB
/
fetch-updates.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
#!/bin/bash
display_usage() {
echo "This script fetch update, create dump and diffs as json files."
echo -e "\nUsage: $0 \n"
}
DO_DATA_UPDATE=1
DO_PUSH=0
GIT_USERNAME=${GIT_USERNAME:-}
GIT_PASSWORD=${GIT_PASSWORD:-}
GIT_ORIGIN="origin"
while (( "$#" )); do
case "$1" in
-n|--no-data-update)
DO_DATA_UPDATE=0
shift
;;
-p|--push-data)
DO_PUSH=1
shift
;;
-u|--username)
echo "Username: $2"
GIT_USERNAME=$2
shift
shift
;;
-w|--password)
echo "password: $2"
GIT_PASSWORD=$2
shift
shift
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
display_usage
exit 1
;;
*)
display_usage
exit 1
;;
esac
done
[[ ${GIT_USERNAME} -ne "" && ${GIT_PASSWORD} -ne "" ]] && {
GIT_ORIGIN="https://${GIT_USERNAME}:${GIT_USERNAME}@github.com/Patrowl/PatrowlHearsData"
}
start_time="$(date -u +%s)"
echo "[+] Started at $start_time"
current_date=$(python3 -c 'from datetime import datetime as dt; print(dt.today().strftime("%Y-%m-%d"))')
current_datetime=$(python3 -c 'from datetime import datetime as dt; print(dt.today().strftime("%Y-%m-%d %H:%M:%S"))')
echo "[+] Pull latest updates from Github"
git pull
[ $DO_DATA_UPDATE -eq 1 ] && {
env/bin/python CWE/fetch-and-update.py
env/bin/python CPE/fetch-and-update.py
env/bin/python CVE/fetch-and-update.py
env/bin/python VIA/fetch-and-update.py
env/bin/python EPSS/fetch-and-update.py
env/bin/python KEV/fetch-and-update.py
}
echo "${current_datetime}" > lastupdate.txt
[ $DO_PUSH -eq 1 ] && {
git add .
git commit -m "data-update-${current_datetime}"
# git push origin :refs/tags/$current_date
git push ${GIT_ORIGIN} :refs/tags/$current_date
git tag -f $current_date
git push && git push --tags
}
end_time="$(date -u +%s)"
elapsed="$(($end_time-$start_time))"
echo "Total of $elapsed seconds elapsed"