From e14098dbbe234c54989d81198eee61a70ef60bdd Mon Sep 17 00:00:00 2001 From: David Personette Date: Sat, 6 Jul 2019 18:34:52 -0400 Subject: [PATCH] samba.sh/README.md fix #190 to allow setting GID and fix USERID derp --- README.md | 3 ++- samba.sh | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e42e7a1..407b541 100644 --- a/README.md +++ b/README.md @@ -53,12 +53,13 @@ OR set local storage: [admins] allowed default:'none' or list of admin users [writelist] list of users that can write to a RO share [comment] description of share - -u "[;ID;group]" Add a user + -u "[;ID;group;GID]" Add a user required arg: ";" for user for user [ID] for user [group] for user + [GID] for group -w "" Configure the workgroup (domain) samba should use required arg: "" for samba diff --git a/samba.sh b/samba.sh index 3ca3604..0c28442 100755 --- a/samba.sh +++ b/samba.sh @@ -135,9 +135,12 @@ smb() { local file=/etc/samba/smb.conf # password) for user # id) for user # group) for user +# gid) for group # Return: user added to container -user() { local name="$1" passwd="$2" id="${3:-""}" group="${4:-""}" - [[ "$group" ]] && { grep -q "^$group:" /etc/group || addgroup "$group"; } +user() { local name="$1" passwd="$2" id="${3:-""}" group="${4:-""}" \ + gid="${5:-""}" + [[ "$group" ]] && { grep -q "^$group:" /etc/group || + addgroup ${gid:+--gid $gid }"$group"; } grep -q "^$name:" /etc/passwd || adduser -D -H ${group:+-G $group} ${id:+-u $id} "$name" echo -e "$passwd\n$passwd" | smbpasswd -s -a "$name" @@ -191,12 +194,13 @@ Options (fields in '[]' are optional, '<>' are required): [admins] allowed default:'none' or list of admin users [writelist] list of users that can write to a RO share [comment] description of share - -u \"[;ID;group]\" Add a user + -u \"[;ID;group;GID]\" Add a user required arg: \";\" for user for user [ID] for user [group] for user + [GID] for group -w \"\" Configure the workgroup (domain) samba should use required arg: \"\" for samba @@ -210,7 +214,7 @@ The 'command' (if provided and valid) will be run instead of samba exit $RC } -[[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o smbuser +[[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o smbuser&&unset USERID [[ "${GROUPID:-""}" =~ ^[0-9]+$ ]] && groupmod -g $GROUPID -o users while getopts ":hc:g:i:nprs:Su:Ww:I:" opt; do