| 1 |
# Copyright 1999-2012 Gentoo Foundation
|
| 2 |
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/games.eclass,v 1.152 2012/09/15 16:16:53 zmedico Exp $
|
| 4 |
|
| 5 |
# devlist: games@gentoo.org
|
| 6 |
#
|
| 7 |
# This is the games eclass for standardizing the install of games ...
|
| 8 |
# you better have a *good* reason why you're *not* using games.eclass
|
| 9 |
# in a games-* ebuild
|
| 10 |
|
| 11 |
if [[ ${___ECLASS_ONCE_GAMES} != "recur -_+^+_- spank" ]] ; then
|
| 12 |
___ECLASS_ONCE_GAMES="recur -_+^+_- spank"
|
| 13 |
|
| 14 |
inherit base multilib toolchain-funcs eutils user
|
| 15 |
|
| 16 |
case ${EAPI:-0} in
|
| 17 |
0|1) EXPORT_FUNCTIONS pkg_setup src_compile pkg_preinst pkg_postinst ;;
|
| 18 |
2|3|4|5) EXPORT_FUNCTIONS pkg_setup src_configure src_compile pkg_preinst pkg_postinst ;;
|
| 19 |
*) die "no support for EAPI=${EAPI} yet" ;;
|
| 20 |
esac
|
| 21 |
|
| 22 |
export GAMES_PREFIX=${GAMES_PREFIX:-/usr/games}
|
| 23 |
export GAMES_PREFIX_OPT=${GAMES_PREFIX_OPT:-/opt}
|
| 24 |
export GAMES_DATADIR=${GAMES_DATADIR:-/usr/share/games}
|
| 25 |
export GAMES_DATADIR_BASE=${GAMES_DATADIR_BASE:-/usr/share} # some packages auto append 'games'
|
| 26 |
export GAMES_SYSCONFDIR=${GAMES_SYSCONFDIR:-/etc/games}
|
| 27 |
export GAMES_STATEDIR=${GAMES_STATEDIR:-/var/games}
|
| 28 |
export GAMES_LOGDIR=${GAMES_LOGDIR:-/var/log/games}
|
| 29 |
export GAMES_BINDIR=${GAMES_BINDIR:-${GAMES_PREFIX}/bin}
|
| 30 |
export GAMES_ENVD="90games"
|
| 31 |
# if you want to use a different user/group than games.games,
|
| 32 |
# just add these two variables to your environment (aka /etc/profile)
|
| 33 |
export GAMES_USER=${GAMES_USER:-root}
|
| 34 |
export GAMES_USER_DED=${GAMES_USER_DED:-games}
|
| 35 |
export GAMES_GROUP=${GAMES_GROUP:-games}
|
| 36 |
|
| 37 |
games_get_libdir() {
|
| 38 |
echo ${GAMES_PREFIX}/$(get_libdir)
|
| 39 |
}
|
| 40 |
|
| 41 |
egamesconf() {
|
| 42 |
econf \
|
| 43 |
--prefix="${GAMES_PREFIX}" \
|
| 44 |
--libdir="$(games_get_libdir)" \
|
| 45 |
--datadir="${GAMES_DATADIR}" \
|
| 46 |
--sysconfdir="${GAMES_SYSCONFDIR}" \
|
| 47 |
--localstatedir="${GAMES_STATEDIR}" \
|
| 48 |
"$@"
|
| 49 |
}
|
| 50 |
|
| 51 |
gameswrapper() {
|
| 52 |
# dont want to pollute calling env
|
| 53 |
(
|
| 54 |
into "${GAMES_PREFIX}"
|
| 55 |
cmd=$1
|
| 56 |
shift
|
| 57 |
${cmd} "$@"
|
| 58 |
)
|
| 59 |
}
|
| 60 |
|
| 61 |
dogamesbin() { gameswrapper ${FUNCNAME/games} "$@"; }
|
| 62 |
dogamessbin() { gameswrapper ${FUNCNAME/games} "$@"; }
|
| 63 |
dogameslib() { gameswrapper ${FUNCNAME/games} "$@"; }
|
| 64 |
dogameslib.a() { gameswrapper ${FUNCNAME/games} "$@"; }
|
| 65 |
dogameslib.so() { gameswrapper ${FUNCNAME/games} "$@"; }
|
| 66 |
newgamesbin() { gameswrapper ${FUNCNAME/games} "$@"; }
|
| 67 |
newgamessbin() { gameswrapper ${FUNCNAME/games} "$@"; }
|
| 68 |
|
| 69 |
games_make_wrapper() { gameswrapper ${FUNCNAME/games_} "$@"; }
|
| 70 |
|
| 71 |
gamesowners() { chown ${GAMES_USER}:${GAMES_GROUP} "$@"; }
|
| 72 |
gamesperms() { chmod u+rw,g+r-w,o-rwx "$@"; }
|
| 73 |
prepgamesdirs() {
|
| 74 |
local dir f mode
|
| 75 |
for dir in \
|
| 76 |
"${GAMES_PREFIX}" "${GAMES_PREFIX_OPT}" "${GAMES_DATADIR}" \
|
| 77 |
"${GAMES_SYSCONFDIR}" "${GAMES_STATEDIR}" "$(games_get_libdir)" \
|
| 78 |
"${GAMES_BINDIR}" "$@"
|
| 79 |
do
|
| 80 |
[[ ! -d ${D}/${dir} ]] && continue
|
| 81 |
(
|
| 82 |
gamesowners -R "${D}/${dir}"
|
| 83 |
find "${D}/${dir}" -type d -print0 | xargs -0 chmod 750
|
| 84 |
mode=o-rwx,g+r,g-w
|
| 85 |
[[ ${dir} = ${GAMES_STATEDIR} ]] && mode=o-rwx,g+r
|
| 86 |
find "${D}/${dir}" -type f -print0 | xargs -0 chmod $mode
|
| 87 |
|
| 88 |
# common trees should not be games owned #264872
|
| 89 |
if [[ ${dir} == "${GAMES_PREFIX_OPT}" ]] ; then
|
| 90 |
fowners root:root "${dir}"
|
| 91 |
fperms 755 "${dir}"
|
| 92 |
for d in $(get_libdir) bin ; do
|
| 93 |
# check if dirs exist to avoid "nonfatal" option
|
| 94 |
if [[ -e ${D}/${dir}/${d} ]] ; then
|
| 95 |
fowners root:root "${dir}/${d}"
|
| 96 |
fperms 755 "${dir}/${d}"
|
| 97 |
fi
|
| 98 |
done
|
| 99 |
fi
|
| 100 |
) &>/dev/null
|
| 101 |
|
| 102 |
f=$(find "${D}/${dir}" -perm +4000 -a -uid 0 2>/dev/null)
|
| 103 |
if [[ -n ${f} ]] ; then
|
| 104 |
eerror "A game was detected that is setuid root!"
|
| 105 |
eerror "${f}"
|
| 106 |
die "refusing to merge a setuid root game"
|
| 107 |
fi
|
| 108 |
done
|
| 109 |
[[ -d ${D}/${GAMES_BINDIR} ]] || return 0
|
| 110 |
find "${D}/${GAMES_BINDIR}" -maxdepth 1 -type f -exec chmod 750 '{}' \;
|
| 111 |
}
|
| 112 |
|
| 113 |
gamesenv() {
|
| 114 |
local d libdirs
|
| 115 |
|
| 116 |
for d in $(get_all_libdirs) ; do
|
| 117 |
libdirs="${libdirs}:${GAMES_PREFIX}/${d}"
|
| 118 |
done
|
| 119 |
|
| 120 |
# Wish we could use doevnd here, but we dont want the env
|
| 121 |
# file to be tracked in the CONTENTS of every game
|
| 122 |
cat <<-EOF > "${ROOT}"/etc/env.d/${GAMES_ENVD}
|
| 123 |
LDPATH="${libdirs:1}"
|
| 124 |
PATH="${GAMES_BINDIR}"
|
| 125 |
EOF
|
| 126 |
}
|
| 127 |
|
| 128 |
games_pkg_setup() {
|
| 129 |
tc-export CC CXX LD AR RANLIB
|
| 130 |
|
| 131 |
enewgroup "${GAMES_GROUP}" 35
|
| 132 |
[[ ${GAMES_USER} != "root" ]] \
|
| 133 |
&& enewuser "${GAMES_USER}" 35 -1 "${GAMES_PREFIX}" "${GAMES_GROUP}"
|
| 134 |
[[ ${GAMES_USER_DED} != "root" ]] \
|
| 135 |
&& enewuser "${GAMES_USER_DED}" 36 /bin/bash "${GAMES_PREFIX}" "${GAMES_GROUP}"
|
| 136 |
|
| 137 |
# Dear portage team, we are so sorry. Lots of love, games team.
|
| 138 |
# See Bug #61680
|
| 139 |
[[ ${USERLAND} != "GNU" ]] && return 0
|
| 140 |
[[ $(egetshell "${GAMES_USER_DED}") == "/bin/false" ]] \
|
| 141 |
&& usermod -s /bin/bash "${GAMES_USER_DED}"
|
| 142 |
}
|
| 143 |
|
| 144 |
games_src_configure() {
|
| 145 |
[[ -x ./configure ]] && egamesconf
|
| 146 |
}
|
| 147 |
|
| 148 |
games_src_compile() {
|
| 149 |
case ${EAPI:-0} in
|
| 150 |
0|1) games_src_configure ;;
|
| 151 |
esac
|
| 152 |
base_src_make
|
| 153 |
}
|
| 154 |
|
| 155 |
games_pkg_preinst() {
|
| 156 |
local f
|
| 157 |
|
| 158 |
while read f ; do
|
| 159 |
if [[ -e ${ROOT}/${GAMES_STATEDIR}/${f} ]] ; then
|
| 160 |
cp -p \
|
| 161 |
"${ROOT}/${GAMES_STATEDIR}/${f}" \
|
| 162 |
"${D}/${GAMES_STATEDIR}/${f}" \
|
| 163 |
|| die "cp failed"
|
| 164 |
# make the date match the rest of the install
|
| 165 |
touch "${D}/${GAMES_STATEDIR}/${f}"
|
| 166 |
fi
|
| 167 |
done < <(find "${D}/${GAMES_STATEDIR}" -type f -printf '%P\n' 2>/dev/null)
|
| 168 |
}
|
| 169 |
|
| 170 |
# pkg_postinst function ... create env.d entry and warn about games group
|
| 171 |
games_pkg_postinst() {
|
| 172 |
gamesenv
|
| 173 |
if [[ -z "${GAMES_SHOW_WARNING}" ]] ; then
|
| 174 |
ewarn "Remember, in order to play games, you have to"
|
| 175 |
ewarn "be in the '${GAMES_GROUP}' group."
|
| 176 |
echo
|
| 177 |
case ${CHOST} in
|
| 178 |
*-darwin*) ewarn "Just run 'niutil -appendprop / /groups/games users <USER>'";;
|
| 179 |
*-freebsd*|*-dragonfly*) ewarn "Just run 'pw groupmod ${GAMES_GROUP} -m <USER>'";;
|
| 180 |
*) ewarn "Just run 'gpasswd -a <USER> ${GAMES_GROUP}', then have <USER> re-login.";;
|
| 181 |
esac
|
| 182 |
echo
|
| 183 |
einfo "For more info about Gentoo gaming in general, see our website:"
|
| 184 |
einfo " http://games.gentoo.org/"
|
| 185 |
echo
|
| 186 |
fi
|
| 187 |
}
|
| 188 |
|
| 189 |
# Unpack .uz2 files for UT2003/UT2004
|
| 190 |
# $1: directory or file to unpack
|
| 191 |
games_ut_unpack() {
|
| 192 |
local ut_unpack="$1"
|
| 193 |
local f=
|
| 194 |
|
| 195 |
if [[ -z ${ut_unpack} ]] ; then
|
| 196 |
die "You must provide an argument to games_ut_unpack"
|
| 197 |
fi
|
| 198 |
if [[ -f ${ut_unpack} ]] ; then
|
| 199 |
uz2unpack "${ut_unpack}" "${ut_unpack%.uz2}" \
|
| 200 |
|| die "uncompressing file ${ut_unpack}"
|
| 201 |
fi
|
| 202 |
if [[ -d ${ut_unpack} ]] ; then
|
| 203 |
while read f ; do
|
| 204 |
uz2unpack "${ut_unpack}/${f}" "${ut_unpack}/${f%.uz2}" \
|
| 205 |
|| die "uncompressing file ${f}"
|
| 206 |
rm -f "${ut_unpack}/${f}" || die "deleting compressed file ${f}"
|
| 207 |
done < <(find "${ut_unpack}" -maxdepth 1 -name '*.uz2' -printf '%f\n' 2>/dev/null)
|
| 208 |
fi
|
| 209 |
}
|
| 210 |
|
| 211 |
# Unpacks .umod/.ut2mod/.ut4mod files for UT/UT2003/UT2004
|
| 212 |
# Usage: games_umod_unpack $1
|
| 213 |
# oh, and don't forget to set 'dir' and 'Ddir'
|
| 214 |
games_umod_unpack() {
|
| 215 |
local umod=$1
|
| 216 |
mkdir -p "${Ddir}"/System
|
| 217 |
cp "${dir}"/System/{ucc-bin,{Manifest,Def{ault,User}}.ini,{Engine,Core,zlib,ogg,vorbis}.so,{Engine,Core}.int} "${Ddir}"/System
|
| 218 |
cd "${Ddir}"/System
|
| 219 |
UT_DATA_PATH=${Ddir}/System ./ucc-bin umodunpack -x "${S}/${umod}" -nohomedir &> /dev/null \
|
| 220 |
|| die "uncompressing file ${umod}"
|
| 221 |
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 \
|
| 222 |
|| die "Removing temporary files"
|
| 223 |
}
|
| 224 |
|
| 225 |
fi
|