aboutsummaryrefslogtreecommitdiff
blob: 5547fd734114954141c52d523e9a09a51b5a9cf8 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

shopt -s extdebug
source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; }

if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then
	ED=${D}
elif [[ ${ED:-unset} == "unset" ]]; then
	echo "The variable ED is missing from the environment, but is required for prefix mode; failing."
	exit -1
fi

dir=${ED}usr/share/doc

[[ ! -d ${dir} ]] && exit 0

z=$(find "${dir}" -print \
	'(' -type f -or -type l ')' \
	-not -name '*.gz' \
	-not -name '*.bz2' \
	-not -name '*.xz' \
	-not -name '*.Z' \
	-not -name '*.js' \
	2>/dev/null)

[[ -z ${z} ]] && exit 0

if [[ -z ${PORTAGE_COMPRESS_SUFFIX} ]]; then
	case ${PORTAGE_COMPRESS} in
		gzip)  suffix="gz";;
		bzip2) suffix="bz2";;
		xz)    suffix="xz";;
		*)     echo "prepalldocs error: please set PORTAGE_COMPRESS_SUFFIX in make.conf" >&2
		       exit 1;;
	esac
fi

IFS=$'\n'
echo "doc: ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}"
for y in ${z}; do
	if [[ -L ${y} ]]; then
		# Symlink ...
		mylink=${y}
		linkto=$(readlink "${y}")

		if [[ ${linkto##*.} != ${suffix} ]]; then
			linkto=${linkto}.${suffix}
		fi
		if [[ ${mylink##*.} != ${suffix} ]]; then
			mylink=${mylink}.${suffix}
		fi

		echo "   link fixed ${mylink##*/}"
		ln -snf "${linkto}" "${mylink}"
		if [[ ${y} != ${mylink} ]]; then
			echo "   link removed ${y##*/}"
			rm -f "${y}"
		fi
	else
		if [[ ${y##*.} != ${suffix} ]]; then
			echo "   compressing ${y##*/}" >&2
			"${PORTAGE_COMPRESS}" ${PORTAGE_COMPRESS_FLAGS} -f "${y}"
		fi
	fi
done

: