ext-tools.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env bash
  2. TOOLS_TAR=""
  3. HOST_BUILD_DIR=$(pwd)/"build_dir/host"
  4. HOST_STAGING_DIR_STAMP=$(pwd)/"staging_dir/host/stamp"
  5. refresh_timestamps() {
  6. find -H "$1" -not -type l -print0 | xargs -0 touch
  7. }
  8. extract_prebuilt_tar() {
  9. tar -xf "$1"
  10. }
  11. refresh_prebuilt_tools() {
  12. if [ ! -d "$HOST_BUILD_DIR" ]; then
  13. echo "Can't find Host Build Dir "$HOST_BUILD_DIR"" >&2
  14. exit 1
  15. fi
  16. refresh_timestamps "$HOST_BUILD_DIR"
  17. sleep 1
  18. if [ ! -d "$HOST_STAGING_DIR_STAMP" ]; then
  19. echo "Can't find Host Staging Dir Stamp "$HOST_STAGING_DIR_STAMP"" >&2
  20. exit 1
  21. fi
  22. refresh_timestamps "$HOST_STAGING_DIR_STAMP"
  23. return 0
  24. }
  25. install_prebuilt_tools() {
  26. extract_prebuilt_tar "$TOOLS_TAR"
  27. refresh_prebuilt_tools
  28. return 0
  29. }
  30. while [ -n "$1" ]; do
  31. arg="$1"; shift
  32. case "$arg" in
  33. --host-build-dir)
  34. [ -d "$1" ] || {
  35. echo "Directory '$1' does not exist." >&2
  36. exit 1
  37. }
  38. HOST_BUILD_DIR="$(cd "$1"; pwd)"; shift
  39. ;;
  40. --host-staging-dir-stamp)
  41. [ -d "$1" ] || {
  42. echo "Directory '$1' does not exist." >&2
  43. exit 1
  44. }
  45. HOST_STAGING_DIR_STAMP="$(cd "$1"; pwd)"; shift
  46. ;;
  47. --tools)
  48. [ -f "$1" ] || {
  49. echo "Tools tar file '$1' does not exist." >&2
  50. exit 1
  51. }
  52. TOOLS_TAR="$1"; shift
  53. install_prebuilt_tools
  54. exit $?
  55. ;;
  56. --refresh)
  57. refresh_prebuilt_tools
  58. exit $?
  59. ;;
  60. -h|--help)
  61. me="$(basename "$0")"
  62. echo -e "\nUsage:\n" >&2
  63. echo -e " $me --host-build-dir {directory}" >&2
  64. echo -e " Set to refresh timestamp of this build directory" >&2
  65. echo -e " with --tools." >&2
  66. echo -e " THIS OPTION MUST BE SET BEFORE --tools." >&2
  67. echo -e " If not provided the default directory is:" >&2
  68. echo -e " $(pwd)/build_dir/host\n" >&2
  69. echo -e " $me --host-staging-dir-stamp {directory}" >&2
  70. echo -e " Set to refresh staging timestamp present in this" >&2
  71. echo -e " directory with --tools." >&2
  72. echo -e " THIS OPTION MUST BE SET BEFORE --tools." >&2
  73. echo -e " If not provided the default directory is:" >&2
  74. echo -e " $(pwd)/staging_dir/host/stamp\n" >&2
  75. echo -e " $me --tools {tar}" >&2
  76. echo -e " Install the prebuilt tools present in the passed" >&2
  77. echo -e " tar and prepare them." >&2
  78. echo -e " To correctly use them it's needed to update the" >&2
  79. echo -e " timestamp of each tools to skip recompilation.\n" >&2
  80. echo -e " $me --refresh" >&2
  81. echo -e " Refresh timestamps of already extracted prebuilt" >&2
  82. echo -e " tools to correctly use them and skip" >&2
  83. echo -e " recompilation.\n" >&2
  84. echo -e " $me --help" >&2
  85. echo -e " Display this help text and exit.\n\n" >&2
  86. exit 1
  87. ;;
  88. *)
  89. echo "Unknown argument '$arg'" >&2
  90. exec $0 --help
  91. ;;
  92. esac
  93. done
  94. exec $0 --help