summaryrefslogtreecommitdiff
path: root/volinit-netatalk
blob: ed93c93c3f47743fb2bf4e3b492147fbcbb51281 (plain)
  1. #!/bin/bash
  2. # Reset access rights of a netatalk archive
  3. #
  4. # The archive should be in subfolders named after read/write and readonly groups
  5. # like this: /var/local/netatalk/files_administered_by_admins/admin/users/
  6. #
  7. # Also, the file /etc/local/volumes should contain something like the following
  8. # (indicating the root of all netatalk folders):
  9. #
  10. # NDIR="/var/local/netatalk"
  11. #
  12. # Fallback to this uid and gid if group uid doesn't exist
  13. GRP_UID="admin"
  14. GRP_GID="admin"
  15. [ -f /etc/local/volumes ] || exit 1
  16. . /etc/local/volumes
  17. [ "x$NDIR" = "x" ] && exit 1
  18. if [ $# -eq 0 ]; then
  19. echo "Usage: $0 <base directory> <read user/group> <write user/group> [create]"
  20. exit 1
  21. fi
  22. if [ "x$1" = "x" ]; then
  23. echo "$0: base directory missing - exiting..."
  24. exit 1
  25. fi
  26. VOL=$NDIR/$1
  27. if [ "x$2" = "x" ]; then
  28. echo "$0: read group missing - exiting..."
  29. exit 1
  30. fi
  31. ALL=$2
  32. #if [ `getent passwd "$ALL" | awk -F: '{print $1}';` ]; then
  33. if [ "`getent passwd "$ALL"`" != "" ]; then
  34. ALL_UID=$ALL
  35. ALL_GID=$ALL
  36. else
  37. echo "$0: User id $ALL doesn't exist - exiting..."
  38. exit 1
  39. fi
  40. if [ "x$3" = "x" ]; then
  41. echo "$0: write group missing - exiting..."
  42. exit 1
  43. fi
  44. GRP=$3
  45. #if [ `getent passwd "$GRP" | awk -F: '{print $1}';` = "" ]; then
  46. if [ "`getent passwd "$GRP"`" != "" ]; then
  47. GRP_UID=$GRP
  48. GRP_GID=$GRP
  49. else
  50. echo "User id $GRP doesn't exist - using $GRP_UID:$GRP_GID instead"
  51. fi
  52. if [ "x$4" != "x" ]; then
  53. if [ "x$4" == "xcreate" ]; then
  54. mkdir -p $VOL/$ALL/$GRP || exit
  55. else
  56. echo "Usage: $0 <base directory> <read user/group> <write user/group> [create]"
  57. exit 1
  58. fi
  59. fi
  60. test -d $VOL/$ALL/$GRP || exit
  61. test -d $VOL/$ALL/$GRP/.AppleDouble || mkdir $VOL/$ALL/$GRP/.AppleDouble
  62. test -d $VOL/$ALL/$GRP/.AppleDesktop || mkdir $VOL/$ALL/$GRP/.AppleDesktop
  63. chown root:$ALL_GID $VOL/$ALL
  64. chown $GRP_UID:$ALL_GID $VOL/$ALL/$GRP
  65. chmod u=rwX,g=rXs,o= $VOL/$ALL
  66. chmod u=rwX,g=rXs,o= $VOL/$ALL/$GRP
  67. echo "People in group $GRP has read/write access through AppleShare"
  68. test $GRP = $ALL || echo "People in group $ALL has read access through AppleShare"
  69. echo "Others have no access"
  70. echo -n "Checking permissions..."
  71. chown -R .$GRP_GID $VOL/$ALL/$GRP \
  72. && chmod -R u=rwX,g=rwXs,o=rX $VOL/$ALL/$GRP \
  73. && chmod u=rwX,g=rXs,o=rX $VOL/$ALL/$GRP
  74. echo "."