fix-permissions 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env bash
  2. __rvm_if_sudo()
  3. {
  4. \typeset -a __command
  5. __command=()
  6. (( UID == 0 )) || __command+=( \command \sudo -p "%p password required for '$*': " )
  7. __command+=( $@ )
  8. "${__command[@]}" || return $?
  9. }
  10. __rvm_fix_permissions_fix_rights()
  11. {
  12. case "${__user}" in
  13. (*:*)
  14. rvm_log "Fixing rights with 'g+w' - this might take a few long minutes..."
  15. __rvm_if_sudo chmod -R g+w "${rvm_path}" || return $?
  16. ;;
  17. esac
  18. }
  19. __rvm_fix_permissions_fix_directories()
  20. {
  21. \typeset -a __broken_dirs
  22. \typeset __broken_dir
  23. while
  24. __rvm_read_lines __broken_dirs <(
  25. find "${rvm_path}" -type d -not -perm -111 2>/dev/null || true
  26. ) &&
  27. (( ${#__broken_dirs[@]} ))
  28. do
  29. for __broken_dir in "${__broken_dirs[@]}"
  30. do chmod +x "${__broken_dir}" || return $?
  31. done
  32. done
  33. }
  34. __rvm_fix_permissions_fix_message()
  35. {
  36. \typeset __type
  37. case "${__user}" in
  38. (:*) __type="group" ;;
  39. (*:*) __type="user/group" ;;
  40. (*) __type="user" ;;
  41. esac
  42. rvm_log "Fixing ${__type} for ${__user} - this might take a few long minutes..."
  43. }
  44. __rvm_fix_permissions_fix()
  45. {
  46. __rvm_fix_permissions_fix_message
  47. __rvm_if_sudo chown -R "${__user}" "${rvm_path}" &&
  48. __rvm_fix_permissions_fix_rights &&
  49. rvm_log "Finished fixing." ||
  50. {
  51. \typeset __result=$?
  52. rvm_error "Failed fixing, read the above messages."
  53. return ${__result}
  54. }
  55. }
  56. __rvm_fix_permissions_select()
  57. {
  58. case "${__user}" in
  59. ("")
  60. if (( ${rvm_user_install_flag:=0} == 0 ))
  61. then __user="system"
  62. else __user="user"
  63. fi
  64. ;;
  65. esac
  66. case "${__user}" in
  67. (system)
  68. __user=":${rvm_group_name:-rvm}"
  69. ;;
  70. (user)
  71. __user="$USER"
  72. ;;
  73. esac
  74. }
  75. __rvm_fix_permissions()
  76. {
  77. \typeset __user="${1:-}"
  78. __rvm_fix_permissions_select &&
  79. __rvm_fix_permissions_fix &&
  80. __rvm_fix_permissions_fix_directories ||
  81. return $?
  82. }
  83. __rvm_fix_permissions "${args[@]}"