From 288979ca519fd1cca246cf6f8f5aa03b1bdf05b8 Mon Sep 17 00:00:00 2001 From: David Personette Date: Tue, 29 Nov 2016 13:22:04 -0500 Subject: [PATCH] samba.sh issue #36 configure character mapping --- README.md | 3 +++ samba.sh | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d581e7e..d9b0d92 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ OR set local storage: Usage: samba.sh [-opt] [command] Options (fields in '[]' are optional, '<>' are required): -h This help + -c "" setup character mapping for file/directory names + required arg: "" character mappings separated by ',' -i "" Import smbpassword required arg: "" - full file path in container -n Start the 'nmbd' daemon to advertise the shares @@ -59,6 +61,7 @@ OR set local storage: ENVIRONMENT VARIABLES (only available with `docker run`) + * `CHARMAP` - As above, configure character mapping * `NMBD` - As above, enable nmbd * `TZ` - As above, set a zoneinfo timezone, IE `EST5EDT` * `WORKGROUP` - As above, set workgroup diff --git a/samba.sh b/samba.sh index 15821ec..8a24696 100755 --- a/samba.sh +++ b/samba.sh @@ -18,11 +18,26 @@ set -o nounset # Treat unset variables as an error +### charmap: setup character mapping for file/directory names +# Arguments: +# chars) from:to character mappings separated by ',' +# Return: configured character mapings +charmap() { local chars="$1" file=/etc/samba/smb.conf + grep -q catia $file || sed -i '/TCP_NODELAY/a \ +\ + vfs objects = catia\ + catia:mappings =\ + + ' $file + + sed -i '/catia:mappings/s/ =.*/ = '"$chars" $file +} + ### import: import a smbpasswd file # Arguments: # file) file to import # Return: user(s) added to container -import() { local name id file="${1}" +import() { local name id file="$1" while read name id; do useradd "$name" -M -u "$id" done < <(cut -d: -f1,2 --output-delimiter=' ' $file) @@ -64,7 +79,7 @@ share() { local share="$1" path="$2" browsable=${3:-yes} ro=${4:-yes} \ echo " valid users = $(tr ',' ' ' <<< $users)" >>$file [[ ${admins:-""} && ! ${admins:-""} =~ none ]] && echo " admin users = $(tr ',' ' ' <<< $admins)" >>$file - echo -e "" >>$file + echo "" >>$file } ### timezone: Set the timezone for the container @@ -111,6 +126,8 @@ usage() { local RC=${1:-0} echo "Usage: ${0##*/} [-opt] [command] Options (fields in '[]' are optional, '<>' are required): -h This help + -c \"\" setup character mapping for file/directory names + required arg: \"\" character mappings separated by ',' -i \"\" Import smbpassword required arg: \"\" - full file path in container -n Start the 'nmbd' daemon to advertise the shares @@ -141,9 +158,10 @@ The 'command' (if provided and valid) will be run instead of samba exit $RC } -while getopts ":hi:nps:t:u:w:" opt; do +while getopts ":hc:i:nps:t:u:w:" opt; do case "$opt" in h) usage ;; + c) charmap "$OPTARG" ;; i) import "$OPTARG" ;; n) NMBD="true" ;; p) PERMISSIONS="true" ;; @@ -157,6 +175,7 @@ while getopts ":hi:nps:t:u:w:" opt; do done shift $(( OPTIND - 1 )) +[[ "${CHARMAP:-""}" ]] && charmap "$CHARMAP" [[ "${TZ:-""}" ]] && timezone "$TZ" [[ "${WORKGROUP:-""}" ]] && workgroup "$WORKGROUP" [[ "${PERMISSIONS:-""}" ]] && perms