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 Kingpin unknown zip http://download.kingpin.info/kingpin/editing/maps/map_editors/NetRadiant/addon/Kingpinpack.zip
64 Neverball proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/NeverballPack.zip
65 Nexuiz GPL gitdir git://git.icculus.org/divverent/nexuiz.git misc/netradiant-NexuizPack master
66 OpenArena GPL git https://github.com/NeonKnightOA/oagamepack.git
67 Osirion GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/OsirionPack.zip
68 Prey proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/PreyPack/trunk/
69 Q3 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q3Pack/trunk/ 29
70 Q3Rally proprietary svn https://svn.code.sf.net/p/q3rallysa/code/tools/radiant-config/radiant15-netradiant/
71 Quake2 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q2Pack/branches/1.5/
72 Quake4 proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/Q4Pack/branches/1.5/
73 Quake GPL zip http://ingar.intranifty.net/files/netradiant/gamepacks/Quake1Pack.zip
74 Quetoo GPL svn svn://svn.icculus.org/gtkradiant-gamepacks/QuetooPack/branches/1.5/
75 SmokinGuns unknown git https://github.com/smokin-guns/smokinguns-mapeditor-support.git
76 Tremulous proprietary zip http://ingar.intranifty.net/files/netradiant/gamepacks/TremulousPack.zip
77 TurtleArena proprietary git https://github.com/Turtle-Arena/turtle-arena-radiant-pack.git
78 UFOAI proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/UFOAIPack/branches/1.5/
79 Unvanquished BSD git https://github.com/Unvanquished/unvanquished-mapeditor-support.git
80 Warsow GPL git https://github.com/Warsow/NetRadiantPack.git
81 Wolf proprietary svn svn://svn.icculus.org/gtkradiant-gamepacks/WolfPack/branches/1.5/
82 Xonotic GPL git https://gitlab.com/xonotic/netradiant-xonoticpack.git
86 if command -v gsed >/dev/null
89 elif sed --help >/dev/null 2>&1
93 printf 'ERROR: GNU sed is missing\n' >&2
99 if command -v grealpath >/dev/null
102 elif command -v realpath >/dev/null
105 elif command -v greadlink >/dev/null
107 # test greadlink first as greadlink has the feature on macos
108 # but readlink only has it on linux, note that it's probably
110 # note: (g)readlink requires the file to be create first
112 elif command -v readlink >/dev/null
114 # --help and -f options are GNU readlink things
115 if readlink --help >/dev/null 2>&1
119 if ! python -c "import os; print(os.path.realpath('${1}'))"
121 printf 'ERROR: GNU realpath or other way to compute real path of a file is missing\n' >&2
129 ${SED} -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
134 [ "$(grep "^${1}$")" = "${1}" ]
155 printLicenseList () {
157 | awk '{ print $2 }' \
163 | awk '{ print $1 }' \
167 printNameListByLicense () {
168 local arg_license_list
172 arg_license_list="${1}"
175 for license in ${arg_license_list}
182 license_list="$(printLicenseList)"
186 license_list="${license_list} ${free_license_list}"
189 if printLicenseList | inList "${license}"
191 license_list="${license_list} ${license}"
193 printError "unknown license: ${license}"
199 license_list="$(dedupeList "${license_list}")"
201 for license in ${license_list}
204 | awk '$2 == "'"${license}"'"' \
209 printNameListByName () {
217 for name in ${argname_list}
225 name_list="$(printNameList)"
229 if printNameList | inList "${name}"
232 name_list="${name_list} ${name}"
234 printError "unknown name: ${name}"
240 name_list="$(dedupeList "${name_list}")"
242 for name in ${name_list}
245 | awk '$1 == "'"${name}"'"' \
256 | awk '$1 == "'"${name}"'"'
266 printPackLine "${name}" \
267 | awk '{ print $'"${key}"' }'
272 if [ -f 'extra-urls.txt' ]
274 while IFS=' ' read -r extra_file extra_url
277 ${WGET} -O "${extra_file}" "${extra_url}"
279 done < 'extra-urls.txt'
297 license="$(getValue "${name}" '2')"
298 source_type="$(getValue "${name}" '3')"
299 source_url="$(getValue "${name}" '4')"
301 pack="${name}${pack_suffix}"
303 ${MKDIR_P} "${download_dir}"
309 ${ECHO} "Available pack: ${pack}"
310 ${ECHO} " License: ${license}"
311 ${ECHO} " Download via ${source_type} from ${source_url}"
314 if [ -d "${download_dir}/${pack}" ]
316 ${ECHO} "Updating ${name}…"
318 ${ECHO} "Downloading ${pack}…"
321 case "${source_type}" in
323 reference="$(getValue "${name}" '5')"
324 if [ -z "${reference}" ]
331 if [ -d "${pack}/.git" ]
338 ${SVN} update -r"${reference}" "${pack}"
341 ${SVN} checkout -r"${reference}" "${source_url}" "${pack}" \
342 || ${GIT} svn clone "${source_url}" "${pack}"
346 ${RM_R} 'zipdownload'
347 ${MKDIR} 'zipdownload'
350 ${WGET} "${source_url}"
351 ${UNZIPPER} './'*.zip
355 if [ -d 'zipdownload/games' ]
357 ${MV} 'zipdownload/'* "${pack}/"
359 ${MV} 'zipdownload/'*'/'* "${pack}/"
361 ${RM_R} 'zipdownload'
364 local subdir="$(getValue "${name}" '5')"
365 local branch="$(getValue "${name}" '6')"
367 ${GIT} archive --remote="${source_url}" --prefix="${pack}/" "${branch}":"${subdir}" \
378 ${GIT} clone "${source_url}" "${pack}"
394 downloadPackList () {
401 for name in ${name_list}
403 if printNameList | inList "${name}"
405 downloadPack "${download_dir}" "${name}"
407 printError "unknown name: ${name}"
425 pack="${name}${pack_suffix}"
427 ${MKDIR_P} "${install_dir}/${games_dir}"
429 # Some per-game workaround for malformed gamepack
442 # mkeditorpacks-based gamepack
443 if [ -d "${download_dir}/${pack}/build/netradiant" ]
445 pack="${pack}/build/netradiant"
448 path="${download_dir}/${pack}"
450 for game_file in "${path}/${games_dir}/"*'.game'
452 if [ x"${game_file}" != x"${path}/"*'.game' ]
454 ${CP} "${game_file}" "${real_install_dir}/${games_dir}/"
458 for game_dir in "${path}/"*'.game'
460 if [ x"${game_dir}" != x"${path}/"*'.game' ]
462 ${CP_R} "${game_dir}" "${real_install_dir}/"
476 for name in ${name_list}
478 if printNameList | inList "${name}"
480 installPack "${download_dir}" "${install_dir}" "${name}"
482 printError "unknown name: ${name}"
488 printf 'ERROR: %s\n' "${1}" >&2
497 prog_name='gamepack-manager'
500 Usage: ${prog_name} [OPTION] [SELECTION <ARGUMENTS>] [ACTION]
503 ${tab}-dd, --download-dir DIRNAME
504 ${tab}${tab}store downloaded games to DIRNAME (default: ${default_download_dir})
506 ${tab}-id, --install-dir DIRNAME
507 ${tab}${tab}store installed games to DIRNAME (default: ${default_install_dir})
510 ${tab}-n, --name NAMES…
511 ${tab}${tab}select games by name (default: none)
512 ${tab}${tab}special keyword: all, none
513 ${tab}${tab}available games:
514 $(printNameList | ${SED} -e 's/^/\t\t\t/')
516 ${tab}-l, --license LICENSES…
517 ${tab}${tab}select games by license (default: none)
518 ${tab}${tab}special keyword: free, all, none
519 ${tab}${tab}available licenses:
520 $(printLicenseList | ${SED} -e 's/^/\t\t\t/')
523 ${tab}-ln, --list-names
524 ${tab}${tab}list all game names
526 ${tab}-ll, --list-licenses
527 ${tab}${tab}list all game licenses
530 ${tab}${tab}list selected games
533 ${tab}${tab}download selected games
536 ${tab}${tab}install selected games
539 ${tab}${tab}print this help
542 ${tab}${prog_name} --license GPL BSD --download --install
551 list_selected='false'
552 list_licenses='false'
555 download_packs='false'
556 install_packs='false'
558 mkdir_download='false'
559 mkdir_install='false'
570 while ! [ -z "${1}" ]
573 if printList "${option_list}" | inList "${1}"
575 printError "option called more than once: ${1}"
578 if echo "${@}" | tr ' ' '\n' | inList '--help'
581 elif echo "${@}" | tr ' ' '\n' | inList '-h'
587 '--list-licenses'|'-ll')
590 option_list="${option_list} ${1}"
592 '--list-names'|'-ln')
595 option_list="${option_list} ${1}"
597 '--list-selected'|'-ls')
600 option_list="${option_list} ${1}"
604 download_packs='true'
605 mkdir_download='true'
606 option_list="${option_list} ${1}"
611 mkdir_download='true'
613 option_list="${option_list} ${1}"
617 arg_type='pack-license'
618 option_list="${option_list} ${1}"
623 option_list="${option_list} ${1}"
625 '--download-dir'|'-dd')
626 arg_type='download-dir'
627 option_list="${option_list} ${1}"
629 '--install-dir'|'-id')
630 arg_type='install-dir'
631 option_list="${option_list} ${1}"
634 printError "unknown option: ${1}"
637 case "${arg_type}" in
639 license_list="${license_list} ${1}"
642 name_list="${name_list} ${1}"
645 if [ -z "${download_dir}" ]
649 printError "more than one download dir: ${1}"
653 if [ -z "${install_dir}" ]
657 printError "more than one install dir: ${1}"
661 printError "misplaced argument: ${1}"
670 # compatibility with legacy Makefile
671 if [ "${DOWNLOAD_GAMEPACKS}" = 'yes' ]
673 if ! [ -z "${DOWNLOADDIR}" ]
675 download_dir="${DOWNLOADDIR}"
678 if ! [ -z "${INSTALLDIR}" ]
680 install_dir="${INSTALLDIR}"
686 download_packs='true'
687 mkdir_download='true'
693 if [ -z "${download_dir}" ]
695 download_dir="${default_download_dir}"
698 if [ -z "${install_dir}" ]
700 install_dir="${default_install_dir}"
705 selected_list="${selected_list} $(printNameListByLicense "${license_list}")"
710 selected_list="${selected_list} $(printNameListByName "${name_list}")"
713 selected_list="$(dedupeList "${selected_list}")"
715 if "${mkdir_download}"
717 ${MKDIR_P} "${download_dir}"
718 real_download_dir="$(printRealPath "${download_dir}")"
721 if "${mkdir_install}"
723 ${MKDIR_P} "${install_dir}"
724 real_install_dir="$(printRealPath "${install_dir}")"
727 if "${list_licenses}"
736 if "${list_selected}"
738 printList "${selected_list}"
741 if "${download_packs}"
743 downloadPackList "${real_download_dir}" "${selected_list}"
746 if "${install_packs}"
748 installPackList "${real_download_dir}" "${real_install_dir}" "${selected_list}"