From: Thomas Debesse Date: Mon, 20 May 2019 19:17:02 +0000 (+0200) Subject: gamepack-manager: try to compute realpath the portable way X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6b4a03f1688e0b76b56f246d200517ce3b274a2e;p=xonotic%2Fnetradiant.git gamepack-manager: try to compute realpath the portable way --- diff --git a/gamepack-manager b/gamepack-manager index aa427455..f06ccf7a 100755 --- a/gamepack-manager +++ b/gamepack-manager @@ -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}"