summaryrefslogtreecommitdiffstats
path: root/bin/prepman
blob: f81e200b99704a775835505e6e218f37d4e9e3b8 (plain)
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
#!/bin/bash
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: /var/cvsroot/gentoo-src/portage/bin/prepman,v 1.10.2.3 2005/05/29 12:40:08 jstubbs Exp $

if [[ -z $1 ]] ; then 
	z="${D}usr/share/man"
else
	z="${D}$1/man"
fi

if [[ ! -d ${z} ]] ; then
	echo "QA Notice: prepman called with non-existent dir '${z#${D}}'" 2>&1
	exit 0
fi

for x in $(find "${z}"/ -type d 2>/dev/null) ; do
	for y in $(find "${x}"/ -mindepth 1 -maxdepth 1 \( -type f -or -type l \) ! -name '.keep' 2>/dev/null) ; do
		if [[ -L ${y} ]] ; then
			# Symlink ...
			mylink=${y}
			linkto=$(readlink "${y}")
			
			# Do NOT change links to directories
			if [[ -d ${z}/${linkto} ]] ; then
				continue
			fi

			if [[ ${linkto##*.} != "gz" ]] && [[ ${linkto##*.} != "bz2" ]] ; then
				linkto="${linkto}.gz"
			fi
			if [[ ${mylink##*.} != "gz" ]] && [[ ${mylink##*.} != "bz2" ]] ; then
				mylink="${mylink}.gz"
			fi

			echo "fixing man page symlink: ${mylink##*/}"
			ln -snf "${linkto}" "${mylink}"
			if [[ ${y} != "${mylink}" ]] ; then
				echo "removing old symlink: ${y##*/}"
				rm -f "${y}"
			fi
		else
			if [[ ${y##*.} != "gz" ]] && [[ ${y##*.} != "bz2" ]] && [[ ! -d ${y} ]] ; then
				echo "gzipping man page: ${y##*/}"
				gzip -f -9 "${y}"
			fi
		fi	
	done
done