bin/118114: [patch] update /usr/sbin/manctl
Alex Kozlov
spam at rm-rf.kiev.ua
Sun Nov 18 21:30:01 PST 2007
>Number: 118114
>Category: bin
>Synopsis: [patch] update /usr/sbin/manctl
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon Nov 19 05:30:01 UTC 2007
>Closed-Date:
>Last-Modified:
>Originator: Alex Kozlov
>Release: FreeBSD 6.2
>Organization:
private
>Environment:
>Description:
- after pr115850 was commited is no longer necessary to inline .so includes in man files.
- add 9 to recognized man sections.
- change check order to prevent situation when symlink moved as hardlinks.
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
Index: src/usr.sbin/manctl/manctl.sh
@@ -35,14 +35,11 @@
# manctl:
# a utility for manipulating manual pages
# functions:
-# compress uncompressed man pages (elliminating .so's)
-# this is now two-pass. If possible, .so's
-# are replaced with hard links
+# compress uncompressed man pages
# uncompress compressed man pages
# purge old formatted man pages (not implemented yet)
# Things to watch out for:
# Hard links - careful with g(un)zipping!
-# .so's - throw everything through soelim before gzip!
# symlinks - ignore these - eg: expn is its own man page:
# don't want to compress this!
#
@@ -57,7 +54,6 @@
echo "not implemented yet\n" 2>&1
}
-
#
# Uncompress one page
#
@@ -86,166 +82,36 @@
IFS=" "
case "$ext" in
- gz|Z) {
+ gz|Z)
IFS=" " ; set `file $pname`
- if [ $2 != "gzip" ] ; then
+ if [ $2 = "symbolic" ] ; then
+ # XXX skip symlinks for now
+ # Remove stale symlinks and create
+ # new to uncompressed man page?
+ echo skipping symlink $pname 1>&2
+ elif [ $2 = "gzip" ] ; then
+ echo gunzipping page $pname 1>&2
+ temp=`mktemp -t manager` || exit 1
+ gunzip -c $pname > $temp
+ chmod u+w $pname
+ cp $temp $pname
+ chmod 444 $pname
+ mv $pname $fname.$sect
+ rm -f $temp
+ else
echo moving hard link $pname 1>&2
mv $pname $fname.$ext # link
- else
- if [ $2 != "symbolic" ] ; then
- echo gunzipping page $pname 1>&2
- temp=`mktemp -t manager` || exit 1
- gunzip -c $pname > $temp
- chmod u+w $pname
- cp $temp $pname
- chmod 444 $pname
- mv $pname $fname.$sect
- rm -f $temp
- else
- # skip symlinks - this can be
- # a program like expn, which is
- # its own man page !
- echo skipping symlink $pname 1>&2
- fi
- fi };;
- *) {
- IFS=" "
- echo skipping file $pname 1>&2
- } ;;
- esac
- # reset IFS - this is important!
- IFS=" "
-}
-
-
-#
-# Uncompress manpages in paths
-#
-do_uncompress()
-{
- local i
- local dir
- local workdir
-
- workdir=`pwd`
- while [ $# != 0 ] ; do
- if [ -d $1 ] ; then
- dir=$1
- cd $dir
- for i in * ; do
- case $i in
- *cat?) ;; # ignore cat directories
- *) {
- if [ -d $i ] ; then
- do_uncompress $i
- else
- if [ -e $i ] ; then
- uncompress_page $i
- fi
- fi } ;;
- esac
- done
- cd $workdir
- else
- echo "directory $1 not found" 1>&2
fi
- shift
- done
-}
-
-#
-# Remove .so's from one file
-#
-so_purge_page()
-{
- local so_entries
- local lines
- local fname
-
- so_entries=`grep "^\.so" $1 | wc -l`
- if [ $so_entries -eq 0 ] ; then return 0 ; fi
-
- # we have a page with a .so in it
- echo $1 contains a .so entry 2>&1
-
- # now check how many lines in the file
- lines=`wc -l < $1`
-
- # if the file is only one line long, we can replace it
- # with a hard link!
- if [ $lines -eq 1 ] ; then
- fname=$1;
- echo replacing $fname with a hard link
- set `cat $fname`;
- rm -f $fname
- ln ../$2 $fname
- else
- echo inlining page $fname 1>&2
- temp=`mktemp -t manager` || exit 1
- cat $fname | \
- (cd .. ; soelim ) > $temp
- chmod u+w $fname
- cp $temp $fname
- chmod 444 $fname
- rm -f $temp
- fi
-}
-
-#
-# Remove .so entries from man pages
-# If a page consists of just one line with a .so,
-# replace it with a hard link
-#
-remove_so()
-{
- local pname
- local fname
- local sect
-
- # break up file name
- pname=$1
- IFS='.' ; set $pname
- if [ $# -lt 2 ] ; then
- IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
- fi
- # construct name and section
- fname=$1 ; shift
- while [ $# -gt 1 ] ; do
- fname=$fname.$1
- shift
- done
- sect=$1
-
- IFS=" "
- case "$sect" in
- gz) { echo file $pname already gzipped 1>&2 ; } ;;
- Z) { echo file $pname already compressed 1>&2 ; } ;;
- [12345678ln]*){
- IFS=" " ; set `file $pname`
- if [ $2 = "gzip" ] ; then
- echo moving hard link $pname 1>&2
- mv $pname $pname.gz # link
- else
- if [ $2 != "symbolic" ] ; then
- echo "removing .so's in page $pname" 1>&2
- so_purge_page $pname
- else
- # skip symlink - this can be
- # a program like expn, which is
- # its own man page !
- echo skipping symlink $pname 1>&2
- fi
- fi };;
- *) {
+ ;;
+ *)
IFS=" "
echo skipping file $pname 1>&2
- } ;;
+ ;;
esac
# reset IFS - this is important!
IFS=" "
}
-
#
# compress one page
# We need to watch out for hard links here.
@@ -272,44 +138,42 @@
IFS=" "
case "$sect" in
- gz) { echo file $pname already gzipped 1>&2 ; } ;;
- Z) { echo file $pname already compressed 1>&2 ; } ;;
- [12345678ln]*){
+ gz) echo file $pname already gzipped 1>&2 ;;
+ Z) echo file $pname already compressed 1>&2 ;;
+ [123456789ln]*)
IFS=" " ; set `file $pname`
- if [ $2 = "gzip" ] ; then
+ if [ $2 = "symbolic" ] ; then
+ # XXX skip symlinks for now
+ # Remove stale symlinks and create
+ # new to compressed man page?
+ echo skipping symlink $pname 1>&2
+ elif [ $2 != "gzip" ] ; then
+ echo gzipping page $pname 1>&2
+ temp=`mktemp -t manager` || exit 1
+ cat $pname | gzip -c -- > $temp
+ chmod u+w $pname
+ cp $temp $pname
+ chmod 444 $pname
+ mv $pname $pname.gz
+ rm -f $temp
+ else
echo moving hard link $pname 1>&2
mv $pname $pname.gz # link
- else
- if [ $2 != "symbolic" ] ; then
- echo gzipping page $pname 1>&2
- temp=`mktemp -t manager` || exit 1
- cat $pname | \
- (cd .. ; soelim )| gzip -c -- > $temp
- chmod u+w $pname
- cp $temp $pname
- chmod 444 $pname
- mv $pname $pname.gz
- rm -f $temp
- else
- # skip symlink - this can be
- # a program like expn, which is
- # its own man page !
- echo skipping symlink $pname 1>&2
- fi
- fi };;
- *) {
+ fi
+ ;;
+ *)
IFS=" "
echo skipping file $pname 1>&2
- } ;;
+ ;;
esac
# reset IFS - this is important!
IFS=" "
}
#
-# Compress man pages in paths
+# Compress/Uncompress man pages in paths
#
-do_compress_so()
+do_walkdir()
{
local i
local dir
@@ -322,21 +186,20 @@
while [ $# != 0 ] ; do
if [ -d $1 ] ; then
dir=$1
- cd $dir
+ cd $dir || continue
for i in * ; do
case $i in
*cat?) ;; # ignore cat directories
- *) {
+ *)
if [ -d $i ] ; then
- do_compress_so $what $i
- else
- if [ -e $i ] ; then
- $what $i
- fi
- fi } ;;
+ do_walkdir $what $i
+ elif [ -e $i ] ; then
+ $what $i
+ fi
+ ;;
esac
done
- cd $workdir
+ cd $workdir || { echo "cannot chdir to $workdir" 1>&2 ; exit 1 ; }
else
echo "directory $1 not found" 1>&2
fi
@@ -357,24 +220,13 @@
}
#
-# remove .so's and do compress
-#
-do_compress()
-{
- # First remove all so's from the pages to be compressed
- do_compress_so remove_so "$@"
- # now do ahead and compress the pages
- do_compress_so compress_page "$@"
-}
-
-#
# dispatch options
#
if [ $# -lt 2 ] ; then ctl_usage $0 ; fi ;
case "$1" in
- -compress) shift ; do_compress "$@" ;;
- -uncompress) shift ; do_uncompress "$@" ;;
+ -compress) shift ; do_walkdir compress_page "$@" ;;
+ -uncompress) shift ; do_walkdir uncompress_page "$@" ;;
-purge) shift ; do_purge "$@" ;;
*) ctl_usage $0 ;;
esac
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list