darrenldl

ezsetfacl.sh Examples

Jan 28th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. -Demonstration-
  2. Note :
  3. user names used in this demo are "alice", "bob" and "carl", which are in the "users" array
  4. group names used are "alice", "bob" and "carl", which are in the "groups" array
  5. chmod functionality will be added later
  6. Types of entries :
  7. ACL block - Set multiple file permissions, for multiple users/groups, can add individual permissions for files within it, supports most of setfacl options
  8. STRAY entry - Set single file permissions, for single user/group, supports most of setfacl options
  9. CHOWN block - chown multiple files, with options to set user and/or group
  10. CHMOD block - chmod multiple files
  11. CHATTR block - chattr multiple files
  12. APPEND block - append text after files. The text can be multiple lines
  13. INSERT block - insert text after a line number, or after a specified text, in files. The text can be multiple lines
  14. REPLACE block - replace text in files. The text can be multiple lines
  15. COMMAND block - lines within will be executed as commands in apply mode, or outputed directly in generate mode
  16.  
  17. Below are example files and the output of it
  18.  
  19. --- ACL block ---
  20. $ cat test_config
  21. RESTRICT USER alice bob
  22. PERM ---
  23. START
  24. file1
  25. file2 r-x P
  26. dir1 r-x r-x PDR
  27. dir2 r-x D
  28. /usr/bin/su
  29. END
  30. ####
  31.  
  32. $ ./ezsetfacl.sh -g test_config
  33. #!/bin/bash
  34. setfacl -m u:alice:--- -- file1
  35. setfacl -m u:bob:--- -- file1
  36. setfacl -m u:alice:r-x -- file2
  37. setfacl -m u:bob:r-x -- file2
  38. setfacl -Rm u:alice:r-x -- dir1
  39. setfacl -Rm u:bob:r-x -- dir1
  40. setfacl -Rm d:u:alice:r-x -- dir1
  41. setfacl -Rm d:u:bob:r-x -- dir1
  42. setfacl -m d:u:alice:r-x -- dir2
  43. setfacl -m d:u:bob:r-x -- dir2
  44. setfacl -m u:alice:--- -- /usr/bin/su
  45. setfacl -m u:bob:--- -- /usr/bin/su
  46.  
  47. --- STRAY ---
  48. $ cat test_config
  49. STRAY RES USR alice P --- /usr/bin/su
  50. STRAY RES USR alice P --- D --- dir1
  51. ####
  52.  
  53. $ ./ezsetfacl.sh -g test_config
  54. #!/bin/bash
  55. setfacl -m u:alice:--- -- /usr/bin/su
  56. setfacl -m u:alice:--- -- dir1
  57. setfacl -m d:u:alice:--- -- dir1
  58.  
  59. --- CHOWN ---
  60. $ cat test_config
  61. CHOWN USER root GROUP root
  62. file1
  63. END
  64. ####
  65.  
  66. $ ./ezsetfacl.sh -g test_config
  67. #!/bin/bash
  68. chown root:root file1
  69.  
  70. --- CHMOD ---
  71. $ cat test_config
  72. CHMOD u=rwx,g=rx,o=
  73. file1
  74. file2
  75. END
  76. ####
  77.  
  78. #!/bin/bash
  79. chmod u=rwx,g=rx,o= file1
  80. chmod u=rwx,g=rx,o= file2
  81.  
  82. --- CHATTR ---
  83. $ cat test_config
  84. CHATTR +i
  85. file1
  86. file2
  87. END
  88. ####
  89.  
  90. $ ./ezsetfacl.sh -g test_config
  91. #!/bin/bash
  92. chattr +i file1
  93. chattr +i file2
  94.  
  95. --- APPEND ---
  96. $ cat test_config
  97. APPEND
  98. Hello
  99. Goodbye
  100. START
  101. file1
  102. file2
  103. END
  104. ####
  105.  
  106. $ ./ezsetfacl.sh -g test_config
  107. #!/bin/bash
  108. echo -e "Hello\nGoodbye" >> file1
  109. echo -e "Hello\nGoodbye" >> file2
  110.  
  111. --- INSERT ---
  112. $ cat test_config
  113. INSERT
  114. Hello|
  115. AFTER
  116. Goodbye
  117. START
  118. file1
  119. file2
  120. END
  121. ####
  122.  
  123. $ ./ezsetfacl.sh -g test_config
  124. #!/bin/bash
  125. cat file1 | sed " s|Goodbye|Goodbye\nHello\||g" > file1
  126. cat file2 | sed " s|Goodbye|Goodbye\nHello\||g" > file2
  127.  
  128. $ cat test_config
  129. INSERT
  130. Hello|
  131. LINE 18
  132. START
  133. file1
  134. file2
  135. END
  136. ####
  137.  
  138. $ ./ezsetfacl.sh -g test_config
  139. #!/bin/bash
  140. cat file1 | sed "18 i Hello\|" > file1
  141. cat file2 | sed "18 i Hello\|" > file2
  142.  
  143. --- REPLACE ---
  144. $ cat test_config
  145. REPLACE
  146. Hello
  147. Goodbye
  148. WITH
  149. Hi
  150. START
  151. file1
  152. file2
  153. END
  154. ####
  155.  
  156. $ ./ezsetfacl.sh -g test_config
  157. #!/bin/bash
  158. cat file1 | sed "N; s|Hello\nGoodbye|Hi|g" > file1
  159. cat file2 | sed "N; s|Hello\nGoodbye|Hi|g" > file2
  160.  
  161. --- COMMAND ---
  162. $ cat test_config
  163. COMMAND
  164. START
  165. echo "Hello"
  166. END
  167. ####
  168.  
  169. $ ./ezsetfacl.sh -g test_config
  170. #!/bin/bash
  171. echo "Hello"
Advertisement
Add Comment
Please, Sign In to add comment