From ab15aae77d1b9523085c3def1cd8338ba14addf1 Mon Sep 17 00:00:00 2001 From: David Personette Date: Wed, 17 Jun 2015 13:37:00 -0400 Subject: [PATCH] README.md and samba.sh add import option for smbpasswd --- README.md | 3 ++- samba.sh | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c9e6b5e..292ff46 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,11 @@ OR set local storage: ## Configuration sudo docker run -it --rm dperson/samba -h - Usage: samba.sh [-opt] [command] Options (fields in '[]' are optional, '<>' are required): -h This help + -i "" Import smbpassword + required arg: "" - full file path in container to import -s "[;browse;readonly;guest;users]" Configure a share required arg: ";;" is how it's called for clients diff --git a/samba.sh b/samba.sh index dbce434..729556a 100755 --- a/samba.sh +++ b/samba.sh @@ -18,6 +18,17 @@ set -o nounset # Treat unset variables as an error +### import: import a smbpasswd file +# Arguments: +# file) file to import +# Return: user(s) added to container +import() { local name file="${2}" + for name in $(cat $file | cut -d: -f1); do + useradd "$name" -M + done + pdbedit -i smbpasswd:$file +} + ### share: Add share # Arguments: # share) share name @@ -62,6 +73,7 @@ user() { local name="${1}" passwd="${2}" useradd "$name" -M echo "$passwd" | tee - | smbpasswd -s -a "$name" } + ### usage: Help # Arguments: # none) @@ -70,6 +82,8 @@ usage() { local RC=${1:-0} echo "Usage: ${0##*/} [-opt] [command] Options (fields in '[]' are optional, '<>' are required): -h This help + -i \"\" Import smbpassword + required arg: \"\" - full file path in container to import -s \"[;browse;readonly;guest;users]\" Configure a share required arg: \";;\" is how it's called for clients @@ -90,9 +104,10 @@ The 'command' (if provided and valid) will be run instead of samba exit $RC } -while getopts ":ht:u:s:" opt; do +while getopts ":hi:t:u:s:" opt; do case "$opt" in h) usage ;; + i) import "$OPTARG" ;; s) eval share $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;; u) eval user $(sed 's/;/ /g' <<< $OPTARG) ;; t) timezone "$OPTARG" ;;