From 54374d29a05c8efc1fb065c13e5b8db4d5b201de Mon Sep 17 00:00:00 2001 From: David Personette Date: Sat, 6 Jul 2019 16:27:43 -0400 Subject: [PATCH] samba.sh/README.md support additional environment variables --- README.md | 9 ++++++--- samba.sh | 12 +++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 06536ae..e42e7a1 100644 --- a/README.md +++ b/README.md @@ -72,15 +72,15 @@ OR set local storage: ENVIRONMENT VARIABLES * `CHARMAP` - As above, configure character mapping - * `GLOBAL` - As above, configure a global option + * `GLOBAL` - As above, configure a global option (See NOTE3 below) * `IMPORT` - As above, import a smbpassword file * `NMBD` - As above, enable nmbd * `PERMISSIONS` - As above, set file permissions on all shares * `RECYCLE` - As above, disable recycle bin - * `SHARE` - As above, setup a share + * `SHARE` - As above, setup a share (See NOTE3 below) * `SMB` - As above, disable SMB2 minimum version * `TZ` - Set a timezone, IE `EST5EDT` - * `USER` - As above, setup a user + * `USER` - As above, setup a user (See NOTE3 below) * `WIDELINKS` - As above, allow access wide symbolic links * `WORKGROUP` - As above, set workgroup * `USERID` - Set the UID for the samba server @@ -93,6 +93,9 @@ will also want to expose port 137 and 138 with `-p 137:137/udp -p 138:138/udp`. **NOTE2**: there are reports that `-n` and `NMBD` only work if you have the container configured to use the hosts network stack. +**NOTE3**: optionally supports additional variables starting with the same name, +IE `SHARE` also will work for `SHARE2`, `SHARE3`... `SHAREx`, etc. + ## Examples Any of the commands can be run at creation with `docker run` or later with diff --git a/samba.sh b/samba.sh index 3cf93dd..3ca3604 100755 --- a/samba.sh +++ b/samba.sh @@ -235,13 +235,19 @@ done shift $(( OPTIND - 1 )) [[ "${CHARMAP:-""}" ]] && charmap "$CHARMAP" -[[ "${GLOBAL:-""}" ]] && global "$GLOBAL" +while read i; do + global "$i" +done <$(env | awk '/^GLOBAL/ {sub (/^[^=]*=/, "", $0); print}') [[ "${IMPORT:-""}" ]] && import "$IMPORT" [[ "${PERMISSIONS:-""}" ]] && perms [[ "${RECYCLE:-""}" ]] && recycle -[[ "${SHARE:-""}" ]] && eval share $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $SHARE) +while read i; do + eval share $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $i) +done <$(env | awk '/^SHARE/ {sub (/^[^=]*=/, "", $0); print}') [[ "${SMB:-""}" ]] && smb -[[ "${USER:-""}" ]] && eval user $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $USER) +while read i; do + eval user $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $i) +done <$(env | awk '/^USER/ {sub (/^[^=]*=/, "", $0); print}') [[ "${WORKGROUP:-""}" ]] && workgroup "$WORKGROUP" [[ "${WIDELINKS:-""}" ]] && widelinks [[ "${INCLUDE:-""}" ]] && include "$INCLUDE"