tfb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. ################## https://github.com/mkropat/sh-realpath #####################
  3. #
  4. # The MIT License (MIT)
  5. #
  6. # Copyright (c) 2014 Michael Kropat
  7. #
  8. # Permission is hereby granted, free of charge, to any person obtaining a copy
  9. # of this software and associated documentation files (the "Software"), to deal
  10. # in the Software without restriction, including without limitation the rights
  11. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. # copies of the Software, and to permit persons to whom the Software is
  13. # furnished to do so, subject to the following conditions:
  14. #
  15. # The above copyright notice and this permission notice shall be included in
  16. # all copies or substantial portions of the Software.
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. # THE SOFTWARE.
  24. realpath() {
  25. canonicalize_path "$(resolve_symlinks "$1")"
  26. }
  27. resolve_symlinks() {
  28. _resolve_symlinks "$1"
  29. }
  30. _resolve_symlinks() {
  31. _assert_no_path_cycles "$@" || return
  32. local dir_context path
  33. path=$(readlink -- "$1")
  34. if [ $? = 0 ]; then
  35. dir_context=$(dirname -- "$1")
  36. _resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@"
  37. else
  38. printf '%s\n' "$1"
  39. fi
  40. }
  41. _prepend_dir_context_if_necessary() {
  42. if [ "$1" = . ]; then
  43. printf '%s\n' "$2"
  44. else
  45. _prepend_path_if_relative "$1" "$2"
  46. fi
  47. }
  48. _prepend_path_if_relative() {
  49. case "$2" in
  50. /* ) printf '%s\n' "$2" ;;
  51. * ) printf '%s\n' "$1/$2" ;;
  52. esac
  53. }
  54. _assert_no_path_cycles() {
  55. local target path
  56. target=$1
  57. shift
  58. for path in "$@"; do
  59. if [ "$path" = "$target" ]; then
  60. return 1
  61. fi
  62. done
  63. }
  64. canonicalize_path() {
  65. if [ -d "$1" ]; then
  66. _canonicalize_dir_path "$1"
  67. else
  68. _canonicalize_file_path "$1"
  69. fi
  70. }
  71. _canonicalize_dir_path() {
  72. (cd "$1" 2>/dev/null && pwd -P)
  73. }
  74. _canonicalize_file_path() {
  75. local dir file
  76. dir=$(dirname -- "$1")
  77. file=$(basename -- "$1")
  78. (cd "$dir" 2>/dev/null >/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
  79. }
  80. ##############################################################################
  81. SCRIPT_PATH="$(realpath "$0")"
  82. SCRIPT_ROOT="$(dirname "$SCRIPT_PATH")"
  83. if ! docker network inspect tfb >/dev/null 2>&1; then
  84. docker network create tfb >/dev/null
  85. fi
  86. exec docker run -it --rm --network tfb -v /var/run/docker.sock:/var/run/docker.sock -v ${SCRIPT_ROOT}:/FrameworkBenchmarks techempower/tfb "${@}"