Debian Codegraph @

gamepack-manager

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #! /usr/bin/env bash
2
3 # get usage help this way:
4 # ./gamepack_manager -h
5
6 : "${CP:=cp -va}"
7 : "${CP_R:=cp -Rva}"
8 : "${GIT:=git}"
9 : "${SVN:=svn}"
10 : "${WGET:=wget}"
11 : "${ECHO:=echo}"
12 : "${MKDIR:=mkdir -v}"
13 : "${MKDIR_P:=mkdir -vp}"
14 : "${RM_R:=rm -vrf}"
15 : "${MV:=mv -v}"
16 : "${TAR:=tar}"
17 : "${UNZIPPER:=unzip}"
18
19 set -e
20
21 default_download_dir='build/download'
22 default_install_dir='build'
23
24 games_dir='games'
25 pack_suffix='Pack'
26
27 free_license_list='BSD GPL'
28
29 printRawDB () {
30 cat <<\EOF
31 #######################################################
32 # #
33 # IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT #
34 # #
35 # Use two whitespaces or more as column separator #
36 # #
37 #######################################################
38
39 #######################################################
40 # Obsolete packs #
41 #######################################################
42
43 # Quake2World was renamed as Quetoo.
44 # JediAcademy and JediOutcast gamepacks are unusable.
45 # Other gamepacks have better version available.
46
47 # JediAcademy proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/JAPack/branches/1.5/
48 # JediOutcast proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/JK2Pack/trunk/
49 # Kingpin unknown zip http://download.kingpin.info/kingpin/editing/maps/map_editors/NetRadiant/addon/Kingpinpack.zip
50 # Neverball proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/NeverballPack.zip
51 # OpenArena unknown zip http://ingar.intranifty.net/files/netradiant/gamepacks/OpenArenaPack.zip
52 # Quake2World GPL svn svn://jdolan.dyndns.org/quake2world/trunk/gtkradiant
53 # Quake3 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q3Pack/trunk/ 29
54 # Quake proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/QuakePack.zip
55 # Tremulous proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/TremulousPack/branches/1.5/
56 # Tremulous proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/TremulousPack.zip
57 # Unvanquished unknown zip http://ingar.intranifty.net/gtkradiant/files/gamepacks/UnvanquishedPack.zip
58 # Warfork GPL zip https://cdn.discordapp.com/attachments/611741789237411850/659512520553267201/netradiant_warfork_gamepack.zip
59 # Warsow GPL svn https://svn.bountysource.com/wswpack/trunk/netradiant/games/WarsowPack/
60 # Warsow GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/WarsowPack.zip
61
62 #######################################################
63 # Usable packs #
64 #######################################################
65
66 AlienArena GPL svn https://svn.code.sf.net/p/alienarena-cc/code/trunk/tools/netradiant_gamepack/AlienArenaPack
67 DarkPlaces GPL svn svn://svn.icculus.org/gtkradiant-gamepacks/DarkPlacesPack/branches/1.5/
68 Doom3 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Doom3Pack/branches/1.5/
69 ET proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/ETPack/branches/1.5/
70 Heretic2 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Her2Pack/branches/1.5/
71 JediAcademy proprietary git https://gitlab.com/netradiant/gamepacks/jediacademy-mapeditor-support.git
72 JediOutcast proprietary git https://gitlab.com/netradiant/gamepacks/jedioutcast-mapeditor-support.git
73 Kingpin unknown git https://gitlab.com/netradiant/gamepacks/kingpin-mapeditor-support.git
74 Neverball proprietary git https://gitlab.com/netradiant/gamepacks/neverball-mapeditor-support.git
75 Nexuiz GPL gitdir https://git.xonotic.org/icculus/nexuiz.git misc/netradiant-NexuizPack master
76 OpenArena GPL git https://github.com/NeonKnightOA/oagamepack.git
77 Osirion GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/OsirionPack.zip
78 Prey proprietary git https://gitlab.com/netradiant/gamepacks/prey-mapeditor-support.git
79 Q3Rally proprietary svn https://svn.code.sf.net/p/q3rallysa/code/tools/radiant-config/radiant15-netradiant/
80 Quake2 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q2Pack/branches/1.5/
81 Quake3 proprietary git https://gitlab.com/netradiant/gamepacks/quake3-mapeditor-support.git
82 Quake4 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q4Pack/branches/1.5/
83 QuakeLive proprietary git https://gitlab.com/netradiant/gamepacks/quakelive-mapeditor-support.git
84 Quake GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/Quake1Pack.zip
85 Quetoo GPL svn svn://svn.icculus.org/gtkradiant-gamepacks/QuetooPack/branches/1.5/
86 SmokinGuns unknown git https://github.com/smokin-guns/smokinguns-mapeditor-support.git
87 SoF2 unknown git https://gitlab.com/netradiant/gamepacks/sof2-mapeditor-support.git
88 STVEF unknown git https://gitlab.com/netradiant/gamepacks/stvef-mapeditor-support.git
89 Tremulous proprietary git https://gitlab.com/netradiant/gamepacks/tremulous-mapeditor-support.git
90 TurtleArena proprietary git https://github.com/Turtle-Arena/turtle-arena-radiant-pack.git
91 UFOAI proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/UFOAIPack/branches/1.5/
92 Unvanquished BSD git https://github.com/Unvanquished/unvanquished-mapeditor-support.git
93 UrbanTerror unknown git https://gitlab.com/netradiant/gamepacks/urbanterror-mapeditor-support.git
94 Warfork GPL git https://gitlab.com/netradiant/gamepacks/warfork-mapeditor-support.git
95 Warsow GPL git https://github.com/Warsow/NetRadiantPack.git
96 Wolf proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/WolfPack/branches/1.5/
97 WoP proprietary git https://github.com/PadWorld-Entertainment/wop-mapeditor-support.git
98 Wrath GPL git https://gitlab.com/netradiant/gamepacks/wrath-mapeditor-support.git
99 Xonotic GPL git https://gitlab.com/xonotic/netradiant-xonoticpack.git
100 ZEQ2Lite unknown git https://gitlab.com/netradiant/gamepacks/zeq2lite-mapeditor-support.git
101 EOF
102 }
103
104 if command -v gsed >/dev/null
105 then
106 SED=gsed
107 elif sed --help >/dev/null 2>&1
108 then
109 SED=sed
110 else
111 printf 'ERROR: GNU sed is missing\n' >&2
112 exit 1
113 fi
114
115 printRealPath ()
116 {
117 if command -v grealpath >/dev/null
118 then
119 grealpath "${1}"
120 elif command -v realpath >/dev/null
121 then
122 realpath "${1}"
123 elif command -v greadlink >/dev/null
124 then
125 # test greadlink first as greadlink has the feature on macos
126 # but readlink only has it on linux, note that it's probably
127 # the same on bsd
128 # note: (g)readlink requires the file to be create first
129 greadlink -f "${1}"
130 elif command -v readlink >/dev/null
131 then
132 # --help and -f options are GNU readlink things
133 if readlink --help >/dev/null 2>&1
134 then
135 readlink -f "${1}"
136 else
137 if ! python -c "import os; print(os.path.realpath('${1}'))"
138 then
139 printf 'ERROR: GNU realpath or other way to compute real path of a file is missing\n' >&2
140 exit 1
141 fi
142 fi
143 fi
144 }
145
146 sanitizeDB () {
147 ${SED} -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
148 | grep -v '^$'
149 }
150
151 inList () {
152 [ "$(grep "^${1}$")" = "${1}" ]
153 }
154
155 printList () {
156 echo "${1}" \
157 | tr ' ' '\n' \
158 | grep -v '^$' \
159 | sort -u
160 }
161
162 dedupeList () {
163 printList "${1}" \
164 | tr '\n' ' ' \
165 | ${SED} -e 's/ $//'
166 }
167
168 printGamePackDB () {
169 printRawDB \
170 | sanitizeDB
171 }
172
173 printLicenseList () {
174 printGamePackDB \
175 | awk '{ print $2 }' \
176 | sort -u
177 }
178
179 printNameList () {
180 printGamePackDB \
181 | awk '{ print $1 }' \
182 | sort -u
183 }
184
185 printNameListByLicense () {
186 local arg_license_list
187 local license_list
188 local license
189
190 arg_license_list="${1}"
191 license_list=''
192
193 for license in ${arg_license_list}
194 do
195 case "${license}" in
196 'none')
197 break
198 ;;
199 'all')
200 license_list="$(printLicenseList)"
201 break
202 ;;
203 'free')
204 license_list="${license_list} ${free_license_list}"
205 ;;
206 *)
207 if printLicenseList | inList "${license}"
208 then
209 license_list="${license_list} ${license}"
210 else
211 printError "unknown license: ${license}"
212 fi
213 ;;
214 esac
215 done
216
217 license_list="$(dedupeList "${license_list}")"
218
219 for license in ${license_list}
220 do
221 printGamePackDB \
222 | awk '$2 == "'"${license}"'"' \
223 | awk '{ print $1 }'
224 done | sort -u
225 }
226
227 printNameListByName () {
228 local argname_list
229 local name_list
230 local name
231
232 argname_list="${1}"
233 name_list=''
234
235 for name in ${argname_list}
236 do
237 case "${name}" in
238 'none')
239 break
240 ;;
241 'all')
242 name_list="$(printNameList)"
243 break
244 ;;
245 *)
246 if printNameList | inList "${name}"
247 then
248 name_list="${name_list} ${name}"
249 else
250 printError "unknown name: ${name}"
251 fi
252 ;;
253 esac
254 done
255
256 name_list="$(dedupeList "${name_list}")"
257
258 for name in ${name_list}
259 do
260 printGamePackDB \
261 | awk '$1 == "'"${name}"'"' \
262 | awk '{ print $1 }'
263 done
264 }
265
266 printPackLine () {
267 local name
268
269 name="${1}"
270
271 printGamePackDB \
272 | awk '$1 == "'"${name}"'"'
273 }
274
275 getValue () {
276 local name
277 local key
278
279 name="${1}"
280 key="${2}"
281
282 printPackLine "${name}" \
283 | awk '{ print $'"${key}"' }'
284 }
285
286 downloadExtraUrls ()
287 {
288 if [ -f 'extra-urls.txt' ]
289 then
290 local line
291 while read line
292 do
293 local extra_file="$(echo "${line}" | cut -f1 -d$'\t')"
294 local extra_url="$(echo "${line}" | cut -f2 -d$'\t')"
295 ${WGET} -O "${extra_file}" "${extra_url}" < /dev/null
296 done < 'extra-urls.txt'
297 fi
298 }
299
300 downloadPack () {
301 local download_dir
302 local name
303 local license
304 local source_type
305 local source_url
306 local pack
307 local reference
308 local subdir
309
310 download_dir="${1}"
311 name="${2}"
312
313 license="$(getValue "${name}" 2)"
314 source_type="$(getValue "${name}" 3)"
315 source_url="$(getValue "${name}" 4)"
316
317 pack="${name}${pack_suffix}"
318
319 ${MKDIR_P} "${download_dir}"
320
321 (
322 cd "${download_dir}"
323
324 ${ECHO} ''
325 ${ECHO} "Available pack: ${pack}"
326 ${ECHO} " License: ${license}"
327 ${ECHO} " Download via ${source_type} from ${source_url}"
328 ${ECHO} ''
329
330 if [ -d "${download_dir}/${pack}" ]
331 then
332 ${ECHO} "Updating ${name}…"
333 else
334 ${ECHO} "Downloading ${pack}…"
335 fi
336
337 case "${source_type}" in
338 'svn')
339 reference="$(getValue "${name}" 5)"
340 if [ -z "${reference}" ]
341 then
342 reference='HEAD'
343 fi
344
345 if [ -d "${pack}" ]
346 then
347 if [ -d "${pack}/.git" ]
348 then
349 (
350 cd "${pack}"
351 ${GIT} svn fetch
352 )
353 else
354 ${SVN} update -r"${reference}" "${pack}"
355 fi
356 else
357 ${SVN} checkout -r"${reference}" "${source_url}" "${pack}" \
358 || ${GIT} svn clone "${source_url}" "${pack}"
359 fi
360 ;;
361 'zip')
362 ${RM_R} 'zipdownload'
363 ${MKDIR} 'zipdownload'
364 (
365 cd 'zipdownload'
366 ${WGET} "${source_url}"
367 ${UNZIPPER} './'*.zip
368 )
369 ${RM_R} "${pack}"
370 ${MKDIR} "${pack}"
371 if [ -d 'zipdownload/games' ]
372 then
373 ${MV} 'zipdownload/'* "${pack}/"
374 else
375 ${MV} 'zipdownload/'*'/'* "${pack}/"
376 fi
377 ${RM_R} 'zipdownload'
378 ;;
379 'gitdir')
380 local subdir="$(getValue "${name}" 5)"
381 # Only branch for now, we would need --revision support for tag or commit id.
382 local rev="$(getValue "${name}" 6)"
383 ${RM_R} "${pack}"
384 # Requires the source repo to enable uploadpack.allowFilter (gitlab and github do).
385 # Not using --sparse as it enables core.sparseCheckoutCone which matches differently and downloads more files.
386 # Not using --revision as it is not compatible with Ubuntu 24.04 LTS, only branches are supported for now.
387 ${GIT} clone --no-checkout --depth=1 --filter=tree:0 ${rev:+"--branch=${rev}"} "${source_url}" "__${pack}"
388 (
389 cd "__${pack}"
390 ${GIT} config core.sparseCheckout true
391
392 # Default, but in case they change it.
393 ${GIT} config core.sparseCheckoutCone false
394
395 # The git sparse-checkout command is experimental/unstable.
396 echo "${subdir}" > .git/info/sparse-checkout
397
398 ${GIT} checkout
399 )
400 ${MV} "__${pack}/${subdir}" "${pack}"
401 ${RM_R} "__${pack}"
402 ;;
403 'git')
404 if [ -d "${pack}" ]
405 then
406 (
407 cd "${pack}"
408 ${GIT} pull
409 )
410 else
411 ${GIT} clone --depth=1 "${source_url}" "${pack}"
412 fi
413 ;;
414 esac
415
416 if [ -d "${pack}" ]
417 then
418 (
419 cd "${pack}"
420 downloadExtraUrls
421 )
422 fi
423
424 )
425 }
426
427 downloadPackList () {
428 local download_dir
429 local name_list
430
431 download_dir="${1}"
432 name_list="${2}"
433
434 for name in ${name_list}
435 do
436 if printNameList | inList "${name}"
437 then
438 downloadPack "${download_dir}" "${name}"
439 else
440 printError "unknown name: ${name}"
441 fi
442 done
443 }
444
445 installPack () {
446 local download_dir
447 local install_dir
448 local name
449 local pack
450 local path
451 local game_file
452 local game_dir
453
454 download_dir="${1}"
455 install_dir="${2}"
456 name="${3}"
457
458 pack="${name}${pack_suffix}"
459
460 ${MKDIR_P} "${install_dir}/${games_dir}"
461
462 # Some per-game workaround for malformed gamepack
463 case "${name}" in
464 'Wolf')
465 pack="${pack}/bin"
466 ;;
467 esac
468
469 # Game packs built with mkeditorpacks
470 if [ -d "${download_dir}/${pack}/build/netradiant" ]
471 then
472 pack="${pack}/build/netradiant"
473 elif [ -d "${download_dir}/${pack}/netradiant" ]
474 # Other known layout
475 then
476 pack="${pack}/netradiant"
477 fi
478
479 path="${download_dir}/${pack}"
480
481 for game_file in "${path}/${games_dir}/"*'.game'
482 do
483 if [ x"${game_file}" != x"${path}/"*'.game' ]
484 then
485 ${CP} "${game_file}" "${real_install_dir}/${games_dir}/"
486 fi
487 done
488
489 for game_dir in "${path}/"*'.game'
490 do
491 if [ x"${game_dir}" != x"${path}/"*'.game' ]
492 then
493 ${CP_R} "${game_dir}" "${real_install_dir}/"
494 fi
495 done
496 }
497
498 installPackList () {
499 local download_dir
500 local install_dir
501 local name_list
502
503 download_dir="${1}"
504 install_dir="${2}"
505 name_list="${3}"
506
507 for name in ${name_list}
508 do
509 if printNameList | inList "${name}"
510 then
511 installPack "${download_dir}" "${install_dir}" "${name}"
512 else
513 printError "unknown name: ${name}"
514 fi
515 done
516 }
517
518 printError () {
519 printf 'ERROR: %s\n' "${1}" >&2
520 exit 1
521 }
522
523 printHelp () {
524 local tab
525 local prog_name
526
527 tab="$(printf '\t')"
528 prog_name='gamepack-manager'
529
530 cat <<-EOF
531 Usage: ${prog_name} [OPTION] [SELECTION <ARGUMENTS>] [ACTION]
532
533 OPTIONS:
534 ${tab}-dd, --download-dir DIRNAME
535 ${tab}${tab}store downloaded games to DIRNAME (default: ${default_download_dir})
536
537 ${tab}-id, --install-dir DIRNAME
538 ${tab}${tab}store installed games to DIRNAME (default: ${default_install_dir})
539
540 SELECTIONS:
541 ${tab}-n, --name NAMES…
542 ${tab}${tab}select games by name (default: none)
543 ${tab}${tab}special keyword: all, none
544 ${tab}${tab}available games:
545 $(printNameList | ${SED} -e 's/^/\t\t\t/')
546
547 ${tab}-l, --license LICENSES…
548 ${tab}${tab}select games by license (default: none)
549 ${tab}${tab}special keyword: free, all, none
550 ${tab}${tab}available licenses:
551 $(printLicenseList | ${SED} -e 's/^/\t\t\t/')
552
553 ACTIONS:
554 ${tab}-ln, --list-names
555 ${tab}${tab}list all game names
556
557 ${tab}-ll, --list-licenses
558 ${tab}${tab}list all game licenses
559
560 ${tab}-ls, --list-selected
561 ${tab}${tab}list selected games
562
563 ${tab}-d, --download
564 ${tab}${tab}download selected games
565
566 ${tab}-i, --install
567 ${tab}${tab}install selected games
568
569 ${tab}-h, --help
570 ${tab}${tab}print this help
571
572 Examples:
573 ${tab}${prog_name} --license GPL BSD --list-selected
574 ${tab}${prog_name} --license GPL BSD --download --install
575
576 ${tab}${prog_name} --name all --list-selected
577 ${tab}${prog_name} --name all --download --install
578
579 EOF
580
581 exit
582 }
583
584 option_list=''
585
586 list_selected='false'
587 list_licenses='false'
588 list_names='false'
589
590 download_packs='false'
591 install_packs='false'
592
593 mkdir_download='false'
594 mkdir_install='false'
595
596 by_license='false'
597 by_name='false'
598
599 arg_type=''
600 selected_list=''
601 license_list=''
602 name_list=''
603 install_dir=''
604
605 while ! [ -z "${1}" ]
606 do
607
608 if printList "${option_list}" | inList "${1}"
609 then
610 printError "option called more than once: ${1}"
611 fi
612
613 if echo "${@}" | tr ' ' '\n' | inList '--help'
614 then
615 printHelp
616 elif echo "${@}" | tr ' ' '\n' | inList '-h'
617 then
618 printHelp
619 fi
620
621 case "${1}" in
622 '--list-names'|'-ln')
623 arg_type=''
624 list_names='true'
625 option_list="${option_list} ${1}"
626 ;;
627 '--list-licenses'|'-ll')
628 arg_type=''
629 list_licenses='true'
630 option_list="${option_list} ${1}"
631 ;;
632 '--list-selected'|'-ls')
633 arg_type=''
634 list_selected='true'
635 option_list="${option_list} ${1}"
636 ;;
637 '--download'|'-d')
638 arg_type=''
639 download_packs='true'
640 mkdir_download='true'
641 option_list="${option_list} ${1}"
642 ;;
643 '--install'|'-i')
644 arg_type=''
645 install_packs='true'
646 mkdir_download='true'
647 mkdir_install='true'
648 option_list="${option_list} ${1}"
649 ;;
650 '--license'|'-l')
651 by_license='true'
652 arg_type='pack-license'
653 option_list="${option_list} ${1}"
654 ;;
655 '--name'|'-n')
656 by_name='true'
657 arg_type='pack-name'
658 option_list="${option_list} ${1}"
659 ;;
660 '--download-dir'|'-dd')
661 arg_type='download-dir'
662 option_list="${option_list} ${1}"
663 ;;
664 '--install-dir'|'-id')
665 arg_type='install-dir'
666 option_list="${option_list} ${1}"
667 ;;
668 '-'*)
669 printError "unknown option: ${1}"
670 ;;
671 *)
672 case "${arg_type}" in
673 'pack-name')
674 name_list="${name_list} ${1}"
675 ;;
676 'pack-license')
677 license_list="${license_list} ${1}"
678 ;;
679 'download-dir')
680 if [ -z "${download_dir}" ]
681 then
682 download_dir="${1}"
683 else
684 printError "more than one download dir: ${1}"
685 fi
686 ;;
687 'install-dir')
688 if [ -z "${install_dir}" ]
689 then
690 install_dir="${1}"
691 else
692 printError "more than one install dir: ${1}"
693 fi
694 ;;
695 *)
696 printError "misplaced argument: ${1}"
697 ;;
698 esac
699 ;;
700 esac
701
702 shift
703 done
704
705 # compatibility with legacy Makefile
706 if [ "${DOWNLOAD_GAMEPACKS}" = 'yes' ]
707 then
708 if ! [ -z "${DOWNLOADDIR}" ]
709 then
710 download_dir="${DOWNLOADDIR}"
711 fi
712
713 if ! [ -z "${INSTALLDIR}" ]
714 then
715 install_dir="${INSTALLDIR}"
716 fi
717
718 license_list='free'
719 by_license='true'
720
721 download_packs='true'
722 mkdir_download='true'
723
724 install_packs='true'
725 mkdir_install='true'
726 fi
727
728 if [ -z "${download_dir}" ]
729 then
730 download_dir="${default_download_dir}"
731 fi
732
733 if [ -z "${install_dir}" ]
734 then
735 install_dir="${default_install_dir}"
736 fi
737
738 if "${by_name}"
739 then
740 selected_list="${selected_list} $(printNameListByName "${name_list}")"
741 fi
742
743 if "${by_license}"
744 then
745 selected_list="${selected_list} $(printNameListByLicense "${license_list}")"
746 fi
747
748 selected_list="$(dedupeList "${selected_list}")"
749
750 if "${mkdir_download}"
751 then
752 ${MKDIR_P} "${download_dir}"
753 real_download_dir="$(printRealPath "${download_dir}")"
754 fi
755
756 if "${mkdir_install}"
757 then
758 ${MKDIR_P} "${install_dir}"
759 real_install_dir="$(printRealPath "${install_dir}")"
760 fi
761
762 if "${list_names}"
763 then
764 printNameList
765 fi
766
767 if "${list_licenses}"
768 then
769 printLicenseList
770 fi
771
772 if "${list_selected}"
773 then
774 printList "${selected_list}"
775 fi
776
777 if "${download_packs}"
778 then
779 downloadPackList "${real_download_dir}" "${selected_list}"
780 fi
781
782 if "${install_packs}"
783 then
784 installPackList "${real_download_dir}" "${real_install_dir}" "${selected_list}"
785 fi
786
787 #EOF