manctl.sh revision 1366
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 126 while [ $# != 0 ] ; do 127 if [ -d $1 ] ; then 128 dir=$1 129 for i in $dir/* ; do 130 case $i in 131 *cat?) ;; # ignore cat directories 132 *) { 133 if [ -d $i ] ; then 134 do_uncompress $i 135 else 136 if [ -e $i ] ; then 137 uncompress_page $i 138 fi 139 fi } ;; 140 esac 141 done 142 else 143 echo "directory $1 not found" 1>&2 144 fi 145 shift 146 done 147} 148 149# 150# compress one page 151# We need to watch out for hard links here. 152# 153compress_page() 154{ 155 local pname 156 local fname 157 local sect 158 159 # break up file name 160 pname=$1 161 IFS='.' ; set $pname 162 if [ $# -lt 2 ] ; then 163 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ; 164 fi 165 # construct name and section 166 fname=$1 ; shift 167 while [ $# -gt 1 ] ; do 168 fname=$fname.$1 169 shift 170 done 171 sect=$1 172 173 IFS=" " 174 case "$sect" in 175 gz) { echo file $pname already gzipped 1>&2 ; } ;; 176 Z) { echo file $pname already compressed 1>&2 ; } ;; 177 [12345678ln]*){ 178 IFS=" " ; set `file $pname` 179 if [ $2 = "gzip" ] ; then 180 echo moving hard link $pname 1>&2 181 mv $pname $pname.gz # link 182 else 183 if [ $2 != "symbolic" ] ; then 184 echo gzipping page $pname 1>&2 185 soelim $pname | gzip -c -- > /tmp/manager.$$ 186 chmod u+w $pname 187 cp /tmp/manager.$$ $pname 188 chmod 444 $pname 189 mv $pname $pname.gz 190 rm /tmp/manager.$$ 191 else 192 # skip symlink - this can be 193 # a program like expn, which is 194 # its own man page ! 195 echo skipping symlink $pname 1>&2 196 fi 197 fi };; 198 *) { 199 IFS=" " 200 echo skipping file $pname 1>&2 201 } ;; 202 esac 203 # reset IFS - this is important! 204 IFS=" " 205} 206 207# 208# Compress man pages in paths 209# 210do_compress() 211{ 212 local i 213 local dir 214 215 while [ $# != 0 ] ; do 216 if [ -d $1 ] ; then 217 dir=$1 218 for i in $dir/* ; do 219 case $i in 220 *cat?) ;; # ignore cat directories 221 *) { 222 if [ -d $i ] ; then 223 do_compress $i 224 else 225 if [ -e $i ] ; then 226 compress_page $i 227 fi 228 fi } ;; 229 esac 230 done 231 else 232 echo "directory $1 not found" 1>&2 233 fi 234 shift 235 done 236} 237 238# 239# Display a usage message 240# 241ctl_usage() 242{ 243 echo "usage : $1 -compress <path> ... " 1>&2 244 echo " $1 -uncompress <path> ... " 1>&2 245 echo " $1 -purge <days> <path> ... " 1>&2 246 echo " $1 -purge expire <path> ... " 1>&2 247 exit 1 248} 249 250 251# 252# dispatch options 253# 254if [ $# = 0 ] ; then ; ctl_usage $0 ; fi ; 255 256case "$1" in 257 -compress) shift ; do_compress "$@" ;; 258 -uncompress) shift ; do_uncompress "$@" ;; 259 -purge) shift ; do_purge "$@" ;; 260 *) ctl_usage $0 ;; 261esac 262