From 174977e9d11854e2e05c687cfd6f710f2ad91568 Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Wed, 3 Apr 2024 13:02:47 -0600 Subject: [PATCH 1/5] Add realpath support to pkg The `pkg` script (along with our build scripts) makes use of `realpath`. But unlike the build scripts, `pkg` does not have a backup `realpath` function if the host OS does not have `realpath`. apache/trafficcontrol#7981 adds a backup `realpath` function to the `pkg` script. --- pkg | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg b/pkg index a9efc2b4af..e3a2991dfc 100755 --- a/pkg +++ b/pkg @@ -12,6 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +# macOS does not come with realpath, so we add a function for it. +if ! type -p realpath; then + # by default, macOS does not have realpath + realpath() { + ls "$( + cd "$(dirname "$0")" + pwd -P # -P resolves symlinks + )/$(basename "$0")" + } + export -f realpath +fi; + # Files are relative to this script directory. SELF="${BASH_SOURCE[0]}" cd "$( dirname "${BASH_SOURCE[0]}" )" From 17b71e31402e9d25874504df0b732c54b572fca9 Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Thu, 4 Apr 2024 09:38:32 -0600 Subject: [PATCH 2/5] realpath -e -> realpath --- pkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg b/pkg index e3a2991dfc..939bce6984 100755 --- a/pkg +++ b/pkg @@ -259,7 +259,7 @@ while (( "$#" )); do # where is the name of the specific service to be chained. The file may be a symlink to another # compose file, in which case the symlink will be followed before it is processed. if [ -e "$COMPOSE_FILE.$1" ] ; then - $SELF -f $(realpath -e "$COMPOSE_FILE.$1") $([ "$verbose" == 0 ] || echo "-v") $([ "$quiet" == 0 ] || echo "-q") $([ "$debug" == 0 ] || echo "-d") $([ "$build" == 0 ] || echo "-b") $("${COMPOSECMD[@]}" -f $(realpath -e "$COMPOSE_FILE.$1") config --services) + $SELF -f $(realpath "$COMPOSE_FILE.$1") $([ "$verbose" == 0 ] || echo "-v") $([ "$quiet" == 0 ] || echo "-q") $([ "$debug" == 0 ] || echo "-d") $([ "$build" == 0 ] || echo "-b") $("${COMPOSECMD[@]}" -f $(realpath "$COMPOSE_FILE.$1") config --services) chained_exit=$? [ $chained_exit == 0 ] || exit $chained_exit fi From a30432f31d72b811eb048a3849d56769b170c2bf Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Fri, 5 Apr 2024 23:35:13 -0600 Subject: [PATCH 3/5] Improve realpath function and detection --- build/functions.sh | 10 +++++++--- pkg | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/build/functions.sh b/build/functions.sh index 718516d833..4416107021 100755 --- a/build/functions.sh +++ b/build/functions.sh @@ -13,13 +13,17 @@ # # shellcheck shell=ash -if ! type -p realpath; then +# macOS's version of realpath does not resolve symlinks, so we add a function +# for it. +if ! realpath -e . >/dev/null 2>&1; then # by default, macOS does not have realpath realpath() { + local path="$1" + shift ls "$( - cd "$(dirname "$0")" + cd "$(dirname "$path")" pwd -P # -P resolves symlinks - )/$(basename "$0")" + )/$(basename "$path")" } export -f realpath fi; diff --git a/pkg b/pkg index 939bce6984..54104d25f6 100755 --- a/pkg +++ b/pkg @@ -12,14 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -# macOS does not come with realpath, so we add a function for it. -if ! type -p realpath; then +# macOS's version of realpath does not resolve symlinks, so we add a function +# for it. +if ! realpath -e . >/dev/null 2>&1; then # by default, macOS does not have realpath realpath() { + local path="$1" + shift ls "$( - cd "$(dirname "$0")" + cd "$(dirname "$path")" pwd -P # -P resolves symlinks - )/$(basename "$0")" + )/$(basename "$path")" } export -f realpath fi; From ff3c4562c80fd9324ef55ced443c26a6292b4cd5 Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Mon, 15 Apr 2024 10:29:14 -0600 Subject: [PATCH 4/5] Use GNU realpath if realpath -e does not work If realpath -e oes not work, the `realpath` binary is probably BSD realpath. --- build/functions.sh | 48 +++++++++++++++++++------- docs/source/development/building.rst | 4 +-- pkg | 50 ++++++++++++++++++++-------- 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/build/functions.sh b/build/functions.sh index 4416107021..c85e5ec7eb 100755 --- a/build/functions.sh +++ b/build/functions.sh @@ -15,18 +15,42 @@ # macOS's version of realpath does not resolve symlinks, so we add a function # for it. -if ! realpath -e . >/dev/null 2>&1; then - # by default, macOS does not have realpath - realpath() { - local path="$1" - shift - ls "$( - cd "$(dirname "$path")" - pwd -P # -P resolves symlinks - )/$(basename "$path")" - } - export -f realpath -fi; +get_realpath() { + local bin + local found='' + first_realpath="$(type -P realpath)" + for bin in $(type -aP realpath | uniq); do + if "$bin" -e . >/dev/null 2>&1; then + found=y + break + fi + done + if [[ -n "$found" ]]; then + if [[ "$first_realpath" == "$bin" ]]; then + # Default realpath works. + return + fi + realpath_path="$bin" + # by default, macOS does not have realpath + eval "$(</dev/null && stat -f%u .; } >/dev/null 2>&1; then #BSD stat uses -f as its formatting flag instead of -c diff --git a/docs/source/development/building.rst b/docs/source/development/building.rst index 0b9d9f416b..0e0b81f82b 100644 --- a/docs/source/development/building.rst +++ b/docs/source/development/building.rst @@ -168,8 +168,8 @@ Install the Dependencies +---------------------------------+---------------------+----------------------------+------------------------+---------------------------+---------------------------+--------------------------+----------+------------------------------+--------------------------+ | OS/Package Manager | Common dependencies | :ref:`dev-traffic-monitor` | :ref:`dev-traffic-ops` | :ref:`dev-traffic-portal` | :ref:`dev-traffic-router` | :ref:`dev-traffic-stats` | Grove | Grove TC Config (grovetccfg) | :ref:`Docs ` | +=================================+=====================+============================+========================+===========================+===========================+==========================+==========+==============================+==========================+ - | macOS\ [#mac-jdk]_ | - rpm | - go | - go | - npm | - maven | - go | - go | - go | - python3 | - | (homebrew_) | | | | - grunt-cli | | | | | | + | macOS\ [#mac-jdk]_ | - coreutils | - go | - go | - npm | - maven | - go | - go | - go | - python3 | + | (homebrew_) | - rpm | | | - grunt-cli | | | | | | +---------------------------------+---------------------+----------------------------+------------------------+---------------------------+---------------------------+--------------------------+----------+------------------------------+--------------------------+ | Rocky\ Linux\ [#rocky-go]_, | - git | | | - epel-release | - java-11-openjdk | | | | - python3-devel | | Red Hat, | - rpm-build | | | - npm | - maven | | | | - gcc | diff --git a/pkg b/pkg index 54104d25f6..7d8b1e887a 100755 --- a/pkg +++ b/pkg @@ -14,18 +14,42 @@ # macOS's version of realpath does not resolve symlinks, so we add a function # for it. -if ! realpath -e . >/dev/null 2>&1; then - # by default, macOS does not have realpath - realpath() { - local path="$1" - shift - ls "$( - cd "$(dirname "$path")" - pwd -P # -P resolves symlinks - )/$(basename "$path")" - } - export -f realpath -fi; +get_realpath() { + local bin + local found='' + first_realpath="$(type -P realpath)" + for bin in $(type -aP realpath | uniq); do + if "$bin" -e . >/dev/null 2>&1; then + found=y + break + fi + done + if [[ -n "$found" ]]; then + if [[ "$first_realpath" == "$bin" ]]; then + # Default realpath works. + return + fi + realpath_path="$bin" + # by default, macOS does not have realpath + eval "$(< is the name of the specific service to be chained. The file may be a symlink to another # compose file, in which case the symlink will be followed before it is processed. if [ -e "$COMPOSE_FILE.$1" ] ; then - $SELF -f $(realpath "$COMPOSE_FILE.$1") $([ "$verbose" == 0 ] || echo "-v") $([ "$quiet" == 0 ] || echo "-q") $([ "$debug" == 0 ] || echo "-d") $([ "$build" == 0 ] || echo "-b") $("${COMPOSECMD[@]}" -f $(realpath "$COMPOSE_FILE.$1") config --services) + $SELF -f $(realpath -e "$COMPOSE_FILE.$1") $([ "$verbose" == 0 ] || echo "-v") $([ "$quiet" == 0 ] || echo "-q") $([ "$debug" == 0 ] || echo "-d") $([ "$build" == 0 ] || echo "-b") $("${COMPOSECMD[@]}" -f $(realpath -e "$COMPOSE_FILE.$1") config --services) chained_exit=$? [ $chained_exit == 0 ] || exit $chained_exit fi From e298e4a4b9f19e0780ad9d92adde09ca5fddf1bd Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Fri, 31 May 2024 05:23:34 -0600 Subject: [PATCH 5/5] Add grealpath to paths to check for macOS/FreeBSD support --- build/functions.sh | 2 +- pkg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/functions.sh b/build/functions.sh index c85e5ec7eb..541ddf5985 100755 --- a/build/functions.sh +++ b/build/functions.sh @@ -19,7 +19,7 @@ get_realpath() { local bin local found='' first_realpath="$(type -P realpath)" - for bin in $(type -aP realpath | uniq); do + for bin in $(type -aP grealpath realpath | uniq); do if "$bin" -e . >/dev/null 2>&1; then found=y break diff --git a/pkg b/pkg index 7d8b1e887a..2a60d6dfcc 100755 --- a/pkg +++ b/pkg @@ -18,7 +18,7 @@ get_realpath() { local bin local found='' first_realpath="$(type -P realpath)" - for bin in $(type -aP realpath | uniq); do + for bin in $(type -aP grealpath realpath | uniq); do if "$bin" -e . >/dev/null 2>&1; then found=y break