Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -Demonstration-
- Note :
- user names used in this demo are "alice", "bob" and "carl", which are in the "users" array
- group names used are "alice", "bob" and "carl", which are in the "groups" array
- chmod functionality will be added later
- Types of entries :
- ACL block - Set multiple file permissions, for multiple users/groups, can add individual permissions for files within it, supports most of setfacl options
- STRAY entry - Set single file permissions, for single user/group, supports most of setfacl options
- CHOWN block - chown multiple files, with options to set user and/or group
- CHMOD block - chmod multiple files
- CHATTR block - chattr multiple files
- APPEND block - append text after files. The text can be multiple lines
- INSERT block - insert text after a line number, or after a specified text, in files. The text can be multiple lines
- REPLACE block - replace text in files. The text can be multiple lines
- COMMAND block - lines within will be executed as commands in apply mode, or outputed directly in generate mode
- Below are example files and the output of it
- --- ACL block ---
- $ cat test_config
- RESTRICT USER alice bob
- PERM ---
- START
- file1
- file2 r-x P
- dir1 r-x r-x PDR
- dir2 r-x D
- /usr/bin/su
- END
- ####
- $ ./ezsetfacl.sh -g test_config
- #!/bin/bash
- setfacl -m u:alice:--- -- file1
- setfacl -m u:bob:--- -- file1
- setfacl -m u:alice:r-x -- file2
- setfacl -m u:bob:r-x -- file2
- setfacl -Rm u:alice:r-x -- dir1
- setfacl -Rm u:bob:r-x -- dir1
- setfacl -Rm d:u:alice:r-x -- dir1
- setfacl -Rm d:u:bob:r-x -- dir1
- setfacl -m d:u:alice:r-x -- dir2
- setfacl -m d:u:bob:r-x -- dir2
- setfacl -m u:alice:--- -- /usr/bin/su
- setfacl -m u:bob:--- -- /usr/bin/su
- --- STRAY ---
- $ cat test_config
- STRAY RES USR alice P --- /usr/bin/su
- STRAY RES USR alice P --- D --- dir1
- ####
- $ ./ezsetfacl.sh -g test_config
- #!/bin/bash
- setfacl -m u:alice:--- -- /usr/bin/su
- setfacl -m u:alice:--- -- dir1
- setfacl -m d:u:alice:--- -- dir1
- --- CHOWN ---
- $ cat test_config
- CHOWN USER root GROUP root
- file1
- END
- ####
- $ ./ezsetfacl.sh -g test_config
- #!/bin/bash
- chown root:root file1
- --- CHMOD ---
- $ cat test_config
- CHMOD u=rwx,g=rx,o=
- file1
- file2
- END
- ####
- #!/bin/bash
- chmod u=rwx,g=rx,o= file1
- chmod u=rwx,g=rx,o= file2
- --- CHATTR ---
- $ cat test_config
- CHATTR +i
- file1
- file2
- END
- ####
- $ ./ezsetfacl.sh -g test_config
- #!/bin/bash
- chattr +i file1
- chattr +i file2
- --- APPEND ---
- $ cat test_config
- APPEND
- Hello
- Goodbye
- START
- file1
- file2
- END
- ####
- $ ./ezsetfacl.sh -g test_config
- #!/bin/bash
- echo -e "Hello\nGoodbye" >> file1
- echo -e "Hello\nGoodbye" >> file2
- --- INSERT ---
- $ cat test_config
- INSERT
- Hello|
- AFTER
- Goodbye
- START
- file1
- file2
- END
- ####
- $ ./ezsetfacl.sh -g test_config
- #!/bin/bash
- cat file1 | sed " s|Goodbye|Goodbye\nHello\||g" > file1
- cat file2 | sed " s|Goodbye|Goodbye\nHello\||g" > file2
- $ cat test_config
- INSERT
- Hello|
- LINE 18
- START
- file1
- file2
- END
- ####
- $ ./ezsetfacl.sh -g test_config
- #!/bin/bash
- cat file1 | sed "18 i Hello\|" > file1
- cat file2 | sed "18 i Hello\|" > file2
- --- REPLACE ---
- $ cat test_config
- REPLACE
- Hello
- Goodbye
- WITH
- Hi
- START
- file1
- file2
- END
- ####
- $ ./ezsetfacl.sh -g test_config
- #!/bin/bash
- cat file1 | sed "N; s|Hello\nGoodbye|Hi|g" > file1
- cat file2 | sed "N; s|Hello\nGoodbye|Hi|g" > file2
- --- COMMAND ---
- $ cat test_config
- COMMAND
- START
- echo "Hello"
- END
- ####
- $ ./ezsetfacl.sh -g test_config
- #!/bin/bash
- echo "Hello"
Advertisement
Add Comment
Please, Sign In to add comment