3 # Copyright (c) 1994 Geoffrey M. Rehmet, Rhodes University
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. All advertising materials mentioning features or use of this software
15 # must display the following acknowledgement:
16 # This product includes software developed by Geoffrey M. Rehmet
17 # 4. Neither the name of Geoffrey M. Rehmet nor that of Rhodes University
18 # may be used to endorse or promote products derived from this software
19 # without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 # IN NO EVENT SHALL GEOFFREY M. REHMET OR RHODES UNIVERSITY BE LIABLE
25 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 # $FreeBSD: src/usr.sbin/manctl/manctl.sh,v 1.11.2.1 2001/02/05 13:53:03 jedgar Exp $
34 # $DragonFly: src/usr.sbin/manctl/manctl.sh,v 1.2 2003/06/17 04:29:57 dillon Exp $
37 # a utility for manipulating manual pages
39 # compress uncompressed man pages (elliminating .so's)
40 # this is now two-pass. If possible, .so's
41 # are replaced with hard links
42 # uncompress compressed man pages
43 # purge old formatted man pages (not implemented yet)
44 # Things to watch out for:
45 # Hard links - careful with g(un)zipping!
46 # .so's - throw everything through soelim before gzip!
47 # symlinks - ignore these - eg: expn is its own man page:
48 # don't want to compress this!
50 PATH
=/bin
:/sbin
:/usr
/bin
:/usr
/sbin
; export PATH
53 # purge cat? directories
58 echo "not implemented yet\n" 2>&1
75 # less than 3 fields - don't know what to do with this
76 if [ $# -lt 3 ] ; then
77 IFS
=" " ; echo ignoring
$pname 1>&2 ; return 0 ;
79 # construct name and section
81 while [ $# -gt 2 ] ; do
91 IFS
=" " ; set `file $pname`
92 if [ $2 != "gzip" ] ; then
93 echo moving hard link
$pname 1>&2
94 mv $pname $fname.
$ext # link
96 if [ $2 != "symbolic" ] ; then
97 echo gunzipping page
$pname 1>&2
98 temp
=`mktemp -t manager` ||
exit 1
99 gunzip
-c $pname > $temp
103 mv $pname $fname.
$sect
106 # skip symlinks - this can be
107 # a program like expn, which is
109 echo skipping symlink
$pname 1>&2
114 echo skipping
file $pname 1>&2
117 # reset IFS - this is important!
123 # Uncompress manpages in paths
132 while [ $# != 0 ] ; do
138 *cat?
) ;; # ignore cat directories
151 echo "directory $1 not found" 1>&2
158 # Remove .so's from one file
166 so_entries
=`grep "^\.so" $1 | wc -l`
167 if [ $so_entries -eq 0 ] ; then return 0 ; fi
169 # we have a page with a .so in it
170 echo $1 contains a .so entry
2>&1
172 # now check how many lines in the file
175 # if the file is only one line long, we can replace it
177 if [ $lines -eq 1 ] ; then
179 echo replacing
$fname with a hard link
184 echo inlining page
$fname 1>&2
185 temp
=`mktemp -t manager` ||
exit 1
187 (cd ..
; soelim
) > $temp
196 # Remove .so entries from man pages
197 # If a page consists of just one line with a .so,
198 # replace it with a hard link
209 if [ $# -lt 2 ] ; then
210 IFS
=" " ; echo ignoring
$pname 1>&2 ; return 0 ;
212 # construct name and section
214 while [ $# -gt 1 ] ; do
222 gz
) { echo file $pname already gzipped
1>&2 ; } ;;
223 Z
) { echo file $pname already compressed
1>&2 ; } ;;
225 IFS
=" " ; set `file $pname`
226 if [ $2 = "gzip" ] ; then
227 echo moving hard link
$pname 1>&2
228 mv $pname $pname.gz
# link
230 if [ $2 != "symbolic" ] ; then
231 echo "removing .so's in page $pname" 1>&2
234 # skip symlink - this can be
235 # a program like expn, which is
237 echo skipping symlink
$pname 1>&2
242 echo skipping
file $pname 1>&2
245 # reset IFS - this is important!
252 # We need to watch out for hard links here.
263 if [ $# -lt 2 ] ; then
264 IFS
=" " ; echo ignoring
$pname 1>&2 ; return 0 ;
266 # construct name and section
268 while [ $# -gt 1 ] ; do
276 gz
) { echo file $pname already gzipped
1>&2 ; } ;;
277 Z
) { echo file $pname already compressed
1>&2 ; } ;;
279 IFS
=" " ; set `file $pname`
280 if [ $2 = "gzip" ] ; then
281 echo moving hard link
$pname 1>&2
282 mv $pname $pname.gz
# link
284 if [ $2 != "symbolic" ] ; then
285 echo gzipping page
$pname 1>&2
286 temp
=`mktemp -t manager` ||
exit 1
288 (cd ..
; soelim
)|
gzip -c -- > $temp
295 # skip symlink - this can be
296 # a program like expn, which is
298 echo skipping symlink
$pname 1>&2
303 echo skipping
file $pname 1>&2
306 # reset IFS - this is important!
311 # Compress man pages in paths
323 while [ $# != 0 ] ; do
329 *cat?
) ;; # ignore cat directories
332 do_compress_so
$what $i
342 echo "directory $1 not found" 1>&2
349 # Display a usage message
353 echo "usage: $1 -compress <path> ... " 1>&2
354 echo " $1 -uncompress <path> ... " 1>&2
355 echo " $1 -purge <days> <path> ... " 1>&2
356 echo " $1 -purge expire <path> ... " 1>&2
361 # remove .so's and do compress
365 # First remove all so's from the pages to be compressed
366 do_compress_so remove_so
"$@"
367 # now do ahead and compress the pages
368 do_compress_so compress_page
"$@"
374 if [ $# -lt 2 ] ; then ctl_usage
$0 ; fi ;
377 -compress) shift ; do_compress
"$@" ;;
378 -uncompress) shift ; do_uncompress
"$@" ;;
379 -purge) shift ; do_purge
"$@" ;;