1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
|
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/games-mods.eclass,v 1.16 2007/09/15 00:42:41 wolf31o2 Exp $
# Variables to specify in an ebuild which uses this eclass:
# GAME - (doom3, quake4 or ut2004, etc), unless ${PN} starts with e.g. "doom3-"
# MOD_BINS - Name of the binary to run
# MOD_DESC - Description for the mod
# MOD_DIR - Subdirectory name for the mod, if applicable
# MOD_ICON - Custom icon for the mod, instead of the default
# MOD_NAME - Creates a command-line wrapper and desktop icon for the mod
# MOD_TBZ2 - File to extract within the Makeself archive
inherit eutils games
EXPORT_FUNCTIONS pkg_setup src_unpack src_install pkg_postinst
[[ -z ${GAME} ]] && GAME=${PN%%-*}
# Set our default title, icon, and cli options
case "${GAME}" in
"doom3")
GAME_TITLE="Doom III"
DEFAULT_MOD_ICON="doom3.png"
SELECT_MOD="+set fs_game "
GAME_EXE="doom3"
DED_EXE="doom3-ded"
DED_OPTIONS="+set dedicated 1 +exec server.cfg"
;;
"enemy-territory")
GAME_TITLE="Enemy Territory"
DEFAULT_MOD_ICON="ET.xpm"
SELECT_MOD="+set fs_game "
GAME_EXE="et"
DED_EXE="et-ded"
DED_OPTIONS="+set dedicated 1 +exec server.cfg"
;;
"quake3")
GAME_TITLE="Quake III"
DEFAULT_MOD_ICON="quake3.xpm"
SELECT_MOD="+set fs_game "
GAME_EXE="quake3"
DED_EXE="quake3-ded"
DED_OPTIONS="+set dedicated 1 +exec server.cfg"
;;
"quake4")
GAME_TITLE="Quake IV"
DEFAULT_MOD_ICON="quake4.bmp"
SELECT_MOD="+set fs_game "
GAME_EXE="quake4"
DED_EXE="quake4-ded"
DED_OPTIONS="+set dedicated 1 +exec server.cfg"
;;
"ut2003")
GAME_TITLE="UT2003"
DEFAULT_MOD_ICON="ut2003.xpm"
SELECT_MOD="-mod="
GAME_EXE="ut2003"
DED_EXE="ucc"
DED_OPTIONS=""
;;
"ut2004")
GAME_TITLE="UT2004"
DEFAULT_MOD_ICON="ut2004.xpm"
SELECT_MOD="-mod="
GAME_EXE="ut2004"
DED_EXE="ucc"
DED_OPTIONS=""
;;
*)
eerror "This game is either not supported or you must set the GAME"
eerror "variable to the proper game."
die "unsupported game"
;;
esac
DESCRIPTION="${GAME_TITLE} ${MOD_NAME} - ${MOD_DESC}"
SLOT="0"
LICENSE="freedist"
KEYWORDS="-* amd64 x86"
IUSE="dedicated opengl"
RESTRICT="mirror strip"
DEPEND="app-arch/unzip"
#RDEPEND="${CATEGORY}/${GAME}"
S=${WORKDIR}
dir=${GAMES_DATADIR}/${GAME}
Ddir=${D}/${dir}
default_client() {
if use opengl || ! use dedicated
then
# Use opengl by default
return 0
else
return 1
fi
}
games-mods_pkg_setup() {
[[ -z "${MOD_NAME}" ]] && die "what is the name of this mod?"
games_pkg_setup
if has_version ${CATEGORY}/${GAME}
then
if use dedicated && ! built_with_use ${CATEGORY}/${GAME} dedicated
then
die "You must merge ${CATEGORY}/${GAME} with USE=dedicated!"
fi
if has_version ${CATEGORY}/${GAME}-bin
then
if use dedicated && \
! built_with_use ${CATEGORY}/${GAME}-bin dedicated
then
die "You must merge ${CATEGORY}/${GAME}-bin with USE=dedicated!"
fi
fi
elif has_version ${CATEGORY}/${GAME}-bin
then
if use dedicated && ! built_with_use ${CATEGORY}/${GAME}-bin dedicated
then
die "You must merge ${CATEGORY}/${GAME}-bin with USE=dedicated!"
fi
# else
# die "${CATEGORY}/${GAME} not installed!"
fi
}
games-mods_src_unpack() {
# The first thing we do here is determine exactly what we're dealing with
for src_uri in ${A}
do
URI_SUFFIX="${src_uri##*.}"
case ${URI_SUFFIX##*.} in
bin|run)
# We have a Makeself archive, use unpack_makeself
unpack_makeself "${src_uri}"
# Since this is a Makeself archive, it has a lot of useless
# files (for us), so we delete them.
rm -rf setup.data setup.sh uninstall
;;
bz2|gz|Z|z|ZIP|zip)
# We have a normal tarball/zip file, use unpack
unpack "${src_uri}"
;;
esac
done
# This code should only be executed for Makeself archives
for tarball in ${MOD_TBZ2}
do
mkdir -p "${S}"/unpack
for name in "${tarball}_${PV}-english" "${tarball}_${PV}" "${tarball}"
do
for ext in tar.bz2 tar.gz tbz2 tgz
do
if [[ -e "${name}.${ext}" ]]
then
tar xf "${name}.${ext}" -C "${S}"/unpack \
|| die "uncompressing tarball"
# Remove the tarball after we unpack it
rm -f "${name}.${ext}"
fi
done
done
done
# Since we remove all of these anyway, let's move it to the eclass
rm -f 3355_patch 3339_patch
}
games-mods_src_install() {
local readme MOD_ICON_EXT new_bin_name bin_name mod files directories i j
INS_DIR=${dir}
# We check if we have a specific MOD_DIR listed
if [[ -n "${MOD_DIR}" ]]
then
# Am installing into a new subdirectory of the game
if [[ -d "${S}"/unpack/"${MOD_DIR}" ]]
then
INS_DIR=${dir}
elif [[ -d "${S}"/"${MOD_DIR}" ]]
then
S=${WORKDIR}/${MOD_DIR}
INS_DIR=${dir}/${MOD_DIR}
fi
fi
cd "${S}"
# If we have a README, install it
for readme in README*
do
if [[ -e "${readme}" ]]
then
dodoc "${readme}" || die "dodoc failed"
fi
done
if default_client
then
if [[ -n "${MOD_ICON}" ]]
then
# Install custom icon
MOD_ICON_EXT=${MOD_ICON##*.}
newicon "${MOD_ICON}" "${PN}.${MOD_ICON_EXT}"
case ${MOD_ICON_EXT} in
bmp|ico)
MOD_ICON=/usr/share/pixmaps/${PN}.${MOD_ICON_EXT}
;;
*)
MOD_ICON=${PN}.${MOD_ICON_EXT}
;;
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_BINS}" ]]
then
for binary in ${MOD_BINS}
do
if [[ -n "${MOD_DIR}" ]]
then
games_make_wrapper "${GAME_EXE}-${MOD_BINS}" \
"${GAME_EXE} ${SELECT_MOD}${MOD_DIR}" "${dir}" "${dir}"
make_desktop_entry "${GAME_EXE}-${MOD_BINS}" \
"${GAME_TITLE} - ${MOD_NAME}" "${MOD_ICON}"
elif [[ -e "${S}"/bin/"${binary}" ]]
then
exeinto "${dir}"
newexe bin/${binary} ${GAME_EXE}-${binary} \
|| die "newexe failed"
new_bin_name=
bin_name=$(echo ${binary} | sed -e 's:[-_.]: :g')
# We want our wrapper to use the libraries/starting
# directory of our game. If the game is in
# GAMES_PREFIX_OPT, then we want to start there.
if [[ -d "${GAMES_PREFIX_OPT}"/${GAME} ]]
then
GAME_DIR="${GAMES_PREFIX_OPT}/${GAME}"
else
GAME_DIR="${dir}"
fi
games_make_wrapper "${GAME_EXE}-${binary}" \
./"${GAME_EXE}-${binary}" "${GAME_DIR}" "${GAME_DIR}"
if [[ "${bin_name}" == "${binary}" ]]
then
bin_name=${MOD_NAME}
else
for tmp1 in ${bin_name}
do
tmp2=$(echo ${tmp1} | cut -b1 | tr [[:lower:]] \
[[:upper:]])
tmp3=$(echo ${tmp1} | cut -b2-)
new_bin_name="${new_bin_name} ${tmp2}${tmp3}"
done
new_bin_name=$(echo ${new_bin_name} | cut -b1-)
bin_name="${MOD_NAME} (${new_bin_name})"
fi
make_desktop_entry "${GAME_EXE}-${binary}" \
"${GAME_TITLE} - ${bin_name}" "${MOD_ICON}"
# We remove the binary after we have installed it.
rm -f bin/${binary}
fi
done
# We don't want to leave the binary directory around
rm -rf bin
elif [[ -n "${MOD_DIR}" ]]
then
games_make_wrapper "${GAME_EXE}-${MOD_DIR}" \
"${GAME_EXE} ${SELECT_MOD}${MOD_DIR}" "${dir}" "${dir}"
make_desktop_entry "${GAME_EXE}-${MOD_DIR}" \
"${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-${MOD_DIR}" \
"${GAME_EXE}-bin ${SELECT_MOD}${MOD_DIR}" \
"${dir}" "${dir}"
fi
make_desktop_entry "${GAME_EXE}-bin-${MOD_DIR}" \
"${GAME_TITLE} - ${MOD_NAME} (binary)" \
"${MOD_ICON}"
;;
esac
fi
fi
# Copy our unpacked files, if it exists
if [[ -d "${S}"/unpack ]]
then
insinto "${INS_DIR}"
doins -r "${S}"/unpack/* || die "copying files"
rm -rf "${S}"/unpack
fi
# We expect anything not wanted to have been deleted by the ebuild
if [[ ! -z $(ls "${S}"/* 2> /dev/null) ]]
then
insinto "${INS_DIR}"
doins -r * || die "doins -r failed"
fi
# We are installing everything for these mods into ${INS_DIR}, which should
# be ${GAMES_DATADIR}/${GAME}/${MOD_DIR} in most cases, and symlinking it
# into ${GAMES_PREFIX_OPT}/${GAME}/${MOD_DIR} for each game. This should
# allow us to support both binary and source-based games easily.
if [[ -d "${GAMES_PREFIX_OPT}"/"${GAME}" ]] && \
[[ "${GAMES_PREFIX_OPT}" != "${GAMES_DATADIR}" ]]
then
dodir "${GAMES_PREFIX_OPT}"/"${GAME}"
mod=$(echo "${INS_DIR}" | sed -e "s:${GAMES_DATADIR}/${GAME}::" -e "s:^/::" )
if [[ -z "${mod}" ]]
then
# Our mod doesn't have its own directory. We now traverse the
# directory structure and try to symlink everything to
# GAMES_PREFIX_OPT/GAME so it'll work.
directories=$(cd "${D}"/"${INS_DIR}";find . -maxdepth 1 -type d -printf '%P ')
for i in ${directories}
do
if [[ -h "${GAMES_PREFIX_OPT}"/"${GAME}"/${i} ]]
then
# Skip this directory, and just run a symlink
dosym "${INS_DIR}"/${i} \
"${GAMES_PREFIX_OPT}"/"${GAME}"/${i} || die
elif [[ -d "${GAMES_PREFIX_OPT}"/"${GAME}"/${i} ]]
then
dodir "${GAMES_PREFIX_OPT}"/"${GAME}"/${i}
cd "${D}"/"${INS_DIR}"/${i}
files="$(find . -type f -printf '%P ')"
for j in ${files}
do
if has_version ${CATEGORY}/${PN}
then
dosym "${INS_DIR}"/${i}/${j} \
"${GAMES_PREFIX_OPT}"/"${GAME}"/${i}/${j} \
|| die
elif [[ ! -e "${GAMES_PREFIX_OPT}"/"${GAME}"/${i}/${j} ]]
then
dosym "${INS_DIR}"/${i}/${j} \
"${GAMES_PREFIX_OPT}"/"${GAME}"/${i}/${j} \
|| die
fi
done
else
# Skip this directory, and just run a symlink
dosym "${INS_DIR}"/${i} \
"${GAMES_PREFIX_OPT}"/"${GAME}"/${i} || die
fi
done
files=$(cd "${D}"/"${INS_DIR}";find . -maxdepth 1 -type f -printf '%P ')
for i in ${files}
do
# Why don´t we use symlinks? Because these use ./$bin when
# they run and that doesn't work if the binary is in
# GAMES_PREFIX_OPT but the mod is in GAMES_DATADIR.
# dosym "${INS_DIR}"/${i} \
# "${GAMES_PREFIX_OPT}"/"${GAME}"/${i} || die
cp -a "${D}"/"${INS_DIR}"/${i} \
${D}/"${GAMES_PREFIX_OPT}"/"${GAME}"/${i} || die
done
elif [[ ! -f "${GAMES_PREFIX_OPT}"/"${GAME}"/${mod} ]]
then
elog "Creating symlink for ${mod}"
dosym "${INS_DIR}" "${GAMES_PREFIX_OPT}"/"${GAME}" || die
fi
fi
if use dedicated
then
dodir "${GAMES_STATEDIR}"
if [[ -e ${FILESDIR}/server.cfg ]]
then
insinto "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}
doins ${FILESDIR}/server.cfg || die "Copying server config"
case ${GAME} in
doom3)
dodir "${GAMES_PREFIX}"/.doom3/${MOD_DIR}
dosym "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}/server.cfg \
"${GAMES_PREFIX}"/.doom3/${MOD_DIR}
;;
enemy-territory)
dodir "${GAMES_PREFIX}"/.etwolf/${MOD_DIR}
dosym "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}/server.cfg \
"${GAMES_PREFIX}"/.etwolf/${MOD_DIR}
;;
quake3)
dodir "${GAMES_PREFIX}"/.q3a/${MOD_DIR}
dosym "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}/server.cfg \
"${GAMES_PREFIX}"/.q3a/${MOD_DIR}
;;
quake4)
dodir "${GAMES_PREFIX}"/.quake4/${MOD_DIR}
dosym "${GAMES_SYSCONFDIR}"/${GAME}/${MOD_DIR}/server.cfg \
"${GAMES_PREFIX}"/.quake4/${MOD_DIR}
;;
esac
fi
games-mods_make_ded_exec
newgamesbin "${T}"/${GAME_EXE}-${MOD_DIR}-ded.bin \
${GAME_EXE}-${MOD_DIR}-ded || die "dedicated"
games-mods_make_init.d
newinitd "${T}"/${GAME_EXE}-${MOD_DIR}-ded.init.d \
${GAME_EXE}-${MOD_DIR}-ded || die "init.d"
games-mods_make_conf.d
newconfd "${T}"/${GAME_EXE}-${MOD_DIR}-ded.conf.d \
${GAME_EXE}-${MOD_DIR}-ded || die "conf.d"
fi
prepgamesdirs
}
games-mods_pkg_postinst() {
games_pkg_postinst
if default_client
then
if [[ -n "${MOD_BINS}" ]]
then
for binary in ${MOD_BINS}
do
elog "To play this mod run:"
elog " ${GAME_EXE}-${binary}"
echo
done
elif [[ -n "${MOD_DIR}" ]]
then
elog "To play this mod run:"
elog " ${GAME_EXE}-${MOD_DIR}"
echo
fi
fi
if use dedicated
then
elog "To launch a dedicated server run:"
elog " ${GAME_EXE}-${MOD_DIR}-ded"
echo
elog "To launch server at startup run:"
elog " rc-update add ${GAME_EXE}-${MOD_DIR}-ded default"
echo
fi
}
games-mods_make_ded_exec() {
cat <<-EOF > "${T}"/${GAME_EXE}-${MOD_DIR}-ded.bin
#!/bin/sh
${GAMES_BINDIR}/${DED_EXE} ${SELECT_MOD}${MOD_DIR} ${DED_OPTIONS} \${@}
EOF
}
games-mods_make_init.d() {
cat <<EOF > "${T}"/${GAME_EXE}-${MOD_DIR}-ded.init.d
#!/sbin/runscript
$(<${PORTDIR}/header.txt)
depend() {
need net
}
start() {
ebegin "Starting ${GAME_TITLE} - ${MOD_NAME} dedicated server"
start-stop-daemon --start --quiet --background --chuid \\
${GAMES_USER_DED}:games --env HOME="${GAMES_PREFIX}" --exec \\
${GAMES_BINDIR}/${GAME_EXE}-${MOD_DIR}-ded \\
\${${GAME_EXE}_${MOD_DIR}_OPTS}
eend \$?
}
stop() {
ebegin "Stopping ${GAME_TITLE} - ${MOD_NAME} dedicated server"
start-stop-daemon --stop --quiet --exec \\
${GAMES_BINDIR}/${GAME_EXE}-${MOD_DIR}-ded
eend \$?
}
EOF
}
games-mods_make_conf.d() {
if [[ -e ${FILESDIR}/${GAME_EXE}-${MOD_DIR}.conf.d ]]
then
cp ${FILESDIR}/${GAME_EXE}-${MOD_DIR}.conf.d \
"${T}"/${GAME_EXE}-${MOD_DIR}-ded.conf.d
return 0
fi
cat <<-EOF > "${T}"/${GAME_EXE}-${MOD_DIR}-ded.conf.d
$(<${PORTDIR}/header.txt)
# Any extra options you want to pass to the dedicated server
# ${GAME_EXE}_${MOD_DIR}_OPTS="+set com_hunkmegs 64 +set com_zonemegs 32"
EOF
}
|