manctl.sh revision 1369
1#!/bin/sh 2# 3# Copyright (c) 1994 Geoffrey M. Rehmet, Rhodes University 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 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. 20# 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 31# SUCH DAMAGE. 32# 33# $Id: manctl,v 1.3 1994/04/17 21:01:18 g89r4222 Exp $ 34# 35# manctl: 36# a utility for manipulating manual pages 37# functions: 38# compress uncompressed man pages (elliminating .so's) 39# uncompress compressed man pages 40# purge old formatted man pages (not implemented yet) 41# Things to watch out for: 42# Hard links - careful with g(un)zipping! 43# .so's - throw everything through soelim before gzip! 44# symlinks - ignore these - eg: expn is its own man page: 45# don't want to compress this! 46# 47PATH=/bin:/sbin:/usr/bin:/usr/sbin 48 49# 50# purge cat? directories 51# 52do_purge() 53{ 54 echo "purge $@" 2>&1 55 echo "not implemented yet\n" 2>&1 56} 57 58 59# 60# Uncompress one page 61# 62uncompress_page() 63{ 64 local pname 65 local fname 66 local sect 67 local ext 68 69 # break up file name 70 pname=$1 71 IFS='.' ; set $pname 72 # less than 3 fields - don't know what to do with this 73 if [ $# -lt 3 ] ; then 74 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ; 75 fi 76 # construct name and section 77 fname=$1 ; shift 78 while [ $# -gt 2 ] ; do 79 fname=$fname.$1 80 shift 81 done 82 sect=$1 83 ext=$2 84 85 IFS=" " 86 case "$ext" in 87 gz|Z) { 88 IFS=" " ; set `file $pname` 89 if [ $2 != "gzip" ] ; then 90 echo moving hard link $pname 1>&2 91 mv $pname $fname.$ext # link 92 else 93 if [ $2 != "symbolic" ] ; then 94 echo gunzipping page $pname 1>&2 95 gunzip -c $pname > /tmp/manager.$$ 96 chmod u+w $pname 97 cp /tmp/manager.$$ $pname 98 chmod 444 $pname 99 mv $pname $fname.$sect 100 rm /tmp/manager.$$ 101 else 102 # skip symlinks - this can be 103 # a program like expn, which is 104 # its own man page ! 105 echo skipping symlink $pname 1>&2 106 fi 107 fi };; 108 *) { 109 IFS=" " 110 echo skipping file $pname 1>&2 111 } ;; 112 esac 113 # reset IFS - this is important! 114 IFS=" " 115} 116 117 118# 119# Uncompress manpages in paths 120# 121do_uncompress() 122{ 123 local i 124 local dir 125 local workdir 126 127 workdir=`pwd` 128 while [ $# != 0 ] ; do 129 if [ -d $1 ] ; then 130 dir=$1 131 cd $dir 132 for i in $dir/* ; do 133 case $i in 134 *cat?) ;; # ignore cat directories 135 *) { 136 if [ -d $i ] ; then 137 do_uncompress $i 138 else 139 if [ -e $i ] ; then 140 uncompress_page $i 141 fi 142 fi } ;; 143 esac 144 done 145 cd $workdir 146 else 147 echo "directory $1 not found" 1>&2 148 fi 149 shift 150 done 151} 152 153# 154# compress one page 155# We need to watch out for hard links here. 156# 157compress_page() 158{ 159 local pname 160 local fname 161 local sect 162 163 # break up file name 164 pname=$1 165 IFS='.' ; set $pname 166 if [ $# -lt 2 ] ; then 167 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ; 168 fi 169 # construct name and section 170 fname=$1 ; shift 171 while [ $# -gt 1 ] ; do 172 fname=$fname.$1 173 shift 174 done 175 sect=$1 176 177 IFS=" " 178 case "$sect" in 179 gz) { echo file $pname already gzipped 1>&2 ; } ;; 180 Z) { echo file $pname already compressed 1>&2 ; } ;; 181 [12345678ln]*){ 182 IFS=" " ; set `file $pname` 183 if [ $2 = "gzip" ] ; then 184 echo moving hard link $pname 1>&2 185 mv $pname $pname.gz # link 186 else 187 if [ $2 != "symbolic" ] ; then 188 echo gzipping page $pname 1>&2 189 soelim $pname | gzip -c -- > /tmp/manager.$$ 190 chmod u+w $pname 191 cp /tmp/manager.$$ $pname 192 chmod 444 $pname 193 mv $pname $pname.gz 194 rm /tmp/manager.$$ 195 else 196 # skip symlink - this can be 197 # a program like expn, which is 198 # its own man page ! 199 echo skipping symlink $pname 1>&2 200 fi 201 fi };; 202 *) { 203 IFS=" " 204 echo skipping file $pname 1>&2 205 } ;; 206 esac 207 # reset IFS - this is important! 208 IFS=" " 209} 210 211# 212# Compress man pages in paths 213# 214do_compress() 215{ 216 local i 217 local dir 218 local workdir 219 220 workdir=`pwd` 221 while [ $# != 0 ] ; do 222 if [ -d $1 ] ; then 223 dir=$1 224 cd $dir 225 for i in * ; do 226 case $i in 227 *cat?) ;; # ignore cat directories 228 *) { 229 if [ -d $i ] ; then 230 do_compress $i 231 else 232 if [ -e $i ] ; then 233 compress_page $i 234 fi 235 fi } ;; 236 esac 237 done 238 cd $workdir 239 else 240 echo "directory $1 not found" 1>&2 241 fi 242 shift 243 done 244} 245 246# 247# Display a usage message 248# 249ctl_usage() 250{ 251 echo "usage : $1 -compress <path> ... " 1>&2 252 echo " $1 -uncompress <path> ... " 1>&2 253 echo " $1 -purge <days> <path> ... " 1>&2 254 echo " $1 -purge expire <path> ... " 1>&2 255 exit 1 256} 257 258 259# 260# dispatch options 261# 262if [ $# = 0 ] ; then ; ctl_usage $0 ; fi ; 263 264case "$1" in 265 -compress) shift ; do_compress "$@" ;; 266 -uncompress) shift ; do_uncompress "$@" ;; 267 -purge) shift ; do_purge "$@" ;; 268 *) ctl_usage $0 ;; 269esac 270