Debian Codegraph @

gamepack-manager

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