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 AlienArena GPL svn https://svn.code.sf.net/p/alienarena-cc/code/trunk/tools/netradiant_gamepack/AlienArenaPack
59 DarkPlaces GPL svn svn://svn.icculus.org/gtkradiant-gamepacks/DarkPlacesPack/branches/1.5/
60 Doom3 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Doom3Pack/branches/1.5/
61 ET proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/ETPack/branches/1.5/
62 Heretic2 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Her2Pack/branches/1.5/
63 JediAcademy proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/JAPack/branches/1.5/
64 Kingpin unknown zip http://download.kingpin.info/kingpin/editing/maps/map_editors/NetRadiant/addon/Kingpinpack.zip
65 Neverball proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/NeverballPack.zip
66 Nexuiz GPL gitdir git://git.icculus.org/divverent/nexuiz.git misc/netradiant-NexuizPack master
67 OpenArena GPL git https://github.com/NeonKnightOA/oagamepack.git
68 Osirion GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/OsirionPack.zip
69 Prey proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/PreyPack/trunk/
70 Q3 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q3Pack/trunk/ 29
71 Q3Rally proprietary svn https://svn.code.sf.net/p/q3rallysa/code/tools/radiant-config/radiant15-netradiant/
72 Quake2 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q2Pack/branches/1.5/
73 Quake4 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q4Pack/branches/1.5/
74 Quake GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/Quake1Pack.zip
75 Quetoo GPL svn svn://svn.icculus.org/gtkradiant-gamepacks/QuetooPack/branches/1.5/
76 SmokinGuns unknown git https://github.com/smokin-guns/smokinguns-mapeditor-support.git
77 Tremulous proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/TremulousPack.zip
78 TurtleArena proprietary git https://github.com/Turtle-Arena/turtle-arena-radiant-pack.git
79 UFOAI proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/UFOAIPack/branches/1.5/
80 Unvanquished BSD git https://github.com/Unvanquished/unvanquished-mapeditor-support.git
81 Warsow GPL git https://github.com/Warsow/NetRadiantPack.git
82 Wolf proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/WolfPack/branches/1.5/
83 WoP proprietary git https://github.com/PadWorld-Entertainment/wop-mapeditor-support.git
84 Xonotic GPL git https://gitlab.com/xonotic/netradiant-xonoticpack.git
88 if command -v gsed >/dev/null
91 elif sed --help >/dev/null 2>&1
95 printf 'ERROR: GNU sed is missing\n' >&2
101 if command -v grealpath >/dev/null
104 elif command -v realpath >/dev/null
107 elif command -v greadlink >/dev/null
109 # test greadlink first as greadlink has the feature on macos
110 # but readlink only has it on linux, note that it's probably
112 # note: (g)readlink requires the file to be create first
114 elif command -v readlink >/dev/null
116 # --help and -f options are GNU readlink things
117 if readlink --help >/dev/null 2>&1
121 if ! python -c "import os; print(os.path.realpath('${1}'))"
123 printf 'ERROR: GNU realpath or other way to compute real path of a file is missing\n' >&2
131 ${SED} -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
136 [ "$(grep "^${1}$")" = "${1}" ]
157 printLicenseList () {
159 | awk '{ print $2 }' \
165 | awk '{ print $1 }' \
169 printNameListByLicense () {
170 local arg_license_list
174 arg_license_list="${1}"
177 for license in ${arg_license_list}
184 license_list="$(printLicenseList)"
188 license_list="${license_list} ${free_license_list}"
191 if printLicenseList | inList "${license}"
193 license_list="${license_list} ${license}"
195 printError "unknown license: ${license}"
201 license_list="$(dedupeList "${license_list}")"
203 for license in ${license_list}
206 | awk '$2 == "'"${license}"'"' \
211 printNameListByName () {
219 for name in ${argname_list}
227 name_list="$(printNameList)"
231 if printNameList | inList "${name}"
234 name_list="${name_list} ${name}"
236 printError "unknown name: ${name}"
242 name_list="$(dedupeList "${name_list}")"
244 for name in ${name_list}
247 | awk '$1 == "'"${name}"'"' \
258 | awk '$1 == "'"${name}"'"'
268 printPackLine "${name}" \
269 | awk '{ print $'"${key}"' }'
274 if [ -f 'extra-urls.txt' ]
276 while IFS=' ' read -r extra_file extra_url
279 ${WGET} -O "${extra_file}" "${extra_url}"
281 done < 'extra-urls.txt'
299 license="$(getValue "${name}" '2')"
300 source_type="$(getValue "${name}" '3')"
301 source_url="$(getValue "${name}" '4')"
303 pack="${name}${pack_suffix}"
305 ${MKDIR_P} "${download_dir}"
311 ${ECHO} "Available pack: ${pack}"
312 ${ECHO} " License: ${license}"
313 ${ECHO} " Download via ${source_type} from ${source_url}"
316 if [ -d "${download_dir}/${pack}" ]
318 ${ECHO} "Updating ${name}…"
320 ${ECHO} "Downloading ${pack}…"
323 case "${source_type}" in
325 reference="$(getValue "${name}" '5')"
326 if [ -z "${reference}" ]
333 if [ -d "${pack}/.git" ]
340 ${SVN} update -r"${reference}" "${pack}"
343 ${SVN} checkout -r"${reference}" "${source_url}" "${pack}" \
344 || ${GIT} svn clone "${source_url}" "${pack}"
348 ${RM_R} 'zipdownload'
349 ${MKDIR} 'zipdownload'
352 ${WGET} "${source_url}"
353 ${UNZIPPER} './'*.zip
357 if [ -d 'zipdownload/games' ]
359 ${MV} 'zipdownload/'* "${pack}/"
361 ${MV} 'zipdownload/'*'/'* "${pack}/"
363 ${RM_R} 'zipdownload'
366 local subdir="$(getValue "${name}" '5')"
367 local branch="$(getValue "${name}" '6')"
369 ${GIT} archive --remote="${source_url}" --prefix="${pack}/" "${branch}":"${subdir}" \
380 ${GIT} clone "${source_url}" "${pack}"
396 downloadPackList () {
403 for name in ${name_list}
405 if printNameList | inList "${name}"
407 downloadPack "${download_dir}" "${name}"
409 printError "unknown name: ${name}"
427 pack="${name}${pack_suffix}"
429 ${MKDIR_P} "${install_dir}/${games_dir}"
431 # Some per-game workaround for malformed gamepack
444 if [ -d "${download_dir}/${pack}/build/netradiant" ]
446 # mkeditorpacks-based gamepack
447 pack="${pack}/build/netradiant"
448 elif [ -d "${download_dir}/${pack}/netradiant" ]
451 pack="${pack}/netradiant"
454 path="${download_dir}/${pack}"
456 for game_file in "${path}/${games_dir}/"*'.game'
458 if [ x"${game_file}" != x"${path}/"*'.game' ]
460 ${CP} "${game_file}" "${real_install_dir}/${games_dir}/"
464 for game_dir in "${path}/"*'.game'
466 if [ x"${game_dir}" != x"${path}/"*'.game' ]
468 ${CP_R} "${game_dir}" "${real_install_dir}/"
482 for name in ${name_list}
484 if printNameList | inList "${name}"
486 installPack "${download_dir}" "${install_dir}" "${name}"
488 printError "unknown name: ${name}"
494 printf 'ERROR: %s\n' "${1}" >&2
503 prog_name='gamepack-manager'
506 Usage: ${prog_name} [OPTION] [SELECTION <ARGUMENTS>] [ACTION]
509 ${tab}-dd, --download-dir DIRNAME
510 ${tab}${tab}store downloaded games to DIRNAME (default: ${default_download_dir})
512 ${tab}-id, --install-dir DIRNAME
513 ${tab}${tab}store installed games to DIRNAME (default: ${default_install_dir})
516 ${tab}-n, --name NAMES…
517 ${tab}${tab}select games by name (default: none)
518 ${tab}${tab}special keyword: all, none
519 ${tab}${tab}available games:
520 $(printNameList | ${SED} -e 's/^/\t\t\t/')
522 ${tab}-l, --license LICENSES…
523 ${tab}${tab}select games by license (default: none)
524 ${tab}${tab}special keyword: free, all, none
525 ${tab}${tab}available licenses:
526 $(printLicenseList | ${SED} -e 's/^/\t\t\t/')
529 ${tab}-ln, --list-names
530 ${tab}${tab}list all game names
532 ${tab}-ll, --list-licenses
533 ${tab}${tab}list all game licenses
536 ${tab}${tab}list selected games
539 ${tab}${tab}download selected games
542 ${tab}${tab}install selected games
545 ${tab}${tab}print this help
548 ${tab}${prog_name} --license GPL BSD --download --install
557 list_selected='false'
558 list_licenses='false'
561 download_packs='false'
562 install_packs='false'
564 mkdir_download='false'
565 mkdir_install='false'
576 while ! [ -z "${1}" ]
579 if printList "${option_list}" | inList "${1}"
581 printError "option called more than once: ${1}"
584 if echo "${@}" | tr ' ' '\n' | inList '--help'
587 elif echo "${@}" | tr ' ' '\n' | inList '-h'
593 '--list-licenses'|'-ll')
596 option_list="${option_list} ${1}"
598 '--list-names'|'-ln')
601 option_list="${option_list} ${1}"
603 '--list-selected'|'-ls')
606 option_list="${option_list} ${1}"
610 download_packs='true'
611 mkdir_download='true'
612 option_list="${option_list} ${1}"
617 mkdir_download='true'
619 option_list="${option_list} ${1}"
623 arg_type='pack-license'
624 option_list="${option_list} ${1}"
629 option_list="${option_list} ${1}"
631 '--download-dir'|'-dd')
632 arg_type='download-dir'
633 option_list="${option_list} ${1}"
635 '--install-dir'|'-id')
636 arg_type='install-dir'
637 option_list="${option_list} ${1}"
640 printError "unknown option: ${1}"
643 case "${arg_type}" in
645 license_list="${license_list} ${1}"
648 name_list="${name_list} ${1}"
651 if [ -z "${download_dir}" ]
655 printError "more than one download dir: ${1}"
659 if [ -z "${install_dir}" ]
663 printError "more than one install dir: ${1}"
667 printError "misplaced argument: ${1}"
676 # compatibility with legacy Makefile
677 if [ "${DOWNLOAD_GAMEPACKS}" = 'yes' ]
679 if ! [ -z "${DOWNLOADDIR}" ]
681 download_dir="${DOWNLOADDIR}"
684 if ! [ -z "${INSTALLDIR}" ]
686 install_dir="${INSTALLDIR}"
692 download_packs='true'
693 mkdir_download='true'
699 if [ -z "${download_dir}" ]
701 download_dir="${default_download_dir}"
704 if [ -z "${install_dir}" ]
706 install_dir="${default_install_dir}"
711 selected_list="${selected_list} $(printNameListByLicense "${license_list}")"
716 selected_list="${selected_list} $(printNameListByName "${name_list}")"
719 selected_list="$(dedupeList "${selected_list}")"
721 if "${mkdir_download}"
723 ${MKDIR_P} "${download_dir}"
724 real_download_dir="$(printRealPath "${download_dir}")"
727 if "${mkdir_install}"
729 ${MKDIR_P} "${install_dir}"
730 real_install_dir="$(printRealPath "${install_dir}")"
733 if "${list_licenses}"
742 if "${list_selected}"
744 printList "${selected_list}"
747 if "${download_packs}"
749 downloadPackList "${real_download_dir}" "${selected_list}"
752 if "${install_packs}"
754 installPackList "${real_download_dir}" "${real_install_dir}" "${selected_list}"