1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # Variables to specify in an ebuild which uses this eclass:
6 # GAME - (doom3, quake4 or ut2004, etc), unless ${PN} starts with e.g. "doom3-"
7 # MOD_DESC - Description for the mod
8 # MOD_NAME - Creates a command-line wrapper and desktop icon for the mod
9 # MOD_DIR - Subdirectory name for the mod, if applicable
10 # MOD_ICON - Custom icon for the mod, instead of the default
14 EXPORT_FUNCTIONS src_install pkg_postinst
16 [[ -z ${GAME} ]] && GAME=${PN%%-*}
20 GAME_PKGS="games-fps/doom3"
21 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/doom3 )
27 DED_OPTS="+set dedicated 1 +exec server.cfg"
29 SELECT_MOD="+set fs_game "
32 GAME_PKGS="games-fps/enemy-territory"
33 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/enemy-territory )
34 GAME_NAME="Enemy Territory"
39 DED_OPTS="+set dedicated 1 +exec server.cfg"
41 SELECT_MOD="+set fs_game "
44 GAME_PKGS="games-fps/quake3 games-fps/quake3-bin"
45 GAME_DIRS=( "${GAMES_DATADIR}"/quake3 "${GAMES_PREFIX_OPT}"/quake3 )
51 DED_OPTS="+set dedicated 1 +exec server.cfg"
53 SELECT_MOD="+set fs_game "
56 GAME_PKGS="games-fps/quake4-bin"
57 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/quake4 )
60 GAME_ICON="/usr/share/pixmaps/quake4.bmp"
63 DED_OPTS="+set dedicated 1 +exec server.cfg"
65 SELECT_MOD="+set fs_game "
68 GAME_PKGS="games-fps/ut2003"
69 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/ut2003 )
80 GAME_PKGS="games-fps/ut2004"
81 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/{ut2004,ut2004-ded} )
85 DED_PKGS="games-server/ut2004-ded"
92 eerror "This game is either not supported or you must set the GAME"
93 eerror "variable to the proper game."
94 die "games-mods.eclass: unsupported GAME"
98 MOD_BIN="${GAME_BIN}-${PN/${GAME}-}"
99 MOD_DED_BIN="${MOD_BIN}-ded"
101 games-mods_get_rdepend() {
104 if [[ ${1} == "--ded" ]] ; then
105 pkgs=( ${DED_PKGS} ${GAME_PKGS} )
107 pkgs=( ${GAME_PKGS} )
110 [[ ${#pkgs[@]} -gt 1 ]] && echo -n "|| ( "
113 0|1) echo -n "${pkgs[@]}" ;;
116 if [[ ${1} == "--ded" ]] ; then
117 echo -n "${DED_PKGS}"
118 for p in ${GAME_PKGS} ; do
119 echo -n " ${p}[dedicated]"
122 for p in ${GAME_PKGS} ; do
123 echo -n " || ( ${p}[opengl] ${p}[-dedicated] )"
127 *) die "EAPI ${EAPI} not supported"
130 [[ ${#pkgs[@]} -gt 1 ]] && echo -n " )"
133 DESCRIPTION="${GAME_NAME} ${MOD_NAME} - ${MOD_DESC}"
136 IUSE="dedicated opengl"
137 RESTRICT="mirror strip"
139 DEPEND="app-arch/unzip"
140 RDEPEND="dedicated? ( $(games-mods_get_rdepend --ded) )
141 opengl? ( $(games-mods_get_rdepend) )
142 !dedicated? ( !opengl? ( $(games-mods_get_rdepend) ) )"
146 INS_DIR=${GAMES_DATADIR}/${GAME}
148 games-mods_use_opengl() {
149 [[ -z ${MOD_DIR} ]] && return 1
151 if use opengl || ! use dedicated ; then
152 # Use opengl by default
159 games-mods_use_dedicated() {
160 [[ -z ${MOD_DIR} ]] && return 1
162 use dedicated && return 0 || return 1
165 games-mods_dosyms() {
166 # We are installing everything for these mods into ${INS_DIR},
167 # ${GAMES_DATADIR}/${GAME} in most cases, and symlinking it
168 # into ${GAMES_PREFIX_OPT}/${GAME} for each game. This should
169 # allow us to support both binary and source-based games easily.
171 for dir in "${GAME_DIRS[@]}" ; do
172 [[ -z ${dir} || ${INS_DIR} == ${dir} ]] && continue
173 pushd "${D}/${INS_DIR}" > /dev/null || die "pushd failed"
176 if [[ -d ${i} ]] ; then
177 if [[ ${i} == ${MOD_DIR} ]] ; then
178 dosym "${INS_DIR}/${i}" "${dir}/${i}" \
179 || die "dosym ${i} failed"
183 dosym "${INS_DIR}/${f}" "${dir}/${f}" \
184 || die "dosym ${f} failed"
185 done < <(find "${i}" -type f)
187 elif [[ -f ${i} ]] ; then
188 dosym "${INS_DIR}/${i}" "${dir}/${i}" \
189 || die "dosym ${i} failed"
191 die "${i} shouldn't be there"
194 popd > /dev/null || die "popd failed"
198 games-mods_make_initd() {
199 cat <<EOF > "${T}"/${MOD_DED_BIN}
201 $(head -n 2 ${PORTDIR}/header.txt)
202 # Generated by games-mods.eclass
209 ebegin "Starting ${MOD_DED_BIN}"
210 start-stop-daemon --start --quiet --background --make-pidfile \\
211 --pidfile /var/run/${MOD_DED_BIN}.pid \\
212 --chuid \${${MOD_DED_BIN//-/_}_user}:\${${MOD_DED_BIN//-/_}_group} \\
213 --env HOME="\${${MOD_DED_BIN//-/_}_home}" \\
214 --exec "${GAMES_BINDIR}/${MOD_DED_BIN}" \\
215 -- \${${MOD_DED_BIN//-/_}_opts}
220 ebegin "Stopping ${MOD_DED_BIN}"
221 start-stop-daemon --stop \\
222 --pidfile /var/run/${MOD_DED_BIN}.pid
227 doinitd "${T}"/${MOD_DED_BIN} || die "doinitd failed"
230 games-mods_make_confd() {
231 cat <<-EOF > "${T}"/${MOD_DED_BIN}
232 # User and group the server should run as
233 ${MOD_DED_BIN//-/_}_user="${GAMES_USER_DED}"
234 ${MOD_DED_BIN//-/_}_group="${GAMES_GROUP}"
236 # Directory to use for HOME
237 ${MOD_DED_BIN//-/_}_home="${GAMES_PREFIX}"
239 # Any extra options you want to pass to the dedicated server
240 ${MOD_DED_BIN//-/_}_opts=""
243 doconfd "${T}"/${MOD_DED_BIN} || die "doconfd failed"
246 games-mods_src_install() {
247 if games-mods_use_opengl ; then
248 if [[ -n ${MOD_ICON} ]] ; then
249 # Install custom icon
250 local ext=${MOD_ICON##*.}
251 if [[ -f ${MOD_ICON} ]] ; then
252 newicon "${MOD_ICON}" ${PN}.${ext} || die "newicon failed"
254 newicon ${MOD_DIR}/"${MOD_ICON}" ${PN}.${ext} \
255 || die "newicon failed"
259 MOD_ICON=/usr/share/pixmaps/${PN}.${ext}
266 # Use the game's standard icon
267 MOD_ICON=${GAME_ICON}
270 games_make_wrapper ${MOD_BIN} "${GAME_BIN} ${SELECT_MOD}${MOD_DIR}"
271 make_desktop_entry ${MOD_BIN} "${GAME_NAME} - ${MOD_NAME}" "${MOD_ICON}"
272 # Since only quake3 has both a binary and a source-based install,
273 # we only look for quake3 here.
276 if has_version games-fps/quake3-bin ; then
277 games_make_wrapper ${GAME_BIN}-bin-${PN/${GAME}-} \
278 "${GAME_BIN}-bin ${SELECT_MOD}${MOD_DIR}"
280 make_desktop_entry ${GAME_BIN}-bin-${PN/${GAME}-} \
281 "${GAME_NAME} - ${MOD_NAME} (binary)" "${MOD_ICON}"
286 # We expect anything not wanted to have been deleted by the ebuild
288 doins -r * || die "doins -r failed"
291 if games-mods_use_dedicated ; then
292 if [[ -f ${FILESDIR}/server.cfg ]] ; then
293 insinto "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}
294 doins "${FILESDIR}"/server.cfg || die "doins server.cfg failed"
295 dosym "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}/server.cfg \
296 "${GAMES_PREFIX}"/${DED_CFG_DIR}/${MOD_DIR}/server.cfg \
297 || die "dosym server.cfg failed"
299 games_make_wrapper ${MOD_DED_BIN} \
300 "\"${GAMES_BINDIR}/${DED_BIN}\" ${SELECT_MOD}${MOD_DIR} ${DED_OPTS}"
301 games-mods_make_initd
302 games-mods_make_confd
308 games-mods_pkg_postinst() {
310 if games-mods_use_opengl ; then
311 elog "To play this mod run:"
314 if games-mods_use_dedicated ; then
315 elog "To launch a dedicated server run:"
316 elog " ${MOD_DED_BIN}"
317 elog "To launch the server at startup run:"
318 elog " rc-update add ${MOD_DED_BIN} default"