]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
gamepack-manager: try to compute realpath the portable way
authorThomas Debesse <dev@illwieckz.net>
Mon, 20 May 2019 19:17:02 +0000 (21:17 +0200)
committerThomas Debesse <dev@illwieckz.net>
Sat, 1 Jun 2019 15:23:48 +0000 (17:23 +0200)
gamepack-manager

index aa42745583211e5d5ffeaafdbc4509d270049aaf..f06ccf7af54becd74d309e7249160761527a3487 100755 (executable)
@@ -81,6 +81,43 @@ Xonotic         GPL          git     https://gitlab.com/xonotic/netradiant-xonot
 EOF
 }
 
+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: no known way to compute real path of a file' >&2
+                               return 1
+                       fi
+               fi
+       fi
+}
+
+if "${mkdir_download}"
+then
+       ${MKDIR_P} "${download_dir}"
+       real_download_dir="$(printRealPath "${download_dir}")"
+fi
+
 sanitizeDB () {
        sed -e 's/#.*//;s/[ \t][ \t][ \t]*/\t/g;s/^[ \t]*//;s/[ \t]*$//' \
        | grep -v '^$'
@@ -663,16 +700,10 @@ fi
 
 selected_list="$(dedupeList "${selected_list}")"
 
-if "${mkdir_download}"
-then
-       ${MKDIR_P} "${download_dir}"
-       real_download_dir="$(readlink -f "${download_dir}")"
-fi
-
 if "${mkdir_install}"
 then
        ${MKDIR_P} "${install_dir}"
-       real_install_dir="$(readlink -f "${install_dir}")"
+       real_install_dir="$(printRealPath "${install_dir}")"
 fi
 
 if "${list_licenses}"