diff --git a/README.md b/README.md index b888504..a7a6e13 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ OR set local storage: -i "" Import smbpassword required arg: "" - full file path in container -n Start the 'nmbd' daemon to advertise the shares + -p Set ownership and permissions on the shares -s "[;browsable;readonly;guest;users]" Configure a share required arg: ";;" is how it's called for clients diff --git a/samba.sh b/samba.sh index eb3907f..015f026 100755 --- a/samba.sh +++ b/samba.sh @@ -29,6 +29,18 @@ import() { local name id file="${1}" pdbedit -i smbpasswd:$file } +### perms: fix ownership and permissions of share paths +# Arguments: +# none) +# Return: result +perms() { local i file=/etc/samba/smb.conf + for i in $(awk -F ' = ' '/ path = / {print $2}'); do + chown -Rh smbuser. $i + find $i -type d -exec chmod 775 {} \; + find $i -type f -exec chmod 664 {} \; + done +} + ### share: Add share # Arguments: # share) share name @@ -101,6 +113,7 @@ Options (fields in '[]' are optional, '<>' are required): -i \"\" Import smbpassword required arg: \"\" - full file path in container -n Start the 'nmbd' daemon to advertise the shares + -p Set ownership and permissions on the shares -s \"[;browsable;readonly;guest;users]\" Configure a share required arg: \";;\" is how it's called for clients @@ -126,11 +139,12 @@ The 'command' (if provided and valid) will be run instead of samba exit $RC } -while getopts ":hi:ns:t:u:w:" opt; do +while getopts ":hi:nps:t:u:w:" opt; do case "$opt" in h) usage ;; i) import "$OPTARG" ;; n) NMBD="true" ;; + p) PERMISSIONS="true" ;; s) eval share $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;; t) timezone "$OPTARG" ;; u) eval user $(sed 's|;| |g' <<< $OPTARG) ;; @@ -143,6 +157,7 @@ shift $(( OPTIND - 1 )) [[ "${TZ:-""}" ]] && timezone "$TZ" [[ "${WORKGROUP:-""}" ]] && workgroup "$WORKGROUP" +[[ "${PERMISSIONS:-""}" ]] && perms if [[ $# -ge 1 && -x $(which $1 2>&-) ]]; then exec "$@"