summaryrefslogtreecommitdiff
path: root/check.sh
blob: 48a8f8a0523d5df1b7fb6ea0b3903f0ae7ab1d24 (plain)
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
#!/bin/bash
# Copyright (C) 2014  Michał Masłowski  <mtjm@mtjm.eu>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without any warranty.

# blacklist::check.sh Verify the blacklist entries are correctly formatted.

readonly REF_REGEX='^[^:]*:[^:]*::[^:]*:.*$'
readonly SYNTAX_REGEX='^[^:]*:[^:]*:(sv|debian|parabola|fsf|fedora)?:[^:]*:.*$'
readonly CSV_CHAR=':'
readonly SEP_CHAR='!'

exit_status=0

printf "\n\nchecking for entries without reference to detailed description: ... " >&2
unsourced="$(egrep ${REF_REGEX} *.txt)"
if   [[ -z "$unsourced" ]]
then printf "OK\n" >&2
else printf "\n[citation needed]:\n\n%s\n\n" "$unsourced" >&2
     echo "entries needing citation: $(grep -c '\n' <<<${unsourced})"
     exit_status=1
fi

printf "\n\nchecking for entries with syntax errors: ... " >&2
invalid="$(egrep -v ${SYNTAX_REGEX} *.txt)"
if   [[ -z "$invalid" ]]
then printf "OK\n" >&2
else printf "\n[Incorrectly formatted entries]:\n\n%s\n\n" "$invalid" >&2
     echo "entries improperly formatted: $(grep -c '\n' <<<${invalid})"
     exit_status=1
fi

# TODO: this check could be removed someday - see note in 'sort-entries' script
printf "\n\nchecking for entries that the 'sort-entries' script would mutate: ... " >&2
unsortable="$(grep ${SEP_CHAR} *.txt)"
if   [[ -z "$unsortable" ]]
then printf "OK\n" >&2
else printf "\n[Entries containing '%s' char]:\n\n%s\n\n" "${SEP_CHAR}" "$unsortable" >&2
     echo "entries containing $SEP_CHAR('${SEP_CHAR}'): $(grep -c '\n' <<<${unsortable})"
     exit_status=1
fi

exit $exit_status