-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdpkg-docreport.sh
executable file
·164 lines (143 loc) · 3.59 KB
/
dpkg-docreport.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash --posix
# create html index to package documentation
############################################################################
# Copyright (C) 2007 Lawrence Livermore National Security, LLC
# Produced at Lawrence Livermore National Laboratory.
# Written by Jim Garlick <garlick@llnl.gov>.
# UCRL-CODE-235516
#
# This file is part of dpkg-scripts, a set of utilities for managing
# packages in /usr/local with dpkg.
#
# dpkg-scripts is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# dpkg-scripts is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with dpkg-scripts; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
############################################################################
declare -r prog=dpkg-docreport
declare -r dpkgroot=/usr/local
declare -r infodir=${dpkgroot}/dpkg-db/info
declare -r docsummary=${dpkgroot}/dpkg-db/doc.html
die()
{
echo "${prog}: $1" >&2
exit 1
}
get_arch()
{
dpkg-architecture | grep DEB_BUILD_ARCH= | cut -d= -f2
}
emit_opening()
{
cat <<EOT
<html>
<head>
<title> packages installed in /usr/local</title>
</head>
<body>
<h2> Packages Installed in /usr/local</h2>
Report generated $(date)
<table cellspacing="0" cellpadding="0" border="1">
<thead>
<tr>
<th>Package</th>
<th>Description</th>
<th>Web docs</th>
<th>Man</th>
<th>Info</th>
<th>Dotkit</th>
</tr>
</thead>
<tbody>
EOT
}
emit_closing()
{
cat <<EOT2
</tbody>
</table>
</body>
</html>
EOT2
}
# Turn doc entries formatted thus:
# "Description maybe with spaces: /full/path/to/file"
# into html on stdout.
doc2html()
{
local docfile=${infodir}/$1.doc
if [ -r ${docfile} ]; then
sed 's/\([^:]*\):[ \t]*\(.*\)$/<a href="file:\/\/\2">\1<\/a><br>/' ${docfile}
fi
}
man_yn()
{
if dpkg -L $1 | grep /man/ >/dev/null; then
echo 'Y'
else
echo 'N'
fi
}
texi_yn()
{
if dpkg -L $1 | grep /info/ >/dev/null; then
echo 'Y'
else
echo 'N'
fi
}
dotkit_yn()
{
if [ -f ${infodir}/$1.dk ]; then
echo 'Y'
else
echo 'N'
fi
}
rowcounter=0
emit_row()
{
local pkg=$1
local desc=$(dpkg-query --show --showformat '${Description}' $pkg)
local vers=$(dpkg-query --showformat '${version}' --show ${pkg})
if [ ${rowcounter} = 0 ]; then
rowcounter=1
echo '<tr>'
else
rowcounter=0
#echo '<tr class="greenbar">'
echo '<tr bgcolor="#CCCCCC">'
fi
echo '<th><p>'${pkg}-${vers}'</p></th>'
echo '<td>'${desc}'</td>'
echo "<td>$(doc2html ${pkg})</td>"
echo "<td>$(man_yn ${pkg})</td>"
echo "<td>$(texi_yn ${pkg})</td>"
echo "<td>$(dotkit_yn ${pkg})</td>"
echo '</tr>'
}
if [ $# -gt 0 ]; then
echo "Usage: ${prog}" >&2
exit 1
fi
[ $(id -u) != 0 ] && die "you must make docreport as superuser"
umask 022
if ! echo $PATH | grep -q ${dpkgroot}/bin; then
PATH=$PATH:${dpkgroot}/bin
fi
emit_opening >${docsummary}
for package in $(dpkg-query --show --showformat '${package}\n'); do
emit_row ${package} >>${docsummary}
done
emit_closing >>${docsummary}
exit 0
# vi: expandtab sw=4 ts=4