3 # get usage help this way:
4 # ./gamepack_manager -h
7 : "${CP_R:=cp -r --preserve=timestamps}"
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 Tremulous proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/TremulousPack.zip
75 TurtleArena proprietary git https://github.com/Turtle-Arena/turtle-arena-radiant-pack.git
76 UFOAI proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/UFOAIPack/branches/1.5/
77 Unvanquished BSD git https://github.com/Unvanquished/unvanquished-mapeditor-support.git
78 Warsow GPL git https://github.com/Warsow/NetRadiantPack.git
79 Wolf proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/WolfPack/branches/1.5/
80 Xonotic GPL git https://gitlab.com/xonotic/netradiant-xonoticpack.git
86 if command -v grealpath >/dev/null
89 elif command -v realpath >/dev/null
92 elif command -v greadlink >/dev/null
94 # test greadlink first as greadlink has the feature on macos
95 # but readlink only has it on linux, note that it's probably
97 # note: (g)readlink requires the file to be create first
99 elif command -v readlink >/dev/null
101 # --help and -f options are GNU readlink things
102 if readlink --help >/dev/null 2>&1
106 if ! python -c "import os; print(os.path.realpath('${1}'))"
108 printf 'ERROR: no known way to compute real path of a file' >&2
115 if "${mkdir_download}"
117 ${MKDIR_P} "${download_dir}"
118 real_download_dir="$(printRealPath "${download_dir}")"
122 sed -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
127 [ "$(grep "^${1}$")" = "${1}" ]
148 printLicenseList () {
150 | awk '{ print $2 }' \
156 | awk '{ print $1 }' \
160 printNameListByLicense () {
161 local arg_license_list
165 arg_license_list="${1}"
168 for license in ${arg_license_list}
175 license_list="$(printLicenseList)"
179 license_list="${license_list} ${free_license_list}"
182 if printLicenseList | inList "${license}"
184 license_list="${license_list} ${license}"
186 printError "unknown license: ${license}"
192 license_list="$(dedupeList "${license_list}")"
194 for license in ${license_list}
197 | awk '$2 == "'"${license}"'"' \
202 printNameListByName () {
210 for name in ${argname_list}
218 name_list="$(printNameList)"
222 if printNameList | inList "${name}"
225 name_list="${name_list} ${name}"
227 printError "unknown name: ${name}"
233 name_list="$(dedupeList "${name_list}")"
235 for name in ${name_list}
238 | awk '$1 == "'"${name}"'"' \
249 | awk '$1 == "'"${name}"'"'
259 printPackLine "${name}" \
260 | awk '{ print $'"${key}"' }'
265 if [ -f 'extra-urls.txt' ]
267 while IFS=' ' read -r extra_file extra_url
270 ${WGET} -O "${extra_file}" "${extra_url}"
272 done < 'extra-urls.txt'
290 license="$(getValue "${name}" '2')"
291 source_type="$(getValue "${name}" '3')"
292 source_url="$(getValue "${name}" '4')"
294 pack="${name}${pack_suffix}"
296 ${MKDIR_P} "${download_dir}"
302 ${ECHO} "Available pack: ${pack}"
303 ${ECHO} " License: ${license}"
304 ${ECHO} " Download via ${source_type} from ${source_url}"
307 if [ -d "${download_dir}/${pack}" ]
309 ${ECHO} "Updating ${name}…"
311 ${ECHO} "Downloading ${pack}…"
314 case "${source_type}" in
316 reference="$(getValue "${name}" '5')"
317 if [ -z "${reference}" ]
324 if [ -d "${pack}/.git" ]
331 ${SVN} update -r"${reference}" "${pack}"
334 ${SVN} checkout -r"${reference}" "${source_url}" "${pack}" \
335 || ${GIT} svn clone "${source_url}" "${pack}"
339 ${RM_R} 'zipdownload'
340 ${MKDIR} 'zipdownload'
343 ${WGET} "${source_url}"
344 ${UNZIPPER} './'*.zip
348 ${MV} 'zipdownload/'*'/'* "${pack}/"
349 ${RM_R} 'zipdownload'
352 local subdir="$(getValue "${name}" '5')"
353 local branch="$(getValue "${name}" '6')"
355 ${GIT} archive --remote="${source_url}" --prefix="${pack}/" "${branch}":"${subdir}" \
366 ${GIT} clone "${source_url}" "${pack}"
382 downloadPackList () {
389 for name in ${name_list}
391 if printNameList | inList "${name}"
393 downloadPack "${download_dir}" "${name}"
395 printError "unknown name: ${name}"
413 pack="${name}${pack_suffix}"
415 ${MKDIR_P} "${install_dir}/${games_dir}"
417 # Some per-game workaround for malformed gamepack
430 # mkeditorpacks-based gamepack
431 if [ -d "${download_dir}/${pack}/build/netradiant" ]
433 pack="${pack}/build/netradiant"
436 path="${download_dir}/${pack}"
438 for game_file in "${path}/${games_dir}/"*'.game'
440 if [ x"${game_file}" != x"${path}/"*'.game' ]
442 ${CP} "${game_file}" "${real_install_dir}/${games_dir}/"
446 for game_dir in "${path}/"*'.game'
448 if [ x"${game_dir}" != x"${path}/"*'.game' ]
450 ${CP_R} "${game_dir}" "${real_install_dir}/"
464 for name in ${name_list}
466 if printNameList | inList "${name}"
468 installPack "${download_dir}" "${install_dir}" "${name}"
470 printError "unknown name: ${name}"
476 printf 'ERROR: %s\n' "${1}" >&2
485 prog_name="$(basename "$(readlink -f "${0}")")"
488 Usage: ${prog_name} [OPTION] [SELECTION <ARGUMENTS>] [ACTION]
491 ${tab}-dd, --download-dir DIRNAME
492 ${tab}${tab}store downloaded games to DIRNAME (default: ${default_download_dir})
494 ${tab}-id, --install-dir DIRNAME
495 ${tab}${tab}store installed games to DIRNAME (default: ${default_install_dir})
498 ${tab}-n, --name NAMES…
499 ${tab}${tab}select games by name (default: none)
500 ${tab}${tab}special keyword: all, none
501 ${tab}${tab}available games:
502 $(printNameList | sed -e 's/^/\t\t\t/')
504 ${tab}-l, --license LICENSES…
505 ${tab}${tab}select games by license (default: none)
506 ${tab}${tab}special keyword: free, all, none
507 ${tab}${tab}available licenses:
508 $(printLicenseList | sed -e 's/^/\t\t\t/')
511 ${tab}-ln, --list-names
512 ${tab}${tab}list all game names
514 ${tab}-ll, --list-licenses
515 ${tab}${tab}list all game licenses
518 ${tab}${tab}list selected games
521 ${tab}${tab}download selected games
524 ${tab}${tab}install selected games
527 ${tab}${tab}print this help
530 ${tab}${prog_name} --license GPL BSD --download --install
539 list_selected='false'
540 list_licenses='false'
543 download_packs='false'
544 install_packs='false'
546 mkdir_download='false'
547 mkdir_install='false'
558 while ! [ -z "${1}" ]
561 if printList "${option_list}" | inList "${1}"
563 printError "option called more than once: ${1}"
566 if echo "${@}" | tr ' ' '\n' | inList '--help'
569 elif echo "${@}" | tr ' ' '\n' | inList '-h'
575 '--list-licenses'|'-ll')
578 option_list="${option_list} ${1}"
580 '--list-names'|'-ln')
583 option_list="${option_list} ${1}"
585 '--list-selected'|'-ls')
588 option_list="${option_list} ${1}"
592 download_packs='true'
593 mkdir_download='true'
594 option_list="${option_list} ${1}"
599 mkdir_download='true'
601 option_list="${option_list} ${1}"
605 arg_type='pack-license'
606 option_list="${option_list} ${1}"
611 option_list="${option_list} ${1}"
613 '--download-dir'|'-dd')
614 arg_type='download-dir'
615 option_list="${option_list} ${1}"
617 '--install-dir'|'-id')
618 arg_type='install-dir'
619 option_list="${option_list} ${1}"
622 printError "unknown option: ${1}"
625 case "${arg_type}" in
627 license_list="${license_list} ${1}"
630 name_list="${name_list} ${1}"
633 if [ -z "${download_dir}" ]
637 printError "more than one download dir: ${1}"
641 if [ -z "${install_dir}" ]
645 printError "more than one install dir: ${1}"
649 printError "misplaced argument: ${1}"
658 # compatibility with legacy Makefile
659 if [ "${DOWNLOAD_GAMEPACKS}" = 'yes' ]
661 if ! [ -z "${DOWNLOADDIR}" ]
663 download_dir="${DOWNLOADDIR}"
666 if ! [ -z "${INSTALLDIR}" ]
668 install_dir="${INSTALLDIR}"
674 download_packs='true'
675 mkdir_download='true'
681 if [ -z "${download_dir}" ]
683 download_dir="${default_download_dir}"
686 if [ -z "${install_dir}" ]
688 install_dir="${default_install_dir}"
693 selected_list="${selected_list} $(printNameListByLicense "${license_list}")"
698 selected_list="${selected_list} $(printNameListByName "${name_list}")"
701 selected_list="$(dedupeList "${selected_list}")"
703 if "${mkdir_install}"
705 ${MKDIR_P} "${install_dir}"
706 real_install_dir="$(printRealPath "${install_dir}")"
709 if "${list_licenses}"
718 if "${list_selected}"
720 printList "${selected_list}"
723 if "${download_packs}"
725 downloadPackList "${real_download_dir}" "${selected_list}"
728 if "${install_packs}"
730 installPackList "${real_download_dir}" "${real_install_dir}" "${selected_list}"