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 Xonotic GPL git https://gitlab.com/xonotic/netradiant-xonoticpack.git
87 if command -v gsed >/dev/null
90 elif sed --help >/dev/null 2>&1
94 printf 'ERROR: GNU sed is missing\n' >&2
100 if command -v grealpath >/dev/null
103 elif command -v realpath >/dev/null
106 elif command -v greadlink >/dev/null
108 # test greadlink first as greadlink has the feature on macos
109 # but readlink only has it on linux, note that it's probably
111 # note: (g)readlink requires the file to be create first
113 elif command -v readlink >/dev/null
115 # --help and -f options are GNU readlink things
116 if readlink --help >/dev/null 2>&1
120 if ! python -c "import os; print(os.path.realpath('${1}'))"
122 printf 'ERROR: GNU realpath or other way to compute real path of a file is missing\n' >&2
130 ${SED} -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
135 [ "$(grep "^${1}$")" = "${1}" ]
156 printLicenseList () {
158 | awk '{ print $2 }' \
164 | awk '{ print $1 }' \
168 printNameListByLicense () {
169 local arg_license_list
173 arg_license_list="${1}"
176 for license in ${arg_license_list}
183 license_list="$(printLicenseList)"
187 license_list="${license_list} ${free_license_list}"
190 if printLicenseList | inList "${license}"
192 license_list="${license_list} ${license}"
194 printError "unknown license: ${license}"
200 license_list="$(dedupeList "${license_list}")"
202 for license in ${license_list}
205 | awk '$2 == "'"${license}"'"' \
210 printNameListByName () {
218 for name in ${argname_list}
226 name_list="$(printNameList)"
230 if printNameList | inList "${name}"
233 name_list="${name_list} ${name}"
235 printError "unknown name: ${name}"
241 name_list="$(dedupeList "${name_list}")"
243 for name in ${name_list}
246 | awk '$1 == "'"${name}"'"' \
257 | awk '$1 == "'"${name}"'"'
267 printPackLine "${name}" \
268 | awk '{ print $'"${key}"' }'
273 if [ -f 'extra-urls.txt' ]
275 while IFS=' ' read -r extra_file extra_url
278 ${WGET} -O "${extra_file}" "${extra_url}"
280 done < 'extra-urls.txt'
298 license="$(getValue "${name}" '2')"
299 source_type="$(getValue "${name}" '3')"
300 source_url="$(getValue "${name}" '4')"
302 pack="${name}${pack_suffix}"
304 ${MKDIR_P} "${download_dir}"
310 ${ECHO} "Available pack: ${pack}"
311 ${ECHO} " License: ${license}"
312 ${ECHO} " Download via ${source_type} from ${source_url}"
315 if [ -d "${download_dir}/${pack}" ]
317 ${ECHO} "Updating ${name}…"
319 ${ECHO} "Downloading ${pack}…"
322 case "${source_type}" in
324 reference="$(getValue "${name}" '5')"
325 if [ -z "${reference}" ]
332 if [ -d "${pack}/.git" ]
339 ${SVN} update -r"${reference}" "${pack}"
342 ${SVN} checkout -r"${reference}" "${source_url}" "${pack}" \
343 || ${GIT} svn clone "${source_url}" "${pack}"
347 ${RM_R} 'zipdownload'
348 ${MKDIR} 'zipdownload'
351 ${WGET} "${source_url}"
352 ${UNZIPPER} './'*.zip
356 if [ -d 'zipdownload/games' ]
358 ${MV} 'zipdownload/'* "${pack}/"
360 ${MV} 'zipdownload/'*'/'* "${pack}/"
362 ${RM_R} 'zipdownload'
365 local subdir="$(getValue "${name}" '5')"
366 local branch="$(getValue "${name}" '6')"
368 ${GIT} archive --remote="${source_url}" --prefix="${pack}/" "${branch}":"${subdir}" \
379 ${GIT} clone "${source_url}" "${pack}"
395 downloadPackList () {
402 for name in ${name_list}
404 if printNameList | inList "${name}"
406 downloadPack "${download_dir}" "${name}"
408 printError "unknown name: ${name}"
426 pack="${name}${pack_suffix}"
428 ${MKDIR_P} "${install_dir}/${games_dir}"
430 # Some per-game workaround for malformed gamepack
443 # mkeditorpacks-based gamepack
444 if [ -d "${download_dir}/${pack}/build/netradiant" ]
446 pack="${pack}/build/netradiant"
449 path="${download_dir}/${pack}"
451 for game_file in "${path}/${games_dir}/"*'.game'
453 if [ x"${game_file}" != x"${path}/"*'.game' ]
455 ${CP} "${game_file}" "${real_install_dir}/${games_dir}/"
459 for game_dir in "${path}/"*'.game'
461 if [ x"${game_dir}" != x"${path}/"*'.game' ]
463 ${CP_R} "${game_dir}" "${real_install_dir}/"
477 for name in ${name_list}
479 if printNameList | inList "${name}"
481 installPack "${download_dir}" "${install_dir}" "${name}"
483 printError "unknown name: ${name}"
489 printf 'ERROR: %s\n' "${1}" >&2
498 prog_name='gamepack-manager'
501 Usage: ${prog_name} [OPTION] [SELECTION <ARGUMENTS>] [ACTION]
504 ${tab}-dd, --download-dir DIRNAME
505 ${tab}${tab}store downloaded games to DIRNAME (default: ${default_download_dir})
507 ${tab}-id, --install-dir DIRNAME
508 ${tab}${tab}store installed games to DIRNAME (default: ${default_install_dir})
511 ${tab}-n, --name NAMES…
512 ${tab}${tab}select games by name (default: none)
513 ${tab}${tab}special keyword: all, none
514 ${tab}${tab}available games:
515 $(printNameList | ${SED} -e 's/^/\t\t\t/')
517 ${tab}-l, --license LICENSES…
518 ${tab}${tab}select games by license (default: none)
519 ${tab}${tab}special keyword: free, all, none
520 ${tab}${tab}available licenses:
521 $(printLicenseList | ${SED} -e 's/^/\t\t\t/')
524 ${tab}-ln, --list-names
525 ${tab}${tab}list all game names
527 ${tab}-ll, --list-licenses
528 ${tab}${tab}list all game licenses
531 ${tab}${tab}list selected games
534 ${tab}${tab}download selected games
537 ${tab}${tab}install selected games
540 ${tab}${tab}print this help
543 ${tab}${prog_name} --license GPL BSD --download --install
552 list_selected='false'
553 list_licenses='false'
556 download_packs='false'
557 install_packs='false'
559 mkdir_download='false'
560 mkdir_install='false'
571 while ! [ -z "${1}" ]
574 if printList "${option_list}" | inList "${1}"
576 printError "option called more than once: ${1}"
579 if echo "${@}" | tr ' ' '\n' | inList '--help'
582 elif echo "${@}" | tr ' ' '\n' | inList '-h'
588 '--list-licenses'|'-ll')
591 option_list="${option_list} ${1}"
593 '--list-names'|'-ln')
596 option_list="${option_list} ${1}"
598 '--list-selected'|'-ls')
601 option_list="${option_list} ${1}"
605 download_packs='true'
606 mkdir_download='true'
607 option_list="${option_list} ${1}"
612 mkdir_download='true'
614 option_list="${option_list} ${1}"
618 arg_type='pack-license'
619 option_list="${option_list} ${1}"
624 option_list="${option_list} ${1}"
626 '--download-dir'|'-dd')
627 arg_type='download-dir'
628 option_list="${option_list} ${1}"
630 '--install-dir'|'-id')
631 arg_type='install-dir'
632 option_list="${option_list} ${1}"
635 printError "unknown option: ${1}"
638 case "${arg_type}" in
640 license_list="${license_list} ${1}"
643 name_list="${name_list} ${1}"
646 if [ -z "${download_dir}" ]
650 printError "more than one download dir: ${1}"
654 if [ -z "${install_dir}" ]
658 printError "more than one install dir: ${1}"
662 printError "misplaced argument: ${1}"
671 # compatibility with legacy Makefile
672 if [ "${DOWNLOAD_GAMEPACKS}" = 'yes' ]
674 if ! [ -z "${DOWNLOADDIR}" ]
676 download_dir="${DOWNLOADDIR}"
679 if ! [ -z "${INSTALLDIR}" ]
681 install_dir="${INSTALLDIR}"
687 download_packs='true'
688 mkdir_download='true'
694 if [ -z "${download_dir}" ]
696 download_dir="${default_download_dir}"
699 if [ -z "${install_dir}" ]
701 install_dir="${default_install_dir}"
706 selected_list="${selected_list} $(printNameListByLicense "${license_list}")"
711 selected_list="${selected_list} $(printNameListByName "${name_list}")"
714 selected_list="$(dedupeList "${selected_list}")"
716 if "${mkdir_download}"
718 ${MKDIR_P} "${download_dir}"
719 real_download_dir="$(printRealPath "${download_dir}")"
722 if "${mkdir_install}"
724 ${MKDIR_P} "${install_dir}"
725 real_install_dir="$(printRealPath "${install_dir}")"
728 if "${list_licenses}"
737 if "${list_selected}"
739 printList "${selected_list}"
742 if "${download_packs}"
744 downloadPackList "${real_download_dir}" "${selected_list}"
747 if "${install_packs}"
749 installPackList "${real_download_dir}" "${real_install_dir}" "${selected_list}"