1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 # All consumers are gone.
6 # Bug #156882, #574642, #637740. Removal in 14 days.
8 # Variables to specify in an ebuild which uses this eclass:
9 # GAME - (doom3, quake4 or ut2004, etc), unless ${PN} starts with e.g. "doom3-"
10 # MOD_DESC - Description for the mod
11 # MOD_NAME - Creates a command-line wrapper and desktop icon for the mod
12 # MOD_DIR - Subdirectory name for the mod, if applicable
13 # MOD_ICON - Custom icon for the mod, instead of the default
17 EXPORT_FUNCTIONS src_install pkg_postinst
19 [[ -z ${GAME} ]] && GAME=${PN%%-*}
23 GAME_PKGS="games-fps/doom3"
24 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/doom3 )
30 DED_OPTS="+set dedicated 1 +exec server.cfg"
32 SELECT_MOD="+set fs_game "
35 GAME_PKGS="games-fps/enemy-territory"
36 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/enemy-territory )
37 GAME_NAME="Enemy Territory"
42 DED_OPTS="+set dedicated 1 +exec server.cfg"
44 SELECT_MOD="+set fs_game "
47 GAME_PKGS="games-fps/quake3 games-fps/quake3-bin"
48 GAME_DIRS=( "${GAMES_DATADIR}"/quake3 "${GAMES_PREFIX_OPT}"/quake3 )
54 DED_OPTS="+set dedicated 1 +exec server.cfg"
56 SELECT_MOD="+set fs_game "
59 GAME_PKGS="games-fps/quake4-bin"
60 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/quake4 )
63 GAME_ICON="/usr/share/pixmaps/quake4.bmp"
66 DED_OPTS="+set dedicated 1 +exec server.cfg"
68 SELECT_MOD="+set fs_game "
71 GAME_PKGS="games-fps/ut2003"
72 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/ut2003 )
83 GAME_PKGS="games-fps/ut2004"
84 GAME_DIRS=( "${GAMES_PREFIX_OPT}"/{ut2004,ut2004-ded} )
88 DED_PKGS="games-server/ut2004-ded"
95 eerror "This game is either not supported or you must set the GAME"
96 eerror "variable to the proper game."
97 die "games-mods.eclass: unsupported GAME"
101 MOD_BIN="${GAME_BIN}-${PN/${GAME}-}"
102 MOD_DED_BIN="${MOD_BIN}-ded"
104 games-mods_get_rdepend() {
107 if [[ ${1} == "--ded" ]] ; then
108 pkgs=( ${DED_PKGS} ${GAME_PKGS} )
110 pkgs=( ${GAME_PKGS} )
113 [[ ${#pkgs[@]} -gt 1 ]] && echo -n "|| ( "
116 0|1) echo -n "${pkgs[@]}" ;;
119 if [[ ${1} == "--ded" ]] ; then
120 echo -n "${DED_PKGS}"
121 for p in ${GAME_PKGS} ; do
122 echo -n " ${p}[dedicated]"
125 for p in ${GAME_PKGS} ; do
126 echo -n " || ( ${p}[opengl] ${p}[-dedicated] )"
130 *) die "EAPI ${EAPI} not supported"
133 [[ ${#pkgs[@]} -gt 1 ]] && echo -n " )"
136 DESCRIPTION="${GAME_NAME} ${MOD_NAME} - ${MOD_DESC}"
139 IUSE="dedicated opengl"
140 RESTRICT="bindist mirror strip"
142 DEPEND="app-arch/unzip"
143 RDEPEND="dedicated? ( $(games-mods_get_rdepend --ded) )
144 opengl? ( $(games-mods_get_rdepend) )
145 !dedicated? ( !opengl? ( $(games-mods_get_rdepend) ) )"
149 INS_DIR=${GAMES_DATADIR}/${GAME}
151 games-mods_use_opengl() {
152 [[ -z ${MOD_DIR} ]] && return 1
154 if use opengl || ! use dedicated ; then
155 # Use opengl by default
162 games-mods_use_dedicated() {
163 [[ -z ${MOD_DIR} ]] && return 1
165 use dedicated && return 0 || return 1
168 games-mods_dosyms() {
169 # We are installing everything for these mods into ${INS_DIR},
170 # ${GAMES_DATADIR}/${GAME} in most cases, and symlinking it
171 # into ${GAMES_PREFIX_OPT}/${GAME} for each game. This should
172 # allow us to support both binary and source-based games easily.
174 for dir in "${GAME_DIRS[@]}" ; do
175 [[ -z ${dir} || ${INS_DIR} == ${dir} ]] && continue
176 pushd "${D}/${INS_DIR}" > /dev/null || die "pushd failed"
179 if [[ -d ${i} ]] ; then
180 if [[ ${i} == ${MOD_DIR} ]] ; then
181 dosym "${INS_DIR}/${i}" "${dir}/${i}" \
182 || die "dosym ${i} failed"
186 dosym "${INS_DIR}/${f}" "${dir}/${f}" \
187 || die "dosym ${f} failed"
188 done < <(find "${i}" -type f)
190 elif [[ -f ${i} ]] ; then
191 dosym "${INS_DIR}/${i}" "${dir}/${i}" \
192 || die "dosym ${i} failed"
194 die "${i} shouldn't be there"
197 popd > /dev/null || die "popd failed"
201 games-mods_make_initd() {
202 cat <<EOF > "${T}"/${MOD_DED_BIN}
204 # Copyright 1999-2016 Gentoo Foundation
205 # Distributed under the terms of the GNU General Public License v2
206 # Generated by games-mods.eclass
213 ebegin "Starting ${MOD_DED_BIN}"
214 start-stop-daemon --start --quiet --background --make-pidfile \\
215 --pidfile /var/run/${MOD_DED_BIN}.pid \\
216 --chuid \${${MOD_DED_BIN//-/_}_user}:\${${MOD_DED_BIN//-/_}_group} \\
217 --env HOME="\${${MOD_DED_BIN//-/_}_home}" \\
218 --exec "${GAMES_BINDIR}/${MOD_DED_BIN}" \\
219 -- \${${MOD_DED_BIN//-/_}_opts}
224 ebegin "Stopping ${MOD_DED_BIN}"
225 start-stop-daemon --stop \\
226 --pidfile /var/run/${MOD_DED_BIN}.pid
231 doinitd "${T}"/${MOD_DED_BIN} || die "doinitd failed"
234 games-mods_make_confd() {
235 cat <<-EOF > "${T}"/${MOD_DED_BIN}
236 # User and group the server should run as
237 ${MOD_DED_BIN//-/_}_user="${GAMES_USER_DED}"
238 ${MOD_DED_BIN//-/_}_group="${GAMES_GROUP}"
240 # Directory to use for HOME
241 ${MOD_DED_BIN//-/_}_home="${GAMES_PREFIX}"
243 # Any extra options you want to pass to the dedicated server
244 ${MOD_DED_BIN//-/_}_opts=""
247 doconfd "${T}"/${MOD_DED_BIN} || die "doconfd failed"
250 games-mods_src_install() {
251 if games-mods_use_opengl ; then
252 if [[ -n ${MOD_ICON} ]] ; then
253 # Install custom icon
254 local ext=${MOD_ICON##*.}
255 if [[ -f ${MOD_ICON} ]] ; then
256 newicon "${MOD_ICON}" ${PN}.${ext} || die "newicon failed"
258 newicon ${MOD_DIR}/"${MOD_ICON}" ${PN}.${ext} \
259 || die "newicon failed"
263 MOD_ICON=/usr/share/pixmaps/${PN}.${ext}
270 # Use the game's standard icon
271 MOD_ICON=${GAME_ICON}
274 games_make_wrapper ${MOD_BIN} "${GAME_BIN} ${SELECT_MOD}${MOD_DIR}"
275 make_desktop_entry ${MOD_BIN} "${GAME_NAME} - ${MOD_NAME}" "${MOD_ICON}"
276 # Since only quake3 has both a binary and a source-based install,
277 # we only look for quake3 here.
280 if has_version games-fps/quake3-bin ; then
281 games_make_wrapper ${GAME_BIN}-bin-${PN/${GAME}-} \
282 "${GAME_BIN}-bin ${SELECT_MOD}${MOD_DIR}"
284 make_desktop_entry ${GAME_BIN}-bin-${PN/${GAME}-} \
285 "${GAME_NAME} - ${MOD_NAME} (binary)" "${MOD_ICON}"
290 # We expect anything not wanted to have been deleted by the ebuild
292 doins -r * || die "doins -r failed"
295 if games-mods_use_dedicated ; then
296 if [[ -f ${FILESDIR}/server.cfg ]] ; then
297 insinto "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}
298 doins "${FILESDIR}"/server.cfg || die "doins server.cfg failed"
299 dosym "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}/server.cfg \
300 "${GAMES_PREFIX}"/${DED_CFG_DIR}/${MOD_DIR}/server.cfg \
301 || die "dosym server.cfg failed"
303 games_make_wrapper ${MOD_DED_BIN} \
304 "\"${GAMES_BINDIR}/${DED_BIN}\" ${SELECT_MOD}${MOD_DIR} ${DED_OPTS}"
305 games-mods_make_initd
306 games-mods_make_confd
312 games-mods_pkg_postinst() {
314 if games-mods_use_opengl ; then
315 elog "To play this mod run:"
318 if games-mods_use_dedicated ; then
319 elog "To launch a dedicated server run:"
320 elog " ${MOD_DED_BIN}"
321 elog "To launch the server at startup run:"
322 elog " rc-update add ${MOD_DED_BIN} default"