From 2b1b0c25270175a76b527a3acd4dc7a02f6895f4 Mon Sep 17 00:00:00 2001 From: Sven Grunewaldt Date: Sun, 23 Sep 2018 18:57:54 +0200 Subject: [PATCH] Add -I include parameter to samba.sh (#143) --- README.md | 4 ++++ samba.sh | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bc540a3..f051294 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,9 @@ OR set local storage: required arg: "" for samba -W Allow access wide symbolic links + -I Add an include option at the end of the smb.conf + required arg: "" + in the container, e.g. a bind mount The 'command' (if provided and valid) will be run instead of samba @@ -82,6 +85,7 @@ ENVIRONMENT VARIABLES * `WORKGROUP` - As above, set workgroup * `USERID` - Set the UID for the samba server * `GROUPID` - Set the GID for the samba server + * `INCLUDE` - As above, add a smb.conf include **NOTE**: if you enable nmbd (via `-n` or the `NMBD` environment variable), you will also want to expose port 137 and 138 with `-p 137:137/udp -p 138:138/udp`. diff --git a/samba.sh b/samba.sh index d8d1800..3350856 100755 --- a/samba.sh +++ b/samba.sh @@ -45,6 +45,14 @@ global() { local key="${1%%=*}" value="${1#*=}" file=/etc/samba/smb.conf fi } +### include: add a samba config file include +# Arguments: +# file) file to import +include() { local includefile="$1" file=/etc/samba/smb.conf + sed -i "\\|include = $includefile|d" "$file" + echo "include = $includefile" >> "$file" +} + ### import: import a smbpasswd file # Arguments: # file) file to import @@ -193,6 +201,9 @@ Options (fields in '[]' are optional, '<>' are required): required arg: \"\" for samba -W Allow access wide symbolic links + -I Add an include option at the end of the smb.conf + required arg: \"\" + in the container, e.g. a bind mount The 'command' (if provided and valid) will be run instead of samba " >&2 @@ -202,7 +213,7 @@ The 'command' (if provided and valid) will be run instead of samba [[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o smbuser [[ "${GROUPID:-""}" =~ ^[0-9]+$ ]] && groupmod -g $GROUPID -o users -while getopts ":hc:g:i:nprs:Su:Ww:" opt; do +while getopts ":hc:g:i:nprs:Su:Ww:I:" opt; do case "$opt" in h) usage ;; c) charmap "$OPTARG" ;; @@ -216,6 +227,7 @@ while getopts ":hc:g:i:nprs:Su:Ww:" opt; do u) eval user $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $OPTARG) ;; w) workgroup "$OPTARG" ;; W) widelinks ;; + I) include "$OPTARG" ;; "?") echo "Unknown option: -$OPTARG"; usage 1 ;; ":") echo "No argument value for option: -$OPTARG"; usage 2 ;; esac @@ -232,6 +244,7 @@ shift $(( OPTIND - 1 )) [[ "${USER:-""}" ]] && eval user $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $USER) [[ "${WORKGROUP:-""}" ]] && workgroup "$WORKGROUP" [[ "${WIDELINKS:-""}" ]] && widelinks +[[ "${INCLUDE:-""}" ]] && include "$INCLUDE" if [[ $# -ge 1 && -x $(which $1 2>&-) ]]; then exec "$@"