setperms.sh

Sunday, August 28th, 2005 - Español English

Quickly fix permissions under one directory. Get it. Or see it…

  1. #!/bin/bash
  2. #
  3. # Fri Aug 19 17:16:21 CEST 2005 * Miguel de Benito <nonick AT 8027 DOT org>
  4. #
  5. # Fixes permissions under one directory
  6. #
  7. # TODO: don't use find -exec but run per-file to be able to check chmod return code
  8. #
  9.  
  10. ##################
  11. # Load lib
  12. #
  13. [ ! -f ~/bin/messages.sh ] && echo "Required file ~/bin/messages.sh not found. Sorry..." && exit 1
  14. . ~/bin/messages.sh
  15.  
  16. ###################
  17. # Check arguments
  18. #
  19. if [ -d "$1" ]
  20. then
  21. dir=$1
  22. else
  23. if [ -z "$1" ]
  24. then
  25. dir=.
  26. else
  27. error_msg "Unable to access directory '$1'"
  28. exit 1
  29. fi
  30. fi
  31.  
  32.  
  33. ###################
  34. # Go:
  35. #
  36. if ask_msg "chmod 664 every regular file in '$dir' and children?" "Y"
  37. then
  38. run_cmd "Processing... " "find $dir -type f -exec chmod 664 \\{\\} \\;"
  39. fi
  40.  
  41. if ask_msg "chmod 775 $dir and every child directory?" "Y"
  42. then
  43. run_cmd "Processing... " "find $dir -type d -exec chmod 775 \\{\\} \\;"
  44. fi
  45.  
  46. if ask_msg "chown .users everything under $dir?" "Y"
  47. then
  48. run_cmd "Processing... " "chown -R :users $dir"
  49. fi

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>