1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # Variables to specify in an ebuild which uses this eclass:
5 # GAME - (doom3, quake4 or ut2004, etc), unless ${PN} starts with e.g. "doom3-"
6 # MOD_DESC - Description for the mod
7 # MOD_NAME - Creates a command-line wrapper and desktop icon for the mod
8 # MOD_DIR - Subdirectory name for the mod, if applicable
9 # MOD_ICON - Custom icon for the mod, instead of the default
13 EXPORT_FUNCTIONS src_install pkg_postinst
15 [[ -z ${GAME} ]] && GAME=${PN%%-*}
19 GAME_PKGS="games-fps/doom3"
20 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/doom3 )
26 DED_OPTS="+set dedicated 1 +exec server.cfg"
28 SELECT_MOD="+set fs_game "
31 GAME_PKGS="games-fps/enemy-territory"
32 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/enemy-territory )
33 GAME_NAME="Enemy Territory"
38 DED_OPTS="+set dedicated 1 +exec server.cfg"
40 SELECT_MOD="+set fs_game "
43 GAME_PKGS="games-fps/quake3 games-fps/quake3-bin"
44 GAME_DIRS=( "${GAMES_DATADIR}"/quake3 "${GAMES_PREFIX_OPT}"/quake3 )
50 DED_OPTS="+set dedicated 1 +exec server.cfg"
52 SELECT_MOD="+set fs_game "
55 GAME_PKGS="games-fps/quake4-bin"
56 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/quake4 )
59 GAME_ICON="/usr/share/pixmaps/quake4.bmp"
62 DED_OPTS="+set dedicated 1 +exec server.cfg"
64 SELECT_MOD="+set fs_game "
67 GAME_PKGS="games-fps/ut2003"
68 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/ut2003 )
79 GAME_PKGS="games-fps/ut2004"
80 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/{ut2004,ut2004-ded} )
84 DED_PKGS="games-server/ut2004-ded"
91 eerror "This game is either not supported or you must set the GAME"
92 eerror "variable to the proper game."
93 die "games-mods.eclass: unsupported GAME"
97 MOD_BIN="${GAME_BIN}-${PN/${GAME}-}"
98 MOD_DED_BIN="${MOD_BIN}-ded"
100 games-mods_get_rdepend() {
103 if [[ ${1} == "--ded" ]] ; then
104 pkgs=( ${DED_PKGS} ${GAME_PKGS} )
106 pkgs=( ${GAME_PKGS} )
109 [[ ${#pkgs[@]} -gt 1 ]] && echo -n "|| ( "
112 0|1) echo -n "${pkgs[@]}" ;;
115 if [[ ${1} == "--ded" ]] ; then
116 echo -n "${DED_PKGS}"
117 for p in ${GAME_PKGS} ; do
118 echo -n " ${p}[dedicated]"
121 for p in ${GAME_PKGS} ; do
122 echo -n " || ( ${p}[opengl] ${p}[-dedicated] )"
126 *) die "EAPI ${EAPI} not supported"
129 [[ ${#pkgs[@]} -gt 1 ]] && echo -n " )"
132 DESCRIPTION="${GAME_NAME} ${MOD_NAME} - ${MOD_DESC}"
135 IUSE="dedicated opengl"
136 RESTRICT="mirror strip"
138 DEPEND="app-arch/unzip"
139 RDEPEND="dedicated? ( $(games-mods_get_rdepend --ded) )
140 opengl? ( $(games-mods_get_rdepend) )
141 !dedicated? ( !opengl? ( $(games-mods_get_rdepend) ) )"
145 INS_DIR=${GAMES_DATADIR}/${GAME}
147 games-mods_use_opengl() {
148 [[ -z ${MOD_DIR} ]] && return 1
150 if use opengl || ! use dedicated ; then
151 # Use opengl by default
158 games-mods_use_dedicated() {
159 [[ -z ${MOD_DIR} ]] && return 1
161 use dedicated && return 0 || return 1
164 games-mods_dosyms() {
165 # We are installing everything for these mods into ${INS_DIR},
166 # ${GAMES_DATADIR}/${GAME} in most cases, and symlinking it
167 # into ${GAMES_PREFIX_OPT}/${GAME} for each game. This should
168 # allow us to support both binary and source-based games easily.
170 for dir in "${GAME_DIRS[@]}" ; do
171 [[ -z ${dir} || ${INS_DIR} == ${dir} ]] && continue
172 pushd "${D}/${INS_DIR}" > /dev/null || die "pushd failed"
175 if [[ -d ${i} ]] ; then
176 if [[ ${i} == ${MOD_DIR} ]] ; then
177 dosym "${INS_DIR}/${i}" "${dir}/${i}" \
178 || die "dosym ${i} failed"
182 dosym "${INS_DIR}/${f}" "${dir}/${f}" \
183 || die "dosym ${f} failed"
184 done < <(find "${i}" -type f)
186 elif [[ -f ${i} ]] ; then
187 dosym "${INS_DIR}/${i}" "${dir}/${i}" \
188 || die "dosym ${i} failed"
190 die "${i} shouldn't be there"
193 popd > /dev/null || die "popd failed"
197 games-mods_make_initd() {
198 cat <<EOF > "${T}"/${MOD_DED_BIN}
200 # Copyright 1999-2016 Gentoo Foundation
201 # Distributed under the terms of the GNU General Public License v2
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"