Debian Codegraph @

src/update-ietf-documents

raw
1 #!/usr/bin/env bash
2 #
3 # Update BibTeX entries for IETF documents (RFCs and Internet Drafts)
4 # Copyright (C) 2014-2026 by Thomas Dreibholz
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Contact: [email protected]
20 #
21
22 REFERENCES=~/src/papers/Referenzarchiv.bib
23 DOCUMENTS="$(grep -E "^@[a-zA-Z]*{[ \t].*,.*$" "${REFERENCES}" | sed -e "s/,//g" | awk '{ print $2; }' | grep -E "^RFC|^draft")"
24 UPDATES_FILE="updated.bib"
25 RESULTS_FILE="results.bib"
26 PARALLEL=16
27
28 BIBTEXCONV_OPTIONS="--check-urls"
29 IETF2BIBTEX_OPTIONS="--quiet"
30
31 if [ "$1" == "--test" ] ; then
32 BIBTEXCONV_OPTIONS="" # Do no check URLs
33 IETF2BIBTEX_OPTIONS="" # Verbose mode
34 echo "!!! Test Mode !!!"
35 fi
36
37 echo "Step 1: Fetching metadata ..."
38 echo "${DOCUMENTS}" | (
39 while read -r name ; do
40 rm -f "${name}".bib
41 if [[ "${name}" =~ ^(RFC[0-9]+$)|(draft-[a-z].*$) ]] ; then
42 # echo >&2 "Processing ${name} ..."
43 echo "./ietf2bibtex ${IETF2BIBTEX_OPTIONS} \"${name}\" >${name}.bib"
44 else
45 echo >&2 "Skipping ${name}"
46 fi
47 done
48 ) | parallel -j${PARALLEL}
49 wait
50
51
52 echo "Step 2: Fetching documents ..."
53 echo "${DOCUMENTS}" | (
54 while read -r name ; do
55 if [ -e "${name}".bib ] ; then
56 if [ "$(stat --format="%s" "${name}".bib)" != "0" ] ; then
57 echo "./bibtexconv ${name}.bib --export-to-bibtex ${name}.bib2 ${BIBTEXCONV_OPTIONS} --only-check-new-urls --non-interactive || echo \"ERROR: ${name}.bib seems to be invalid!\""
58 else
59 echo >&2 "NOTE: Removing empty file ${name}.bib"
60 rm -f "${name}".bib
61 fi
62 fi
63 done
64 ) | parallel -j${PARALLEL}
65 wait
66
67
68 echo "Step 3: Collecting results ..."
69 (
70 cat "${REFERENCES}"
71 echo "${DOCUMENTS}" | (
72 while read -r name ; do
73 if [ -e "${name}".bib2 ] ; then
74 cat "${name}".bib2
75 fi
76 rm -f "${name}".bib "${name}".bib2
77 done
78 )
79 ) >"${UPDATES_FILE}"
80 ./bibtexconv "${UPDATES_FILE}" --export-to-bibtex "${RESULTS_FILE}" --non-interactive
81 echo "Done."
82
83
84 echo "Step 4: Showing differences (${REFERENCES} ${RESULTS_FILE}) ..."
85 ls -l "${REFERENCES}" "${RESULTS_FILE}"
86 diff "${REFERENCES}" "${RESULTS_FILE}" | grep -v url.checked | grep -v -E '^[[:alnum:]]+' | grep -v "^---$"| grep -v "[ \t]*url[.a-z0-9]* ="
87 diff --color ${REFERENCES} "${RESULTS_FILE}" |grep author|grep -B1 '>'