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
|
#!/usr/bin/env bash
SUBDIRS=(static/openbsd static/netbsd static/freebsd)
create() {
sqlite3 man.db <<EOF
CREATE TABLE manpages (
os TEXT,
name TEXT,
section INTEGER,
path TEXT,
PRIMARY KEY (os, name, section)
);
EOF
if [[ $? != 0 ]];
then
printf "Error: error creating table.\n" >&2
exit 1
fi
for SUBDIR in ${SUBDIRS[*]};
do
make -j "$(nproc)" -C "$SUBDIR"
if [[ $? != 0 ]];
then
printf "Error: error building %s man pages.\n" "$SUBDIR" >&2
exit 1
fi
HTML=$(find "$SUBDIR" -type f -name '*.html')
for FILE in $HTML;
do
SECTION=$(basename "$FILE" | sed -E 's|.*\.([0-9])\..*|\1|')
NAME=$(basename "$FILE" | sed -E 's|(.*)\.[0-9]\.html|\1|')
OS=$(basename "$SUBDIR")
if [[ -n "$(echo "$FILE" | grep "man$SECTION\.")" ]];
then
NAME="$(echo "$FILE" | sed -E "s|.*man$SECTION\.(.*)/.*|\1|" ).$NAME"
fi
echo "INSERT INTO manpages (os, name, section, path) VALUES ('"$OS"', '"$NAME"', '"$SECTION"', '"$FILE"');"
sqlite3 man.db \
"INSERT INTO manpages (os, name, section, path) VALUES ('"$OS"', '"$NAME"', '"$SECTION"', '"$FILE"');"
if [[ $? != 0 ]];
then
printf "Error: error inserting ('%s', '%s', '%s', '%s').\n" "$OS" "$NAME" "$SECTION" "$FILE" >&2
exit 1
fi
done
done
}
clean() {
for SUBDIR in ${SUBDIRS[*]};
do
make -C "$SUBDIR" -j "$(nproc)" clean
done
rm -f man.db
}
case "$1" in
create)
create
;;
clean)
clean
;;
*)
printf "Error: \"%s\" not an option.\n" "$1"
exit 1
;;
esac
|