utility_package 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/usr/bin/env bash
  2. __rvm_fix_group_permissions()
  3. {
  4. if
  5. \umask -S | __rvm_grep 'g=rw' >/dev/null
  6. then
  7. chmod -R g+rwX "$@"
  8. fi
  9. }
  10. # params: archive_file
  11. __rvm_package_list()
  12. {
  13. rvm_debug __rvm_package_list:$#: "$@"
  14. case "$1" in
  15. *.zip)
  16. unzip -Z -1 "$1"
  17. ;;
  18. *.tar.bz2)
  19. __rvm_tar tjf "$1"
  20. ;;
  21. *.tar.gz|*.tgz)
  22. __rvm_tar tzf "$1"
  23. ;;
  24. *)
  25. return 199
  26. ;;
  27. esac
  28. }
  29. __map_tar_excludes()
  30. {
  31. \typeset __exclude_element
  32. for __exclude_element
  33. do __exclude_elements+=( --exclude "${__exclude_element}" )
  34. done
  35. }
  36. __rvm_package_extract_run()
  37. {
  38. \typeset __extract_run_src __extract_run_target __exclude_elements
  39. __extract_run_src="$1"
  40. __extract_run_target="$2"
  41. shift 2
  42. __exclude_elements=()
  43. if
  44. [[ " ${rvm_tar_options:-} " != *" --no-same-owner "* ]] &&
  45. __rvm_tar --help 2>&1 | __rvm_grep -- --no-same-owner >/dev/null
  46. then
  47. rvm_tar_options="${rvm_tar_options:-}${rvm_tar_options:+ }--no-same-owner"
  48. fi
  49. [[ -d "$__extract_run_target" ]] || mkdir -p "$__extract_run_target"
  50. case "$__extract_run_src" in
  51. *.zip)
  52. #__map_unzip_excludes
  53. unzip -q -o "$__extract_run_src" -d "$__extract_run_target"
  54. ;;
  55. *.tar.bz2)
  56. __map_tar_excludes "$@"
  57. if [[ -n "$ZSH_VERSION" ]]
  58. then __rvm_tar "${__exclude_elements[@]}" -xjf "$__extract_run_src" -C "$__extract_run_target" ${=rvm_tar_options:-}
  59. else __rvm_tar "${__exclude_elements[@]}" -xjf "$__extract_run_src" -C "$__extract_run_target" ${rvm_tar_options:-}
  60. fi
  61. ;;
  62. *.tar.gz|*.tgz)
  63. __map_tar_excludes "$@"
  64. if [[ -n "$ZSH_VERSION" ]]
  65. then __rvm_tar "${__exclude_elements[@]}" -xzf "$__extract_run_src" -C "$__extract_run_target" ${=rvm_tar_options:-}
  66. else __rvm_tar "${__exclude_elements[@]}" -xzf "$__extract_run_src" -C "$__extract_run_target" ${rvm_tar_options:-}
  67. fi
  68. ;;
  69. *)
  70. return 199
  71. ;;
  72. esac &&
  73. __rvm_fix_group_permissions "$__extract_run_target"/* ||
  74. return $?
  75. }
  76. # params: archive_file path [excludes...]
  77. __rvm_package_extract()
  78. {
  79. rvm_debug __rvm_package_extract:$#: "$@"
  80. \typeset __extract_src __extract_target __tempdir __path __file __return
  81. __extract_src="$1"
  82. __extract_target="$2"
  83. shift 2
  84. __return=0
  85. __tempdir="$( TMPDIR="${rvm_tmp_path}" mktemp -d -t rvm-tmp.XXXXXXXXX )"
  86. __rvm_package_extract_run "$__extract_src" "$__tempdir" "$@" || __return=$?
  87. if
  88. (( __return == 0 ))
  89. then
  90. for __path in "$__tempdir"/*
  91. do
  92. __file="${__path##*/}"
  93. if
  94. [[ -n "${__file}" && -e "$__extract_target/${__file}" ]]
  95. then
  96. \command \rm -rf "$__extract_target/${__file}" || __return=$?
  97. fi
  98. \command \mv -f "${__path}" "$__extract_target/" || __return=$?
  99. done
  100. fi
  101. if [[ -n "$__tempdir" ]]
  102. then \command \rm -rf "$__tempdir"
  103. fi
  104. return $__return
  105. }
  106. # params: archive_file [path [path2]]
  107. __rvm_package_create()
  108. {
  109. rvm_debug __rvm_package_create:$#: "$@"
  110. case "$1" in
  111. *.tar.bz2)
  112. if [[ -z "${3:-}" ]]
  113. then __rvm_tar cjf "$1" "$2"
  114. else __rvm_tar cjf "$1" -C "$2" "$3"
  115. fi
  116. ;;
  117. *.tar.gz|*.tgz)
  118. if [[ -z "${3:-}" ]]
  119. then __rvm_tar czf "$1" "$2"
  120. else __rvm_tar czf "$1" -C "$2" "$3"
  121. fi
  122. ;;
  123. *)
  124. return 199
  125. ;;
  126. esac
  127. }