@@ -21,17 +21,23 @@ set -e
2121#
2222# ==============================================================================
2323
24- # --- Argument Parsing ---
25- SHARED_GROUP=" $1 "
26- shift # Shift arguments so $@ contains only the directories
27- TARGET_DIRS=(" $@ " )
28-
2924# --- Input Validation ---
30- if [ ${ # TARGET_DIRS[@]} -eq 0 ] || [ " $1 " == " -h" ] || [ " $1 " == " --help" ]; then
31- echo " Usage: $0 <shared_group > <dir1> [<dir2> ...]"
25+ if [ $# -eq 0 ] || [ " $1 " == " -h" ] || [ " $1 " == " --help" ]; then
26+ echo " Usage: $0 <user_group > <dir1> [<dir2> ...]"
3227 exit 1
3328fi
3429
30+ if [ $# -lt 2 ]; then
31+ echo " Error: Missing directory arguments."
32+ echo " Usage: $0 <user_group> <dir1> [<dir2> ...]"
33+ exit 1
34+ fi
35+
36+ # --- Argument Parsing ---
37+ USER_GROUP=" $1 "
38+ shift
39+ TARGET_DIRS=(" $@ " )
40+
3541# --- Pre-flight Checks ---
3642# 1. Check for root privileges.
3743if [[ $EUID -ne 0 ]]; then
@@ -40,22 +46,22 @@ if [[ $EUID -ne 0 ]]; then
4046fi
4147
4248# 2. Check if the specified group exists.
43- if ! getent group " $SHARED_GROUP " > /dev/null; then
44- echo " Error: Group '$SHARED_GROUP ' does not exist." >&2
49+ if ! getent group " $USER_GROUP " > /dev/null; then
50+ echo " Error: Group '$USER_GROUP ' does not exist." >&2
4551 exit 1
4652fi
4753
4854# --- Main Logic ---
49- echo " Configuring shared directories for group '$SHARED_GROUP '..."
55+ echo " Configuring shared directories for group '$USER_GROUP '..."
5056
5157for target_dir in " ${TARGET_DIRS[@]} " ; do
5258 echo " --> Processing: $target_dir "
5359 mkdir -p " $target_dir "
54- chgrp -R " $SHARED_GROUP " " $target_dir "
60+ chgrp -R " $USER_GROUP " " $target_dir "
5561 chmod -R g=rwX,o-rwx " $target_dir "
5662 find " $target_dir " -type d -exec chmod g+s {} +
57- setfacl -R -m " g:$SHARED_GROUP :rwX" " $target_dir "
58- setfacl -R -d -m " g:$SHARED_GROUP :rwX" " $target_dir "
63+ setfacl -R -m " g:$USER_GROUP :rwX" " $target_dir "
64+ setfacl -R -d -m " g:$USER_GROUP :rwX" " $target_dir "
5965done
6066
6167echo " Configuration complete."
0 commit comments