diff options
author | Tristan Heaven <tristan@gentoo.org> | 2009-10-12 00:53:51 +0000 |
---|---|---|
committer | Tristan Heaven <tristan@gentoo.org> | 2009-10-12 00:53:51 +0000 |
commit | b441dda1b60aa2fefaad6b78d6552ccb708192ad (patch) | |
tree | db01847eb4fea3967d896e11d6dbc800df3af592 /eclass/games-mods.eclass | |
parent | x11-libs/libxkbfile: bump to 1.0.6, sync with overlay (diff) | |
download | historical-b441dda1b60aa2fefaad6b78d6552ccb708192ad.tar.gz historical-b441dda1b60aa2fefaad6b78d6552ccb708192ad.tar.bz2 historical-b441dda1b60aa2fefaad6b78d6552ccb708192ad.zip |
support symlinking files to more than one directory; mod support for ut2004-ded; fix init scripts; cleanup
Diffstat (limited to 'eclass/games-mods.eclass')
-rw-r--r-- | eclass/games-mods.eclass | 356 |
1 files changed, 187 insertions, 169 deletions
diff --git a/eclass/games-mods.eclass b/eclass/games-mods.eclass index 577280cd1396..3d9315ba4cfa 100644 --- a/eclass/games-mods.eclass +++ b/eclass/games-mods.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2009 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/games-mods.eclass,v 1.41 2009/10/11 11:50:21 maekke Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/games-mods.eclass,v 1.42 2009/10/12 00:53:51 nyhm Exp $ # Variables to specify in an ebuild which uses this eclass: # GAME - (doom3, quake4 or ut2004, etc), unless ${PN} starts with e.g. "doom3-" @@ -15,107 +15,134 @@ EXPORT_FUNCTIONS src_install pkg_postinst [[ -z ${GAME} ]] && GAME=${PN%%-*} -# Set our default title, icon, and cli options case ${GAME} in doom3) GAME_PKGS="games-fps/doom3" - GAME_TITLE="Doom 3" - DEFAULT_MOD_ICON="doom3" - SELECT_MOD="+set fs_game " - GAME_EXE="doom3" - DED_EXE="doom3-ded" - DED_OPTIONS="+set dedicated 1 +exec server.cfg" + GAME_DIRS=( "${GAMES_PREFIX_OPT}"/doom3 ) + GAME_NAME="Doom 3" + GAME_BIN="doom3" + GAME_ICON="doom3" + DED_PKGS="" + DED_BIN="doom3-ded" + DED_OPTS="+set dedicated 1 +exec server.cfg" DED_CFG_DIR=".doom3" + SELECT_MOD="+set fs_game " ;; enemy-territory) GAME_PKGS="games-fps/enemy-territory" - GAME_TITLE="Enemy Territory" - DEFAULT_MOD_ICON="ET" - SELECT_MOD="+set fs_game " - GAME_EXE="et" - DED_EXE="et-ded" - DED_OPTIONS="+set dedicated 1 +exec server.cfg" + GAME_DIRS=( "${GAMES_PREFIX_OPT}"/enemy-territory ) + GAME_NAME="Enemy Territory" + GAME_BIN="et" + GAME_ICON="ET" + DED_PKGS="" + DED_BIN="et-ded" + DED_OPTS="+set dedicated 1 +exec server.cfg" DED_CFG_DIR=".etwolf" + SELECT_MOD="+set fs_game " ;; quake3) GAME_PKGS="games-fps/quake3 games-fps/quake3-bin" - GAME_TITLE="Quake III" - DEFAULT_MOD_ICON="quake3" - SELECT_MOD="+set fs_game " - GAME_EXE="quake3" - DED_EXE="quake3-ded" - DED_OPTIONS="+set dedicated 1 +exec server.cfg" + GAME_DIRS=( "${GAMES_DATADIR}"/quake3 "${GAMES_PREFIX_OPT}"/quake3 ) + GAME_NAME="Quake III" + GAME_BIN="quake3" + GAME_ICON="quake3" + DED_PKGS="" + DED_BIN="quake3-ded" + DED_OPTS="+set dedicated 1 +exec server.cfg" DED_CFG_DIR=".q3a" + SELECT_MOD="+set fs_game " ;; quake4) GAME_PKGS="games-fps/quake4-bin" - GAME_TITLE="Quake 4" - DEFAULT_MOD_ICON="/usr/share/pixmaps/quake4.bmp" - SELECT_MOD="+set fs_game " - GAME_EXE="quake4" - DED_EXE="quake4-ded" - DED_OPTIONS="+set dedicated 1 +exec server.cfg" + GAME_DIRS=( "${GAMES_PREFIX_OPT}"/quake4 ) + GAME_NAME="Quake 4" + GAME_BIN="quake4" + GAME_ICON="/usr/share/pixmaps/quake4.bmp" + DED_PKGS="" + DED_BIN="quake4-ded" + DED_OPTS="+set dedicated 1 +exec server.cfg" DED_CFG_DIR=".quake4" + SELECT_MOD="+set fs_game " ;; ut2003) GAME_PKGS="games-fps/ut2003" - GAME_TITLE="UT2003" - DEFAULT_MOD_ICON="ut2003" - SELECT_MOD="-mod=" - GAME_EXE="ut2003" - DED_EXE="ucc" - DED_OPTIONS="" + GAME_DIRS=( "${GAMES_PREFIX_OPT}"/ut2003 ) + GAME_NAME="UT2003" + GAME_BIN="ut2003" + GAME_ICON="ut2003" + DED_PKGS="" + DED_BIN="ucc" + DED_OPTS="" DED_CFG_DIR="" + SELECT_MOD="-mod=" ;; ut2004) GAME_PKGS="games-fps/ut2004" - GAME_TITLE="UT2004" - DEFAULT_MOD_ICON="ut2004" - SELECT_MOD="-mod=" - GAME_EXE="ut2004" - DED_EXE="ut2004-ded" - DED_OPTIONS="" + GAME_DIRS=( "${GAMES_PREFIX_OPT}"/{ut2004,ut2004-ded} ) + GAME_NAME="UT2004" + GAME_BIN="ut2004" + GAME_ICON="ut2004" + DED_PKGS="games-server/ut2004-ded" + DED_BIN="ut2004-ded" + DED_OPTS="" DED_CFG_DIR="" + SELECT_MOD="-mod=" ;; *) eerror "This game is either not supported or you must set the GAME" eerror "variable to the proper game." - die "unsupported game" + die "games-mods.eclass: unsupported GAME" ;; esac +MOD_BIN="${GAME_BIN}-${PN/${GAME}-}" +MOD_DED_BIN="${MOD_BIN}-ded" + games-mods_get_rdepend() { - [[ $# -lt 1 ]] && die "${FUNCNAME}: need args" - [[ $# -gt 1 ]] && echo -n "|| ( " + local pkgs + + if [[ ${1} == "--ded" ]] ; then + pkgs=( ${DED_PKGS} ${GAME_PKGS} ) + else + pkgs=( ${GAME_PKGS} ) + fi + + [[ ${#pkgs[@]} -gt 1 ]] && echo -n "|| ( " case ${EAPI:-0} in - 0|1) echo -n $@ ;; + 0|1) echo -n "${pkgs[@]}" ;; 2) - local pkg - for pkg in $@ ; do - if [[ -z ${MOD_DIR} ]] ; then - echo -n " ${pkg}" - else - echo -n " ${pkg}[dedicated=,opengl=]" - fi - done + local p + if [[ ${1} == "--ded" ]] ; then + echo -n "${DED_PKGS}" + for p in ${GAME_PKGS} ; do + echo -n " ${p}[dedicated]" + done + else + for p in ${GAME_PKGS} ; do + echo -n " || ( ${p}[opengl] ${p}[-dedicated] )" + done + fi ;; esac - [[ $# -gt 1 ]] && echo -n " )" + [[ ${#pkgs[@]} -gt 1 ]] && echo -n " )" } -DESCRIPTION="${GAME_TITLE} ${MOD_NAME} - ${MOD_DESC}" +DESCRIPTION="${GAME_NAME} ${MOD_NAME} - ${MOD_DESC}" SLOT="0" +IUSE="dedicated opengl" RESTRICT="mirror strip" DEPEND="app-arch/unzip" -RDEPEND="$(games-mods_get_rdepend ${GAME_PKGS})" +RDEPEND="dedicated? ( $(games-mods_get_rdepend --ded) ) + opengl? ( $(games-mods_get_rdepend) ) + !dedicated? ( !opengl? ( $(games-mods_get_rdepend) ) )" S=${WORKDIR} -dir=${GAMES_DATADIR}/${GAME} +INS_DIR=${GAMES_DATADIR}/${GAME} games-mods_use_opengl() { [[ -z ${MOD_DIR} ]] && return 1 @@ -134,135 +161,41 @@ games-mods_use_dedicated() { use dedicated && return 0 || return 1 } -games-mods_src_install() { - local readme MOD_ICON_EXT new_bin_name bin_name - INS_DIR=${dir} - - # If we have a README, install it - for readme in README* ; do - if [[ -s "${readme}" ]] ; then - dodoc "${readme}" || die "dodoc failed" - fi - done - - if games-mods_use_opengl ; then - if [[ -n "${MOD_ICON}" ]] ; then - # Install custom icon - MOD_ICON_EXT=${MOD_ICON##*.} - if [[ -f ${MOD_ICON} ]] ; then - newicon "${MOD_ICON}" ${PN}.${MOD_ICON_EXT} - else - newicon ${MOD_DIR}/"${MOD_ICON}" ${PN}.${MOD_ICON_EXT} - fi - case ${MOD_ICON_EXT} in - bmp|ico) - MOD_ICON=/usr/share/pixmaps/${PN}.${MOD_ICON_EXT} - ;; - *) - MOD_ICON=${PN} - ;; - esac - else - # Use the game's standard icon - MOD_ICON=${DEFAULT_MOD_ICON} - fi - - # Set up command-line and desktop menu entries - if [[ -n ${MOD_DIR} ]] ; then - games_make_wrapper "${GAME_EXE}-${PN/${GAME}-}" \ - "${GAME_EXE} ${SELECT_MOD}${MOD_DIR}" - make_desktop_entry "${GAME_EXE}-${PN/${GAME}-}" \ - "${GAME_TITLE} - ${MOD_NAME}" "${MOD_ICON}" - # Since only quake3 has both a binary and a source-based install, - # we only look for quake3 here. - case "${GAME_EXE}" in - "quake3") - if has_version games-fps/quake3-bin ; then - games_make_wrapper "${GAME_EXE}-bin-${PN/${GAME}-}" \ - "${GAME_EXE}-bin ${SELECT_MOD}${MOD_DIR}" - fi - make_desktop_entry "${GAME_EXE}-bin-${PN/${GAME}-}" \ - "${GAME_TITLE} - ${MOD_NAME} (binary)" \ - "${MOD_ICON}" - ;; - esac - fi - fi - - # We expect anything not wanted to have been deleted by the ebuild - insinto "${INS_DIR}" - doins -r * || die "doins -r failed" - +games-mods_dosyms() { # We are installing everything for these mods into ${INS_DIR}, # ${GAMES_DATADIR}/${GAME} in most cases, and symlinking it # into ${GAMES_PREFIX_OPT}/${GAME} for each game. This should # allow us to support both binary and source-based games easily. - if [[ ${GAMES_PREFIX_OPT} != ${GAMES_DATADIR} ]] ; then + local dir + for dir in "${GAME_DIRS[@]}" ; do + [[ -z ${dir} || ${INS_DIR} == ${dir} ]] && continue pushd "${D}/${INS_DIR}" > /dev/null || die "pushd failed" local i for i in * ; do if [[ -d ${i} ]] ; then if [[ ${i} == ${MOD_DIR} ]] ; then - dosym "${INS_DIR}/${i}" \ - "${GAMES_PREFIX_OPT}/${GAME}/${i}" \ + dosym "${INS_DIR}/${i}" "${dir}/${i}" \ || die "dosym ${i} failed" else local f while read f ; do - dosym "${INS_DIR}/${f}" \ - "${GAMES_PREFIX_OPT}/${GAME}/${f}" \ + dosym "${INS_DIR}/${f}" "${dir}/${f}" \ || die "dosym ${f} failed" done < <(find "${i}" -type f) fi elif [[ -f ${i} ]] ; then - dosym "${INS_DIR}/${i}" "${GAMES_PREFIX_OPT}/${GAME}/${i}" \ + dosym "${INS_DIR}/${i}" "${dir}/${i}" \ || die "dosym ${i} failed" else die "${i} shouldn't be there" fi done popd > /dev/null || die "popd failed" - fi - - if games-mods_use_dedicated ; then - if [[ -f ${FILESDIR}/server.cfg ]] ; then - insinto "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR} - doins "${FILESDIR}"/server.cfg || die "Copying server config" - dodir "${GAMES_PREFIX}"/${DED_CFG_DIR}/${MOD_DIR} - dosym "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}/server.cfg \ - "${GAMES_PREFIX}"/${DED_CFG_DIR}/${MOD_DIR}/server.cfg - fi - games_make_wrapper \ - ${GAME_EXE}-${PN/${GAME}-}-ded \ - "${DED_EXE} ${SELECT_MOD}${MOD_DIR} ${DED_OPTIONS}" - games-mods_make_initd - games-mods_make_confd - fi - - prepgamesdirs -} - -games-mods_pkg_postinst() { - games_pkg_postinst - if games-mods_use_opengl ; then - if [[ -n ${MOD_DIR} ]] ; then - elog "To play this mod run:" - elog " ${GAME_EXE}-${PN/${GAME}-}" - echo - fi - fi - if games-mods_use_dedicated ; then - elog "To launch a dedicated server run:" - elog " ${GAME_EXE}-${PN/${GAME}-}-ded" - echo - elog "To launch server at startup run:" - elog " rc-update add ${GAME_EXE}-${PN/${GAME}-}-ded default" - echo - fi + done } games-mods_make_initd() { - cat <<EOF > "${T}"/${GAME_EXE}-${PN/${GAME}-}-ded + cat <<EOF > "${T}"/${MOD_DED_BIN} #!/sbin/runscript $(head -n 2 ${PORTDIR}/header.txt) # Generated by games-mods.eclass @@ -272,30 +205,115 @@ depend() { } start() { - ebegin "Starting ${GAME_TITLE} ${MOD_NAME} dedicated server" - start-stop-daemon --start --quiet --background --chuid \\ - ${GAMES_USER_DED}:${GAMES_GROUP} --env HOME="${GAMES_PREFIX}" --exec \\ - ${GAMES_BINDIR}/${GAME_EXE}-${PN/${GAME}-}-ded -- \\ - \${${GAME_EXE}_${PN/${GAME}-}_opts} + ebegin "Starting ${MOD_DED_BIN}" + start-stop-daemon --start --quiet --background --make-pidfile \\ + --pidfile /var/run/${MOD_DED_BIN}.pid \\ + --chuid \${${MOD_DED_BIN//-/_}_user}:\${${MOD_DED_BIN//-/_}_group} \\ + --env HOME="\${${MOD_DED_BIN//-/_}_home}" \\ + --exec "${GAMES_BINDIR}/${MOD_DED_BIN}" \\ + -- \${${MOD_DED_BIN//-/_}_opts} eend \$? } stop() { - ebegin "Stopping ${GAME_TITLE} ${MOD_NAME} dedicated server" - start-stop-daemon --stop --quiet --exec \\ - ${GAMES_BINDIR}/${GAME_EXE}-${PN/${GAME}-}-ded + ebegin "Stopping ${MOD_DED_BIN}" + start-stop-daemon --stop \\ + --pidfile /var/run/${MOD_DED_BIN}.pid eend \$? } EOF - doinitd "${T}"/${GAME_EXE}-${PN/${GAME}-}-ded || die "doinitd failed" + doinitd "${T}"/${MOD_DED_BIN} || die "doinitd failed" } games-mods_make_confd() { - cat <<-EOF > "${T}"/${GAME_EXE}-${PN/${GAME}-}-ded + cat <<-EOF > "${T}"/${MOD_DED_BIN} + # User and group the server should run as + ${MOD_DED_BIN//-/_}_user="${GAMES_USER_DED}" + ${MOD_DED_BIN//-/_}_group="${GAMES_GROUP}" + + # Directory to use for HOME + ${MOD_DED_BIN//-/_}_home="${GAMES_PREFIX}" + # Any extra options you want to pass to the dedicated server - ${GAME_EXE}_${PN/${GAME}-}_opts="" + ${MOD_DED_BIN//-/_}_opts="" EOF - doconfd "${T}"/${GAME_EXE}-${PN/${GAME}-}-ded || die "doconfd failed" + doconfd "${T}"/${MOD_DED_BIN} || die "doconfd failed" +} + +games-mods_src_install() { + if games-mods_use_opengl ; then + if [[ -n ${MOD_ICON} ]] ; then + # Install custom icon + local ext=${MOD_ICON##*.} + if [[ -f ${MOD_ICON} ]] ; then + newicon "${MOD_ICON}" ${PN}.${ext} || die "newicon failed" + else + newicon ${MOD_DIR}/"${MOD_ICON}" ${PN}.${ext} \ + || die "newicon failed" + fi + case ${ext} in + bmp|ico) + MOD_ICON=/usr/share/pixmaps/${PN}.${ext} + ;; + *) + MOD_ICON=${PN} + ;; + esac + else + # Use the game's standard icon + MOD_ICON=${GAME_ICON} + fi + + games_make_wrapper ${MOD_BIN} "${GAME_BIN} ${SELECT_MOD}${MOD_DIR}" + make_desktop_entry ${MOD_BIN} "${GAME_NAME} - ${MOD_NAME}" "${MOD_ICON}" + # Since only quake3 has both a binary and a source-based install, + # we only look for quake3 here. + case ${GAME} in + quake3) + if has_version games-fps/quake3-bin ; then + games_make_wrapper ${GAME_BIN}-bin-${PN/${GAME}-} \ + "${GAME_BIN}-bin ${SELECT_MOD}${MOD_DIR}" + fi + make_desktop_entry ${GAME_BIN}-bin-${PN/${GAME}-} \ + "${GAME_NAME} - ${MOD_NAME} (binary)" "${MOD_ICON}" + ;; + esac + fi + + # We expect anything not wanted to have been deleted by the ebuild + insinto "${INS_DIR}" + doins -r * || die "doins -r failed" + games-mods_dosyms + + if games-mods_use_dedicated ; then + if [[ -f ${FILESDIR}/server.cfg ]] ; then + insinto "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR} + doins "${FILESDIR}"/server.cfg || die "doins server.cfg failed" + dosym "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}/server.cfg \ + "${GAMES_PREFIX}"/${DED_CFG_DIR}/${MOD_DIR}/server.cfg \ + || die "dosym server.cfg failed" + fi + games_make_wrapper ${MOD_DED_BIN} \ + "\"${GAMES_BINDIR}/${DED_BIN}\" ${SELECT_MOD}${MOD_DIR} ${DED_OPTS}" + games-mods_make_initd + games-mods_make_confd + fi + + prepgamesdirs +} + +games-mods_pkg_postinst() { + games_pkg_postinst + if games-mods_use_opengl ; then + elog "To play this mod run:" + elog " ${MOD_BIN}" + fi + if games-mods_use_dedicated ; then + elog "To launch a dedicated server run:" + elog " ${MOD_DED_BIN}" + elog "To launch the server at startup run:" + elog " rc-update add ${MOD_DED_BIN} default" + fi } |