summaryrefslogtreecommitdiff
blob: 5870e8624d818099ae934ced5f807ec11a5bb157 (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
70
71
72
73
74
75
76
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils toolchain-funcs

KEYWORDS="~amd64 ~x86"
DESCRIPTION="ExecWrap is a super-user exec wrapper (not only) for the lighttpd web-server"
HOMEPAGE="http://freebsd.unixfreunde.de/sources/"
SRC_URI="http://freebsd.unixfreunde.de/sources/ExecWrap-${PV}.tgz"
LICENSE="BSD"
SLOT="0"
IUSE="lighttpd"

DEPEND=""
RDEPEND="lighttpd? ( www-servers/lighttpd )"

pkg_setup() {
	einfo
	einfo "You can manipulate several configure options of this"
	einfo "ebuild through environment variables:"
	einfo
	einfo "PARENT_UID: UID of the user your parent process runs as (default: 1)"
	einfo "TARGET_MIN_UID: Minimum UID allowed to run scripts (default: 1000)"
	einfo "TARGET_MIN_GID: Minimum GID allowed to run scripts (default: 100)"
	einfo "TARGET_PATH_PREFIX: The prefix required for scripts to be executed (default: /usr/local/)"
	einfo

	if use lighttpd; then
		local -i lighttpd_uid=$(egetent passwd lighttpd 2>/dev/null | cut -d : -f 3)
		if [[ ${lighttpd_uid} > 0 ]]; then
			PARENT_UID=${lighttpd_uid}
			TARGET_PATH_PREFIX="/var/www/"
			einfo "Using values suitable for lighttpd."
			einfo
		fi
	fi

	: ${PARENT_UID:=1}
	: ${TARGET_MIN_UID:=1000}
	: ${TARGET_MIN_GID:=100}
	: ${TARGET_PATH_PREFIX:=/usr/local/}

	einfo "Using PARENT_UID ${PARENT_UID}"
	einfo "Using TARGET_MIN_UID ${TARGET_MIN_UID}"
	einfo "Using TARGET_MIN_GID ${TARGET_MIN_GID}"
	einfo "Using TARGET_PATH_PREFIX ${TARGET_PATH_PREFIX}"
	einfo
}

src_unpack() {
	unpack ${A}
	cd ${WORKDIR}
	sed -i \
		-e "s:^#define PARENT_UID[[:space:]].*$:#define PARENT_UID ${PARENT_UID}:g" \
		-e "s:^#define TARGET_MIN_UID[[:space:]].*$:#define TARGET_MIN_UID ${TARGET_MIN_UID}:g" \
		-e "s:^#define TARGET_MIN_GID[[:space:]].*$:#define TARGET_MIN_GID ${TARGET_MIN_GID}:g" \
		-e "s:^#define TARGET_PATH_PREFIX[[:space:]].*$:#define TARGET_PATH_PREFIX \"${TARGET_PATH_PREFIX}\":g" \
		execwrap_config.h \
		|| die "sed failed"
}

src_compile() {
	$(tc-getCC) ${CFLAGS} -o ${PN} ${PN}.c || die "compilation failed"
}

src_install() {
	dobin ${PN}
	dodoc README
	if use lighttpd; then
		fowners root:lighttpd "${ROOT}"usr/bin/${PN}
		fperms 4710 "${ROOT}"usr/bin/${PN}
	else
		fperms 4711 "${ROOT}"usr/bin/${PN}
	fi
}