1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: games.eclass
7 # Games team <games@gentoo.org>
8 # @BLURB: Standardizing the install of games.
10 # This eclass makes sure that games are consistently handled in gentoo.
11 # It installs game files by default in FHS-compatible directories
12 # like /usr/share/games and sets more restrictive permissions in order
13 # to avoid some security bugs.
15 # The installation directories as well as the user and group files are
16 # installed as can be controlled by the user. See the variables like
17 # GAMES_BINDIR, GAMES_USER etc. below. These are NOT supposed to be set
20 # For a general guide on writing games ebuilds, see:
21 # https://wiki.gentoo.org/wiki/Project:Games/Ebuild_howto
24 if [[ -z ${_GAMES_ECLASS} ]]; then
27 inherit base multilib toolchain-funcs eutils user
30 0|1) EXPORT_FUNCTIONS pkg_setup src_compile pkg_preinst pkg_postinst ;;
31 2|3|4|5) EXPORT_FUNCTIONS pkg_setup src_configure src_compile pkg_preinst pkg_postinst ;;
32 *) die "no support for EAPI=${EAPI} yet" ;;
35 if [[ ${CATEGORY}/${PN} != "games-misc/games-envd" ]] ; then
37 RDEPEND="games-misc/games-envd"
40 # @ECLASS-VARIABLE: GAMES_PREFIX
42 # Prefix where to install games, mostly used by GAMES_BINDIR. Games data should
43 # still go into GAMES_DATADIR. May be set by the user.
44 GAMES_PREFIX=${GAMES_PREFIX:-/usr/games}
46 # @ECLASS-VARIABLE: GAMES_PREFIX_OPT
48 # Prefix where to install precompiled/blob games, usually followed by
49 # package name. May be set by the user.
50 GAMES_PREFIX_OPT=${GAMES_PREFIX_OPT:-/opt}
52 # @ECLASS-VARIABLE: GAMES_DATADIR
54 # Base directory where to install game data files, usually followed by
55 # package name. May be set by the user.
56 GAMES_DATADIR=${GAMES_DATADIR:-/usr/share/games}
58 # @ECLASS-VARIABLE: GAMES_DATADIR_BASE
60 # Similar to GAMES_DATADIR, but only used when a package auto appends 'games'
61 # to the path. May be set by the user.
62 GAMES_DATADIR_BASE=${GAMES_DATADIR_BASE:-/usr/share}
64 # @ECLASS-VARIABLE: GAMES_SYSCONFDIR
66 # Where to install global games configuration files, usually followed by
67 # package name. May be set by the user.
68 GAMES_SYSCONFDIR=${GAMES_SYSCONFDIR:-/etc/games}
70 # @ECLASS-VARIABLE: GAMES_STATEDIR
72 # Where to install/store global variable game data, usually followed by
73 # package name. May be set by the user.
74 GAMES_STATEDIR=${GAMES_STATEDIR:-/var/games}
76 # @ECLASS-VARIABLE: GAMES_LOGDIR
78 # Where to store global game log files, usually followed by
79 # package name. May be set by the user.
80 GAMES_LOGDIR=${GAMES_LOGDIR:-/var/log/games}
82 # @ECLASS-VARIABLE: GAMES_BINDIR
84 # Where to install the game binaries. May be set by the user. This is in PATH.
85 GAMES_BINDIR=${GAMES_BINDIR:-${GAMES_PREFIX}/bin}
87 # @ECLASS-VARIABLE: GAMES_ENVD
90 # The games environment file name which sets games specific LDPATH and PATH.
93 # @ECLASS-VARIABLE: GAMES_USER
95 # The USER who owns all game files and usually has write permissions.
96 # May be set by the user.
97 GAMES_USER=${GAMES_USER:-root}
99 # @ECLASS-VARIABLE: GAMES_USER_DED
101 # The USER who owns all game files related to the dedicated server part
102 # of a package. May be set by the user.
103 GAMES_USER_DED=${GAMES_USER_DED:-games}
105 # @ECLASS-VARIABLE: GAMES_GROUP
107 # The GROUP that owns all game files and usually does not have
108 # write permissions. May be set by the user.
109 # If you want games world-executable, then you can at least set this variable
110 # to 'users' which is almost the same.
111 GAMES_GROUP=${GAMES_GROUP:-games}
113 # @FUNCTION: games_get_libdir
115 # Gets the directory where to install games libraries. This is in LDPATH.
117 echo ${GAMES_PREFIX}/$(get_libdir)
120 # @FUNCTION: egamesconf
121 # @USAGE: [<args>...]
123 # Games equivalent to 'econf' for autotools based build systems. It passes
124 # the necessary games specific directories automatically.
126 # handle verbose build log pre-EAPI5
128 if has "${EAPI:-0}" 0 1 2 3 4 ; then
129 if grep -q -s disable-silent-rules "${ECONF_SOURCE:-.}"/configure ; then
130 _gamesconf="--disable-silent-rules"
135 if grep -q -s datarootdir "${ECONF_SOURCE:-.}"/configure ; then
136 _gamesconf="${_gamesconf} --datarootdir=/usr/share"
140 --prefix="${GAMES_PREFIX}" \
141 --libdir="$(games_get_libdir)" \
142 --datadir="${GAMES_DATADIR}" \
143 --sysconfdir="${GAMES_SYSCONFDIR}" \
144 --localstatedir="${GAMES_STATEDIR}" \
149 # @FUNCTION: gameswrapper
150 # @USAGE: <command> [<args>...]
153 # Wraps an install command like dobin, dolib etc, so that
154 # it has GAMES_PREFIX as prefix.
156 # dont want to pollute calling env
158 into "${GAMES_PREFIX}"
165 # @FUNCTION: dogamesbin
168 # Install one or more games binaries.
169 dogamesbin() { gameswrapper ${FUNCNAME/games} "$@"; }
171 # @FUNCTION: dogamessbin
174 # Install one or more games system binaries.
175 dogamessbin() { gameswrapper ${FUNCNAME/games} "$@"; }
177 # @FUNCTION: dogameslib
180 # Install one or more games libraries.
181 dogameslib() { gameswrapper ${FUNCNAME/games} "$@"; }
183 # @FUNCTION: dogameslib.a
186 # Install one or more static games libraries.
187 dogameslib.a() { gameswrapper ${FUNCNAME/games} "$@"; }
189 # @FUNCTION: dogameslib.so
192 # Install one or more shared games libraries.
193 dogameslib.so() { gameswrapper ${FUNCNAME/games} "$@"; }
195 # @FUNCTION: newgamesbin
196 # @USAGE: <path> <newname>
198 # Install one games binary with a new name.
199 newgamesbin() { gameswrapper ${FUNCNAME/games} "$@"; }
201 # @FUNCTION: newgamessbin
202 # @USAGE: <path> <newname>
204 # Install one system games binary with a new name.
205 newgamessbin() { gameswrapper ${FUNCNAME/games} "$@"; }
207 # @FUNCTION: games_make_wrapper
208 # @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
210 # Create a shell wrapper script named wrapper in installpath
211 # (defaults to the games bindir) to execute target (default of wrapper) by
212 # first optionally setting LD_LIBRARY_PATH to the colon-delimited
213 # libpaths followed by optionally changing directory to chdir.
214 games_make_wrapper() { gameswrapper ${FUNCNAME/games_} "$@"; }
216 # @FUNCTION: gamesowners
217 # @USAGE: [<args excluding owner/group>...] <path>...
219 # Run 'chown' with the given args on the given files. Owner and
220 # group are GAMES_USER and GAMES_GROUP and must not be passed
222 gamesowners() { chown ${GAMES_USER}:${GAMES_GROUP} "$@"; }
224 # @FUNCTION: gamesperms
227 # Run 'chmod' with games specific permissions on the given files.
228 gamesperms() { chmod u+rw,g+r-w,o-rwx "$@"; }
230 # @FUNCTION: prepgamesdirs
232 # Fix all permissions/owners of files in games related directories,
233 # usually called at the end of src_install().
237 "${GAMES_PREFIX}" "${GAMES_PREFIX_OPT}" "${GAMES_DATADIR}" \
238 "${GAMES_SYSCONFDIR}" "${GAMES_STATEDIR}" "$(games_get_libdir)" \
239 "${GAMES_BINDIR}" "$@"
241 [[ ! -d ${D}/${dir} ]] && continue
243 gamesowners -R "${D}/${dir}"
244 find "${D}/${dir}" -type d -print0 | xargs -0 chmod 750
246 [[ ${dir} = ${GAMES_STATEDIR} ]] && mode=o-rwx,g+r
247 find "${D}/${dir}" -type f -print0 | xargs -0 chmod $mode
249 # common trees should not be games owned #264872 #537580
250 fowners root:0 "${dir}"
252 if [[ ${dir} == "${GAMES_PREFIX}" \
253 || ${dir} == "${GAMES_PREFIX_OPT}" ]] ; then
254 for d in $(get_libdir) bin ; do
255 # check if dirs exist to avoid "nonfatal" option
256 if [[ -e ${D}/${dir}/${d} ]] ; then
257 fowners root:0 "${dir}/${d}"
258 fperms 755 "${dir}/${d}"
264 f=$(find "${D}/${dir}" -perm +4000 -a -uid 0 2>/dev/null)
265 if [[ -n ${f} ]] ; then
266 eerror "A game was detected that is setuid root!"
268 die "refusing to merge a setuid root game"
271 [[ -d ${D}/${GAMES_BINDIR} ]] || return 0
272 find "${D}/${GAMES_BINDIR}" -maxdepth 1 -type f -exec chmod 750 '{}' \;
275 # @FUNCTION: games_pkg_setup
277 # Export some toolchain specific variables and create games related groups
278 # and users. This function is exported as pkg_setup().
280 tc-export CC CXX LD AR RANLIB
282 enewgroup "${GAMES_GROUP}" 35
283 [[ ${GAMES_USER} != "root" ]] \
284 && enewuser "${GAMES_USER}" 35 -1 "${GAMES_PREFIX}" "${GAMES_GROUP}"
285 [[ ${GAMES_USER_DED} != "root" ]] \
286 && enewuser "${GAMES_USER_DED}" 36 /bin/bash "${GAMES_PREFIX}" "${GAMES_GROUP}"
288 # Dear portage team, we are so sorry. Lots of love, games team.
290 [[ ${USERLAND} != "GNU" ]] && return 0
291 [[ $(egetshell "${GAMES_USER_DED}") == "/bin/false" ]] \
292 && usermod -s /bin/bash "${GAMES_USER_DED}"
295 # @FUNCTION: games_src_configure
297 # Runs egamesconf if there is a configure file.
298 # This function is exported as src_configure().
299 games_src_configure() {
300 [[ -x "${ECONF_SOURCE:-.}"/configure ]] && egamesconf
303 # @FUNCTION: games_src_compile
305 # Runs base_src_make(). This function is exported as src_compile().
306 games_src_compile() {
308 0|1) games_src_configure ;;
313 # @FUNCTION: games_pkg_preinst
315 # Synchronizes GAMES_STATEDIR of the ebuild image with the live filesystem.
316 games_pkg_preinst() {
320 if [[ -e ${ROOT}/${GAMES_STATEDIR}/${f} ]] ; then
322 "${ROOT}/${GAMES_STATEDIR}/${f}" \
323 "${D}/${GAMES_STATEDIR}/${f}" \
325 # make the date match the rest of the install
326 touch "${D}/${GAMES_STATEDIR}/${f}"
328 done < <(find "${D}/${GAMES_STATEDIR}" -type f -printf '%P\n' 2>/dev/null)
331 # @FUNCTION: games_pkg_postinst
333 # Prints some warnings and infos, also related to games groups.
334 games_pkg_postinst() {
335 if [[ -z "${GAMES_SHOW_WARNING}" ]] ; then
336 ewarn "Remember, in order to play games, you have to"
337 ewarn "be in the '${GAMES_GROUP}' group."
340 *-darwin*) ewarn "Just run 'niutil -appendprop / /groups/games users <USER>'";;
341 *-freebsd*|*-dragonfly*) ewarn "Just run 'pw groupmod ${GAMES_GROUP} -m <USER>'";;
342 *) ewarn "Just run 'gpasswd -a <USER> ${GAMES_GROUP}', then have <USER> re-login.";;
345 einfo "For more info about Gentoo gaming in general, see our website:"
346 einfo " https://games.gentoo.org/"
351 # @FUNCTION: games_ut_unpack
352 # @USAGE: <directory or file to unpack>
354 # Unpack .uz2 files for UT2003/UT2004.
359 if [[ -z ${ut_unpack} ]] ; then
360 die "You must provide an argument to games_ut_unpack"
362 if [[ -f ${ut_unpack} ]] ; then
363 uz2unpack "${ut_unpack}" "${ut_unpack%.uz2}" \
364 || die "uncompressing file ${ut_unpack}"
366 if [[ -d ${ut_unpack} ]] ; then
368 uz2unpack "${ut_unpack}/${f}" "${ut_unpack}/${f%.uz2}" \
369 || die "uncompressing file ${f}"
370 rm -f "${ut_unpack}/${f}" || die "deleting compressed file ${f}"
371 done < <(find "${ut_unpack}" -maxdepth 1 -name '*.uz2' -printf '%f\n' 2>/dev/null)
375 # @FUNCTION: games_umod_unpack
376 # @USAGE: <file to unpack>
378 # Unpacks .umod/.ut2mod/.ut4mod files for UT/UT2003/UT2004.
379 # Don't forget to set 'dir' and 'Ddir'.
380 games_umod_unpack() {
382 mkdir -p "${Ddir}"/System
383 cp "${dir}"/System/{ucc-bin,{Manifest,Def{ault,User}}.ini,{Engine,Core,zlib,ogg,vorbis}.so,{Engine,Core}.int} "${Ddir}"/System
385 UT_DATA_PATH=${Ddir}/System ./ucc-bin umodunpack -x "${S}/${umod}" -nohomedir &> /dev/null \
386 || die "uncompressing file ${umod}"
387 rm -f "${Ddir}"/System/{ucc-bin,{Manifest,Def{ault,User},User,UT200{3,4}}.ini,{Engine,Core,zlib,ogg,vorbis}.so,{Engine,Core}.int,ucc.log} &>/dev/null \
388 || die "Removing temporary files"