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 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
84 if command -v gsed >/dev/null
87 elif sed --help >/dev/null 2>&1
91 printf 'ERROR: GNU sed is missing\n' >&2
97 if command -v grealpath >/dev/null
100 elif command -v realpath >/dev/null
103 elif command -v greadlink >/dev/null
105 # test greadlink first as greadlink has the feature on macos
106 # but readlink only has it on linux, note that it's probably
108 # note: (g)readlink requires the file to be create first
110 elif command -v readlink >/dev/null
112 # --help and -f options are GNU readlink things
113 if readlink --help >/dev/null 2>&1
117 if ! python -c "import os; print(os.path.realpath('${1}'))"
119 printf 'ERROR: GNU realpath or other way to compute real path of a file is missing\n' >&2
127 ${SED} -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
132 [ "$(grep "^${1}$")" = "${1}" ]
153 printLicenseList () {
155 | awk '{ print $2 }' \
161 | awk '{ print $1 }' \
165 printNameListByLicense () {
166 local arg_license_list
170 arg_license_list="${1}"
173 for license in ${arg_license_list}
180 license_list="$(printLicenseList)"
184 license_list="${license_list} ${free_license_list}"
187 if printLicenseList | inList "${license}"
189 license_list="${license_list} ${license}"
191 printError "unknown license: ${license}"
197 license_list="$(dedupeList "${license_list}")"
199 for license in ${license_list}
202 | awk '$2 == "'"${license}"'"' \
207 printNameListByName () {
215 for name in ${argname_list}
223 name_list="$(printNameList)"
227 if printNameList | inList "${name}"
230 name_list="${name_list} ${name}"
232 printError "unknown name: ${name}"
238 name_list="$(dedupeList "${name_list}")"
240 for name in ${name_list}
243 | awk '$1 == "'"${name}"'"' \
254 | awk '$1 == "'"${name}"'"'
264 printPackLine "${name}" \
265 | awk '{ print $'"${key}"' }'
270 if [ -f 'extra-urls.txt' ]
272 while IFS=' ' read -r extra_file extra_url
275 ${WGET} -O "${extra_file}" "${extra_url}"
277 done < 'extra-urls.txt'
295 license="$(getValue "${name}" '2')"
296 source_type="$(getValue "${name}" '3')"
297 source_url="$(getValue "${name}" '4')"
299 pack="${name}${pack_suffix}"
301 ${MKDIR_P} "${download_dir}"
307 ${ECHO} "Available pack: ${pack}"
308 ${ECHO} " License: ${license}"
309 ${ECHO} " Download via ${source_type} from ${source_url}"
312 if [ -d "${download_dir}/${pack}" ]
314 ${ECHO} "Updating ${name}…"
316 ${ECHO} "Downloading ${pack}…"
319 case "${source_type}" in
321 reference="$(getValue "${name}" '5')"
322 if [ -z "${reference}" ]
329 if [ -d "${pack}/.git" ]
336 ${SVN} update -r"${reference}" "${pack}"
339 ${SVN} checkout -r"${reference}" "${source_url}" "${pack}" \
340 || ${GIT} svn clone "${source_url}" "${pack}"
344 ${RM_R} 'zipdownload'
345 ${MKDIR} 'zipdownload'
348 ${WGET} "${source_url}"
349 ${UNZIPPER} './'*.zip
353 ${MV} 'zipdownload/'*'/'* "${pack}/"
354 ${RM_R} 'zipdownload'
357 local subdir="$(getValue "${name}" '5')"
358 local branch="$(getValue "${name}" '6')"
360 ${GIT} archive --remote="${source_url}" --prefix="${pack}/" "${branch}":"${subdir}" \
371 ${GIT} clone "${source_url}" "${pack}"
387 downloadPackList () {
394 for name in ${name_list}
396 if printNameList | inList "${name}"
398 downloadPack "${download_dir}" "${name}"
400 printError "unknown name: ${name}"
418 pack="${name}${pack_suffix}"
420 ${MKDIR_P} "${install_dir}/${games_dir}"
422 # Some per-game workaround for malformed gamepack
435 # mkeditorpacks-based gamepack
436 if [ -d "${download_dir}/${pack}/build/netradiant" ]
438 pack="${pack}/build/netradiant"
441 path="${download_dir}/${pack}"
443 for game_file in "${path}/${games_dir}/"*'.game'
445 if [ x"${game_file}" != x"${path}/"*'.game' ]
447 ${CP} "${game_file}" "${real_install_dir}/${games_dir}/"
451 for game_dir in "${path}/"*'.game'
453 if [ x"${game_dir}" != x"${path}/"*'.game' ]
455 ${CP_R} "${game_dir}" "${real_install_dir}/"
469 for name in ${name_list}
471 if printNameList | inList "${name}"
473 installPack "${download_dir}" "${install_dir}" "${name}"
475 printError "unknown name: ${name}"
481 printf 'ERROR: %s\n' "${1}" >&2
490 prog_name="$(basename "$(readlink -f "${0}")")"
493 Usage: ${prog_name} [OPTION] [SELECTION <ARGUMENTS>] [ACTION]
496 ${tab}-dd, --download-dir DIRNAME
497 ${tab}${tab}store downloaded games to DIRNAME (default: ${default_download_dir})
499 ${tab}-id, --install-dir DIRNAME
500 ${tab}${tab}store installed games to DIRNAME (default: ${default_install_dir})
503 ${tab}-n, --name NAMES…
504 ${tab}${tab}select games by name (default: none)
505 ${tab}${tab}special keyword: all, none
506 ${tab}${tab}available games:
507 $(printNameList | ${SED} -e 's/^/\t\t\t/')
509 ${tab}-l, --license LICENSES…
510 ${tab}${tab}select games by license (default: none)
511 ${tab}${tab}special keyword: free, all, none
512 ${tab}${tab}available licenses:
513 $(printLicenseList | ${SED} -e 's/^/\t\t\t/')
516 ${tab}-ln, --list-names
517 ${tab}${tab}list all game names
519 ${tab}-ll, --list-licenses
520 ${tab}${tab}list all game licenses
523 ${tab}${tab}list selected games
526 ${tab}${tab}download selected games
529 ${tab}${tab}install selected games
532 ${tab}${tab}print this help
535 ${tab}${prog_name} --license GPL BSD --download --install
544 list_selected='false'
545 list_licenses='false'
548 download_packs='false'
549 install_packs='false'
551 mkdir_download='false'
552 mkdir_install='false'
563 while ! [ -z "${1}" ]
566 if printList "${option_list}" | inList "${1}"
568 printError "option called more than once: ${1}"
571 if echo "${@}" | tr ' ' '\n' | inList '--help'
574 elif echo "${@}" | tr ' ' '\n' | inList '-h'
580 '--list-licenses'|'-ll')
583 option_list="${option_list} ${1}"
585 '--list-names'|'-ln')
588 option_list="${option_list} ${1}"
590 '--list-selected'|'-ls')
593 option_list="${option_list} ${1}"
597 download_packs='true'
598 mkdir_download='true'
599 option_list="${option_list} ${1}"
604 mkdir_download='true'
606 option_list="${option_list} ${1}"
610 arg_type='pack-license'
611 option_list="${option_list} ${1}"
616 option_list="${option_list} ${1}"
618 '--download-dir'|'-dd')
619 arg_type='download-dir'
620 option_list="${option_list} ${1}"
622 '--install-dir'|'-id')
623 arg_type='install-dir'
624 option_list="${option_list} ${1}"
627 printError "unknown option: ${1}"
630 case "${arg_type}" in
632 license_list="${license_list} ${1}"
635 name_list="${name_list} ${1}"
638 if [ -z "${download_dir}" ]
642 printError "more than one download dir: ${1}"
646 if [ -z "${install_dir}" ]
650 printError "more than one install dir: ${1}"
654 printError "misplaced argument: ${1}"
663 # compatibility with legacy Makefile
664 if [ "${DOWNLOAD_GAMEPACKS}" = 'yes' ]
666 if ! [ -z "${DOWNLOADDIR}" ]
668 download_dir="${DOWNLOADDIR}"
671 if ! [ -z "${INSTALLDIR}" ]
673 install_dir="${INSTALLDIR}"
679 download_packs='true'
680 mkdir_download='true'
686 if [ -z "${download_dir}" ]
688 download_dir="${default_download_dir}"
691 if [ -z "${install_dir}" ]
693 install_dir="${default_install_dir}"
698 selected_list="${selected_list} $(printNameListByLicense "${license_list}")"
703 selected_list="${selected_list} $(printNameListByName "${name_list}")"
706 selected_list="$(dedupeList "${selected_list}")"
708 if "${mkdir_download}"
710 ${MKDIR_P} "${download_dir}"
711 real_download_dir="$(printRealPath "${download_dir}")"
714 if "${mkdir_install}"
716 ${MKDIR_P} "${install_dir}"
717 real_install_dir="$(printRealPath "${install_dir}")"
720 if "${list_licenses}"
729 if "${list_selected}"
731 printList "${selected_list}"
734 if "${download_packs}"
736 downloadPackList "${real_download_dir}" "${selected_list}"
739 if "${install_packs}"
741 installPackList "${real_download_dir}" "${real_install_dir}" "${selected_list}"