]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - gamepack-manager
library-bundler: rely on gcp instead of cp on macos
[xonotic/netradiant.git] / gamepack-manager
index a7bf9913ca79ec054cf0894f8695a165aebcfb34..4a3f63afd49da9df459d62117311db89e536abeb 100755 (executable)
@@ -3,8 +3,8 @@
 # get usage help this way:
 # ./gamepack_manager -h
 
-: "${CP:=cp -v}"
-: "${CP_R:=cp -r --preserve=timestamps}"
+: "${CP:=cp -va}"
+: "${CP_R:=cp -Rva}"
 : "${GIT:=git}"
 : "${SVN:=svn}"
 : "${WGET:=wget}"
@@ -55,33 +55,79 @@ cat <<\EOF
 # Usable packs                                        #
 #######################################################
 
+AlienArena      GPL          svn     https://svn.code.sf.net/p/alienarena-cc/code/trunk/tools/netradiant_gamepack/AlienArenaPack
 DarkPlaces      GPL          svn     svn://svn.icculus.org/gtkradiant-gamepacks/DarkPlacesPack/branches/1.5/
 Doom3           proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/Doom3Pack/branches/1.5/
 ET              proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/ETPack/branches/1.5/
 Heretic2        proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/Her2Pack/branches/1.5/
 JediAcademy     proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/JAPack/branches/1.5/
+Kingpin         unknown      zip     http://download.kingpin.info/kingpin/editing/maps/map_editors/NetRadiant/addon/Kingpinpack.zip
 Neverball       proprietary  zip     http://ingar.intranifty.net/files/netradiant/gamepacks/NeverballPack.zip
 Nexuiz          GPL          gitdir  git://git.icculus.org/divverent/nexuiz.git misc/netradiant-NexuizPack master
 OpenArena       GPL          git     https://github.com/NeonKnightOA/oagamepack.git
 Osirion         GPL          zip     http://ingar.intranifty.net/files/netradiant/gamepacks/OsirionPack.zip
 Prey            proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/PreyPack/trunk/
 Q3              proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/Q3Pack/trunk/ 29
+Q3Rally         proprietary  svn     https://svn.code.sf.net/p/q3rallysa/code/tools/radiant-config/radiant15-netradiant/
 Quake2          proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/Q2Pack/branches/1.5/
 Quake4          proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/Q4Pack/branches/1.5/
 Quake           GPL          zip     http://ingar.intranifty.net/files/netradiant/gamepacks/Quake1Pack.zip
 Quetoo          GPL          svn     svn://svn.icculus.org/gtkradiant-gamepacks/QuetooPack/branches/1.5/
+SmokinGuns      unknown      git     https://github.com/smokin-guns/smokinguns-mapeditor-support.git
 Tremulous       proprietary  zip     http://ingar.intranifty.net/files/netradiant/gamepacks/TremulousPack.zip
 TurtleArena     proprietary  git     https://github.com/Turtle-Arena/turtle-arena-radiant-pack.git
 UFOAI           proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/UFOAIPack/branches/1.5/
-Unvanquished    BSD          svn     https://github.com/Unvanquished/unvanquished-mapeditor-support.git/trunk/build/netradiant
+Unvanquished    BSD          git     https://github.com/Unvanquished/unvanquished-mapeditor-support.git
 Warsow          GPL          git     https://github.com/Warsow/NetRadiantPack.git
 Wolf            proprietary  svn     svn://svn.icculus.org/gtkradiant-gamepacks/WolfPack/branches/1.5/
 Xonotic         GPL          git     https://gitlab.com/xonotic/netradiant-xonoticpack.git
 EOF
 }
 
+if command -v gsed >/dev/null
+then
+       SED=gsed
+elif sed --help >/dev/null 2>&1
+then
+       SED=sed
+else
+       printf 'ERROR: GNU sed is missing\n' >&2
+       exit 1
+fi
+
+printRealPath ()
+{
+       if command -v grealpath >/dev/null
+       then
+               grealpath "${1}"
+       elif command -v realpath >/dev/null
+       then
+               realpath "${1}"
+       elif command -v greadlink >/dev/null
+       then
+               # test greadlink first as greadlink has the feature on macos
+               # but readlink only has it on linux, note that it's probably
+               # the same on bsd
+               # note: (g)readlink requires the file to be create first
+               greadlink -f "${1}"
+       elif command -v readlink >/dev/null
+       then
+               # --help and -f options are GNU readlink things
+               if readlink --help >/dev/null 2>&1
+               then
+                       readlink -f "${1}"
+               else
+                       if ! python -c "import os; print(os.path.realpath('${1}'))"
+                       then
+                               printf 'ERROR: GNU realpath or other way to compute real path of a file is missing\n' >&2
+                               exit 1
+                       fi
+               fi
+       fi
+}
+
 sanitizeDB () {
-       sed -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
+       ${SED} -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
        | grep -v '^$'
 }
 
@@ -99,7 +145,7 @@ printList () {
 dedupeList () {
        printList "${1}" \
        | tr '\n' ' ' \
-       | sed -e 's/ $//'
+       | ${SED} -e 's/ $//'
 }
 
 printGamePackDB () {
@@ -132,14 +178,14 @@ printNameListByLicense () {
                case "${license}" in
                        'none')
                                break
-                       ;;
+                               ;;
                        'all')
                                license_list="$(printLicenseList)"
                                break
-                       ;;
+                               ;;
                        'free')
                                license_list="${license_list} ${free_license_list}"
-                       ;;
+                               ;;
                        *)
                                if printLicenseList | inList "${license}"
                                then
@@ -147,7 +193,7 @@ printNameListByLicense () {
                                else
                                        printError "unknown license: ${license}"
                                fi
-                       ;;
+                               ;;
                esac
        done
 
@@ -174,12 +220,12 @@ printNameListByName () {
                case "${name}" in
                        'none')
                                break
-                       ;;
+                               ;;
                        'all')
                                local name_list
                                name_list="$(printNameList)"
                                break
-                       ;;
+                               ;;
                        *)
                                if printNameList | inList "${name}"
                                then
@@ -188,7 +234,7 @@ printNameListByName () {
                                else
                                        printError "unknown name: ${name}"
                                fi
-                       ;;
+                               ;;
                esac
        done
 
@@ -224,18 +270,14 @@ getValue () {
 
 downloadExtraUrls ()
 {
-       local dir
-
-       dir="${1}"
-
-       if [ -f "${dir}/extra-urls.txt" ]
+       if [ -f 'extra-urls.txt' ]
        then
-               while IFS='     ' read -r FILE URL
+               while IFS='     ' read -r extra_file extra_url
                do
                        (
-                               ${WGET} -O "${dir}/${FILE}" "${URL}"
+                               ${WGET} -O "${extra_file}" "${extra_url}"
                        ) </dev/null
-               done < "${dir}/extra-urls.txt"
+               done < 'extra-urls.txt'
        fi
 }
 
@@ -285,13 +327,22 @@ downloadPack () {
                                        reference='HEAD'
                                fi
 
-                               if [ -d "${download_dir}/${pack}" ]
+                               if [ -d "${pack}" ]
                                then
-                                       ${SVN} update -r"${reference}" "${pack}"
+                                       if [ -d "${pack}/.git" ]
+                                       then
+                                               (
+                                                       cd "${pack}"
+                                                       ${GIT} svn fetch
+                                               )
+                                       else
+                                               ${SVN} update -r"${reference}" "${pack}"
+                                       fi
                                else
-                                       ${SVN} checkout -r"${reference}" "${source_url}" "${pack}"
+                                       ${SVN} checkout -r"${reference}" "${source_url}" "${pack}" \
+                                       || ${GIT} svn clone "${source_url}" "${pack}"
                                fi
-                       ;;
+                               ;;
                        'zip')
                                ${RM_R} 'zipdownload'
                                ${MKDIR} 'zipdownload'
@@ -302,18 +353,23 @@ downloadPack () {
                                )
                                ${RM_R} "${pack}"
                                ${MKDIR} "${pack}"
-                               ${MV} 'zipdownload/'*'/'* "${pack}/"
+                               if [ -d 'zipdownload/games' ]
+                               then
+                                       ${MV} 'zipdownload/'* "${pack}/"
+                               else
+                                       ${MV} 'zipdownload/'*'/'* "${pack}/"
+                               fi
                                ${RM_R} 'zipdownload'
-                       ;;
+                               ;;
                        'gitdir')
-                               subdir="$(getValue "${name}" '5')"
-                               branch="$(getValue "${name}" '6')"
+                               local subdir="$(getValue "${name}" '5')"
+                               local branch="$(getValue "${name}" '6')"
                                ${RM_R} "${pack}"
                                ${GIT} archive --remote="${source_url}" --prefix="${pack}/" "${branch}":"${subdir}" \
                                | ${TAR} xvf -
-                       ;;
+                               ;;
                        'git')
-                               if [ -d "${download_dir}/${pack}" ]
+                               if [ -d "${pack}" ]
                                then
                                        (
                                                cd "${pack}"
@@ -322,14 +378,14 @@ downloadPack () {
                                else
                                        ${GIT} clone "${source_url}" "${pack}"
                                fi
-                       ;;
+                               ;;
                esac
 
-               if [ -d "${download_dir}/${pack}" ]
+               if [ -d "${pack}" ]
                then
                        (
-                               cd "${download_dir}/${pack}"
-                               downloadExtraUrls "${pack}"
+                               cd "${pack}"
+                               downloadExtraUrls
                        )
                fi
 
@@ -369,21 +425,27 @@ installPack () {
 
        pack="${name}${pack_suffix}"
 
-       ${MKDIR_P} "${real_install_dir}/${games_dir}"
+       ${MKDIR_P} "${install_dir}/${games_dir}"
 
        # Some per-game workaround for malformed gamepack
        case "${name}" in
                'JediAcademy')
                        pack="${pack}/Tools"
-               ;;
+                       ;;
                'Prey'|'Q3')
                        pack="${pack}/tools"
-               ;;
+                       ;;
                'Wolf')
                        pack="${pack}/bin"
-               ;;
+                       ;;
        esac
 
+       # mkeditorpacks-based gamepack
+       if [ -d "${download_dir}/${pack}/build/netradiant" ]
+       then
+               pack="${pack}/build/netradiant"
+       fi
+
        path="${download_dir}/${pack}"
 
        for game_file in "${path}/${games_dir}/"*'.game'
@@ -433,7 +495,7 @@ printHelp () {
        local prog_name
 
        tab="$(printf '\t')"
-       prog_name="$(basename "$(readlink -f "${0}")")"
+       prog_name='gamepack-manager'
 
        cat <<-EOF
        Usage: ${prog_name} [OPTION] [SELECTION <ARGUMENTS>] [ACTION]
@@ -450,13 +512,13 @@ printHelp () {
        ${tab}${tab}select games by name (default: none)
        ${tab}${tab}special keyword: all, none
        ${tab}${tab}available games:
-       $(printNameList | sed -e 's/^/\t\t\t/')
+       $(printNameList | ${SED} -e 's/^/\t\t\t/')
 
        ${tab}-l, --license LICENSES…
        ${tab}${tab}select games by license (default: none)
        ${tab}${tab}special keyword: free, all, none
        ${tab}${tab}available licenses:
-       $(printLicenseList | sed -e 's/^/\t\t\t/')
+       $(printLicenseList | ${SED} -e 's/^/\t\t\t/')
 
        ACTIONS:
        ${tab}-ln, --list-names
@@ -494,6 +556,9 @@ list_names='false'
 download_packs='false'
 install_packs='false'
 
+mkdir_download='false'
+mkdir_install='false'
+
 by_license='false'
 by_name='false'
 
@@ -523,55 +588,60 @@ do
                '--list-licenses'|'-ll')
                        arg_type=''
                        list_licenses='true'
-               ;;
+                       option_list="${option_list} ${1}"
+                       ;;
                '--list-names'|'-ln')
                        arg_type=''
                        list_names='true'
-               ;;
+                       option_list="${option_list} ${1}"
+                       ;;
                '--list-selected'|'-ls')
                        arg_type=''
                        list_selected='true'
                        option_list="${option_list} ${1}"
-               ;;
+                       ;;
                '--download'|'-d')
                        arg_type=''
                        download_packs='true'
+                       mkdir_download='true'
                        option_list="${option_list} ${1}"
-               ;;
+                       ;;
                '--install'|'-i')
                        arg_type=''
                        install_packs='true'
+                       mkdir_download='true'
+                       mkdir_install='true'
                        option_list="${option_list} ${1}"
-               ;;
+                       ;;
                '--license'|'-l')
                        by_license='true'
                        arg_type='pack-license'
                        option_list="${option_list} ${1}"
-               ;;
+                       ;;
                '--name'|'-n')
                        by_name='true'
                        arg_type='pack-name'
                        option_list="${option_list} ${1}"
-               ;;
+                       ;;
                '--download-dir'|'-dd')
                        arg_type='download-dir'
                        option_list="${option_list} ${1}"
-               ;;
+                       ;;
                '--install-dir'|'-id')
                        arg_type='install-dir'
                        option_list="${option_list} ${1}"
-               ;;
+                       ;;
                '-'*)
                        printError "unknown option: ${1}"
-               ;;
+                       ;;
                *)
                        case "${arg_type}" in
                                'pack-license')
                                        license_list="${license_list} ${1}"
-                               ;;
+                                       ;;
                                'pack-name')
                                        name_list="${name_list} ${1}"
-                               ;;
+                                       ;;
                                'download-dir')
                                        if [ -z "${download_dir}" ]
                                        then
@@ -579,7 +649,7 @@ do
                                        else
                                                printError "more than one download dir: ${1}"
                                        fi
-                               ;;
+                                       ;;
                                'install-dir')
                                        if [ -z "${install_dir}" ]
                                        then
@@ -587,12 +657,12 @@ do
                                        else
                                                printError "more than one install dir: ${1}"
                                        fi
-                               ;;
+                                       ;;
                                *)
                                        printError "misplaced argument: ${1}"
-                               ;;
+                                       ;;
                        esac
-               ;;
+                       ;;
        esac
 
        shift
@@ -601,12 +671,24 @@ done
 # compatibility with legacy Makefile
 if [ "${DOWNLOAD_GAMEPACKS}" = 'yes' ]
 then
-       ! [ -z "${DOWNLOADDIR}" ] && download_dir="${DOWNLOADDIR}"
-       ! [ -z "${INSTALLDIR}" ] && install_dir="${INSTALDIR}"
+       if ! [ -z "${DOWNLOADDIR}" ]
+       then
+               download_dir="${DOWNLOADDIR}"
+       fi
+
+       if ! [ -z "${INSTALLDIR}" ]
+       then
+               install_dir="${INSTALLDIR}"
+       fi
+
        license_list='free'
        by_license='true'
+
        download_packs='true'
+       mkdir_download='true'
+
        install_packs='true'
+       mkdir_install='true'
 fi
 
 if [ -z "${download_dir}" ]
@@ -631,10 +713,17 @@ fi
 
 selected_list="$(dedupeList "${selected_list}")"
 
-${MKDIR_P} "${download_dir}"
-${MKDIR_P} "${install_dir}"
-real_download_dir="$(readlink -f "${download_dir}")"
-real_install_dir="$(readlink -f "${install_dir}")"
+if "${mkdir_download}"
+then
+       ${MKDIR_P} "${download_dir}"
+       real_download_dir="$(printRealPath "${download_dir}")"
+fi
+
+if "${mkdir_install}"
+then
+       ${MKDIR_P} "${install_dir}"
+       real_install_dir="$(printRealPath "${install_dir}")"
+fi
 
 if "${list_licenses}"
 then