3 # get usage help this way:
4 # ./gamepack_manager -h
12 : "${MKDIR:=mkdir -v}"
13 : "${MKDIR_P:=mkdir -vp}"
17 : "${UNZIPPER:=unzip}"
21 default_download_dir='build/download'
22 default_install_dir='build'
27 free_license_list='BSD GPL'
31 #######################################################
33 # IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT #
35 # Use two whitespaces or more as column separator #
37 #######################################################
39 #######################################################
41 #######################################################
43 # Quake2World was renamed as Quetoo
44 # Other gamepacks have better version available
46 # OpenArena unknown zip http://ingar.intranifty.net/files/netradiant/gamepacks/OpenArenaPack.zip
47 # Quake proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/QuakePack.zip
48 # Quake2World GPL svn svn://jdolan.dyndns.org/quake2world/trunk/gtkradiant
49 # Tremulous proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/TremulousPack/branches/1.5/
50 # Unvanquished unknown zip http://ingar.intranifty.net/gtkradiant/files/gamepacks/UnvanquishedPack.zip
51 # Warsow GPL svn https://svn.bountysource.com/wswpack/trunk/netradiant/games/WarsowPack/
52 # Warsow GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/WarsowPack.zip
54 #######################################################
56 #######################################################
58 DarkPlaces GPL svn svn://svn.icculus.org/gtkradiant-gamepacks/DarkPlacesPack/branches/1.5/
59 Doom3 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Doom3Pack/branches/1.5/
60 ET proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/ETPack/branches/1.5/
61 Heretic2 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Her2Pack/branches/1.5/
62 JediAcademy proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/JAPack/branches/1.5/
63 Neverball proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/NeverballPack.zip
64 Nexuiz GPL gitdir git://git.icculus.org/divverent/nexuiz.git misc/netradiant-NexuizPack master
65 OpenArena GPL git https://github.com/NeonKnightOA/oagamepack.git
66 Osirion GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/OsirionPack.zip
67 Prey proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/PreyPack/trunk/
68 Q3 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q3Pack/trunk/ 29
69 Q3Rally proprietary svn https://svn.code.sf.net/p/q3rallysa/code/tools/radiant-config/radiant15-netradiant/
70 Quake2 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q2Pack/branches/1.5/
71 Quake4 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q4Pack/branches/1.5/
72 Quake GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/Quake1Pack.zip
73 Quetoo GPL svn svn://svn.icculus.org/gtkradiant-gamepacks/QuetooPack/branches/1.5/
74 SmokinGuns unknown git https://github.com/smokin-guns/smokinguns-mapeditor-support.git
75 Tremulous proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/TremulousPack.zip
76 TurtleArena proprietary git https://github.com/Turtle-Arena/turtle-arena-radiant-pack.git
77 UFOAI proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/UFOAIPack/branches/1.5/
78 Unvanquished BSD git https://github.com/Unvanquished/unvanquished-mapeditor-support.git
79 Warsow GPL git https://github.com/Warsow/NetRadiantPack.git
80 Wolf proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/WolfPack/branches/1.5/
81 Xonotic GPL git https://gitlab.com/xonotic/netradiant-xonoticpack.git
85 if command -v gsed >/dev/null
88 elif sed --help >/dev/null 2>&1
92 printf 'ERROR: GNU sed is missing\n' >&2
98 if command -v grealpath >/dev/null
101 elif command -v realpath >/dev/null
104 elif command -v greadlink >/dev/null
106 # test greadlink first as greadlink has the feature on macos
107 # but readlink only has it on linux, note that it's probably
109 # note: (g)readlink requires the file to be create first
111 elif command -v readlink >/dev/null
113 # --help and -f options are GNU readlink things
114 if readlink --help >/dev/null 2>&1
118 if ! python -c "import os; print(os.path.realpath('${1}'))"
120 printf 'ERROR: GNU realpath or other way to compute real path of a file is missing\n' >&2
128 ${SED} -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
133 [ "$(grep "^${1}$")" = "${1}" ]
154 printLicenseList () {
156 | awk '{ print $2 }' \
162 | awk '{ print $1 }' \
166 printNameListByLicense () {
167 local arg_license_list
171 arg_license_list="${1}"
174 for license in ${arg_license_list}
181 license_list="$(printLicenseList)"
185 license_list="${license_list} ${free_license_list}"
188 if printLicenseList | inList "${license}"
190 license_list="${license_list} ${license}"
192 printError "unknown license: ${license}"
198 license_list="$(dedupeList "${license_list}")"
200 for license in ${license_list}
203 | awk '$2 == "'"${license}"'"' \
208 printNameListByName () {
216 for name in ${argname_list}
224 name_list="$(printNameList)"
228 if printNameList | inList "${name}"
231 name_list="${name_list} ${name}"
233 printError "unknown name: ${name}"
239 name_list="$(dedupeList "${name_list}")"
241 for name in ${name_list}
244 | awk '$1 == "'"${name}"'"' \
255 | awk '$1 == "'"${name}"'"'
265 printPackLine "${name}" \
266 | awk '{ print $'"${key}"' }'
271 if [ -f 'extra-urls.txt' ]
273 while IFS=' ' read -r extra_file extra_url
276 ${WGET} -O "${extra_file}" "${extra_url}"
278 done < 'extra-urls.txt'
296 license="$(getValue "${name}" '2')"
297 source_type="$(getValue "${name}" '3')"
298 source_url="$(getValue "${name}" '4')"
300 pack="${name}${pack_suffix}"
302 ${MKDIR_P} "${download_dir}"
308 ${ECHO} "Available pack: ${pack}"
309 ${ECHO} " License: ${license}"
310 ${ECHO} " Download via ${source_type} from ${source_url}"
313 if [ -d "${download_dir}/${pack}" ]
315 ${ECHO} "Updating ${name}…"
317 ${ECHO} "Downloading ${pack}…"
320 case "${source_type}" in
322 reference="$(getValue "${name}" '5')"
323 if [ -z "${reference}" ]
330 if [ -d "${pack}/.git" ]
337 ${SVN} update -r"${reference}" "${pack}"
340 ${SVN} checkout -r"${reference}" "${source_url}" "${pack}" \
341 || ${GIT} svn clone "${source_url}" "${pack}"
345 ${RM_R} 'zipdownload'
346 ${MKDIR} 'zipdownload'
349 ${WGET} "${source_url}"
350 ${UNZIPPER} './'*.zip
354 ${MV} 'zipdownload/'*'/'* "${pack}/"
355 ${RM_R} 'zipdownload'
358 local subdir="$(getValue "${name}" '5')"
359 local branch="$(getValue "${name}" '6')"
361 ${GIT} archive --remote="${source_url}" --prefix="${pack}/" "${branch}":"${subdir}" \
372 ${GIT} clone "${source_url}" "${pack}"
388 downloadPackList () {
395 for name in ${name_list}
397 if printNameList | inList "${name}"
399 downloadPack "${download_dir}" "${name}"
401 printError "unknown name: ${name}"
419 pack="${name}${pack_suffix}"
421 ${MKDIR_P} "${install_dir}/${games_dir}"
423 # Some per-game workaround for malformed gamepack
436 # mkeditorpacks-based gamepack
437 if [ -d "${download_dir}/${pack}/build/netradiant" ]
439 pack="${pack}/build/netradiant"
442 path="${download_dir}/${pack}"
444 for game_file in "${path}/${games_dir}/"*'.game'
446 if [ x"${game_file}" != x"${path}/"*'.game' ]
448 ${CP} "${game_file}" "${real_install_dir}/${games_dir}/"
452 for game_dir in "${path}/"*'.game'
454 if [ x"${game_dir}" != x"${path}/"*'.game' ]
456 ${CP_R} "${game_dir}" "${real_install_dir}/"
470 for name in ${name_list}
472 if printNameList | inList "${name}"
474 installPack "${download_dir}" "${install_dir}" "${name}"
476 printError "unknown name: ${name}"
482 printf 'ERROR: %s\n' "${1}" >&2
491 prog_name='gamepack-manager'
494 Usage: ${prog_name} [OPTION] [SELECTION <ARGUMENTS>] [ACTION]
497 ${tab}-dd, --download-dir DIRNAME
498 ${tab}${tab}store downloaded games to DIRNAME (default: ${default_download_dir})
500 ${tab}-id, --install-dir DIRNAME
501 ${tab}${tab}store installed games to DIRNAME (default: ${default_install_dir})
504 ${tab}-n, --name NAMES…
505 ${tab}${tab}select games by name (default: none)
506 ${tab}${tab}special keyword: all, none
507 ${tab}${tab}available games:
508 $(printNameList | ${SED} -e 's/^/\t\t\t/')
510 ${tab}-l, --license LICENSES…
511 ${tab}${tab}select games by license (default: none)
512 ${tab}${tab}special keyword: free, all, none
513 ${tab}${tab}available licenses:
514 $(printLicenseList | ${SED} -e 's/^/\t\t\t/')
517 ${tab}-ln, --list-names
518 ${tab}${tab}list all game names
520 ${tab}-ll, --list-licenses
521 ${tab}${tab}list all game licenses
524 ${tab}${tab}list selected games
527 ${tab}${tab}download selected games
530 ${tab}${tab}install selected games
533 ${tab}${tab}print this help
536 ${tab}${prog_name} --license GPL BSD --download --install
545 list_selected='false'
546 list_licenses='false'
549 download_packs='false'
550 install_packs='false'
552 mkdir_download='false'
553 mkdir_install='false'
564 while ! [ -z "${1}" ]
567 if printList "${option_list}" | inList "${1}"
569 printError "option called more than once: ${1}"
572 if echo "${@}" | tr ' ' '\n' | inList '--help'
575 elif echo "${@}" | tr ' ' '\n' | inList '-h'
581 '--list-licenses'|'-ll')
584 option_list="${option_list} ${1}"
586 '--list-names'|'-ln')
589 option_list="${option_list} ${1}"
591 '--list-selected'|'-ls')
594 option_list="${option_list} ${1}"
598 download_packs='true'
599 mkdir_download='true'
600 option_list="${option_list} ${1}"
605 mkdir_download='true'
607 option_list="${option_list} ${1}"
611 arg_type='pack-license'
612 option_list="${option_list} ${1}"
617 option_list="${option_list} ${1}"
619 '--download-dir'|'-dd')
620 arg_type='download-dir'
621 option_list="${option_list} ${1}"
623 '--install-dir'|'-id')
624 arg_type='install-dir'
625 option_list="${option_list} ${1}"
628 printError "unknown option: ${1}"
631 case "${arg_type}" in
633 license_list="${license_list} ${1}"
636 name_list="${name_list} ${1}"
639 if [ -z "${download_dir}" ]
643 printError "more than one download dir: ${1}"
647 if [ -z "${install_dir}" ]
651 printError "more than one install dir: ${1}"
655 printError "misplaced argument: ${1}"
664 # compatibility with legacy Makefile
665 if [ "${DOWNLOAD_GAMEPACKS}" = 'yes' ]
667 if ! [ -z "${DOWNLOADDIR}" ]
669 download_dir="${DOWNLOADDIR}"
672 if ! [ -z "${INSTALLDIR}" ]
674 install_dir="${INSTALLDIR}"
680 download_packs='true'
681 mkdir_download='true'
687 if [ -z "${download_dir}" ]
689 download_dir="${default_download_dir}"
692 if [ -z "${install_dir}" ]
694 install_dir="${default_install_dir}"
699 selected_list="${selected_list} $(printNameListByLicense "${license_list}")"
704 selected_list="${selected_list} $(printNameListByName "${name_list}")"
707 selected_list="$(dedupeList "${selected_list}")"
709 if "${mkdir_download}"
711 ${MKDIR_P} "${download_dir}"
712 real_download_dir="$(printRealPath "${download_dir}")"
715 if "${mkdir_install}"
717 ${MKDIR_P} "${install_dir}"
718 real_install_dir="$(printRealPath "${install_dir}")"
721 if "${list_licenses}"
730 if "${list_selected}"
732 printList "${selected_list}"
735 if "${download_packs}"
737 downloadPackList "${real_download_dir}" "${selected_list}"
740 if "${install_packs}"
742 installPackList "${real_download_dir}" "${real_install_dir}" "${selected_list}"