-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.sh
55 lines (48 loc) · 1.29 KB
/
build.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
#!/bin/bash
download() {
curl -LO 'http://standards-oui.ieee.org/oui/oui.csv'
curl -LO 'http://standards-oui.ieee.org/oui28/mam.csv'
curl -LO 'http://standards-oui.ieee.org/oui36/oui36.csv'
}
merge_csv() {
for file in mam.csv oui36.csv; do
sed -i '1d' "$file"
done
cat oui.csv mam.csv oui36.csv >mac.csv
rm oui.csv mam.csv oui36.csv
}
build_sqlite() {
dbfile='mac.db'
table='mac'
rm "$dbfile"
sqlite3 "$dbfile" <<_EOF
CREATE TABLE $table (
registry TEXT,
assignment TEXT COLLATE NOCASE,
organization_name TEXT,
organization_address TEXT
);
CREATE INDEX assignment_index ON $table (assignment);
_EOF
# 运行器上 sqlite3 版本不支持以下命令
# sqlite3 "$dbfile" ".import --csv --skip 1 'mac.csv' $table"
sqlite3 -csv "$dbfile" ".import 'mac.csv' $table"
}
check_to_commit() {
if ! sha256sum -c sha256sum.txt; then
sha256sum mac.csv mac.db >sha256sum.txt
git config user.name 'WH-2099 CI/CD'
git config user.email '[email protected]'
git add sha256sum.txt mac.csv mac.db
git commit -m "CI/CD Auto Update"
git push
fi
}
main() {
# set -x
download
merge_csv
build_sqlite
check_to_commit
}
main