samba.sh issue #36 configure character mapping

This commit is contained in:
David Personette 2016-11-29 13:22:04 -05:00
parent 17723a88ce
commit 288979ca51
2 changed files with 25 additions and 3 deletions

View File

@ -30,6 +30,8 @@ OR set local storage:
Usage: samba.sh [-opt] [command] Usage: samba.sh [-opt] [command]
Options (fields in '[]' are optional, '<>' are required): Options (fields in '[]' are optional, '<>' are required):
-h This help -h This help
-c "<from:to>" setup character mapping for file/directory names
required arg: "<from:to>" character mappings separated by ','
-i "<path>" Import smbpassword -i "<path>" Import smbpassword
required arg: "<path>" - full file path in container required arg: "<path>" - full file path in container
-n Start the 'nmbd' daemon to advertise the shares -n Start the 'nmbd' daemon to advertise the shares
@ -59,6 +61,7 @@ OR set local storage:
ENVIRONMENT VARIABLES (only available with `docker run`) ENVIRONMENT VARIABLES (only available with `docker run`)
* `CHARMAP` - As above, configure character mapping
* `NMBD` - As above, enable nmbd * `NMBD` - As above, enable nmbd
* `TZ` - As above, set a zoneinfo timezone, IE `EST5EDT` * `TZ` - As above, set a zoneinfo timezone, IE `EST5EDT`
* `WORKGROUP` - As above, set workgroup * `WORKGROUP` - As above, set workgroup

View File

@ -18,11 +18,26 @@
set -o nounset # Treat unset variables as an error 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 ### import: import a smbpasswd file
# Arguments: # Arguments:
# file) file to import # file) file to import
# Return: user(s) added to container # Return: user(s) added to container
import() { local name id file="${1}" import() { local name id file="$1"
while read name id; do while read name id; do
useradd "$name" -M -u "$id" useradd "$name" -M -u "$id"
done < <(cut -d: -f1,2 --output-delimiter=' ' $file) 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 echo " valid users = $(tr ',' ' ' <<< $users)" >>$file
[[ ${admins:-""} && ! ${admins:-""} =~ none ]] && [[ ${admins:-""} && ! ${admins:-""} =~ none ]] &&
echo " admin users = $(tr ',' ' ' <<< $admins)" >>$file echo " admin users = $(tr ',' ' ' <<< $admins)" >>$file
echo -e "" >>$file echo "" >>$file
} }
### timezone: Set the timezone for the container ### timezone: Set the timezone for the container
@ -111,6 +126,8 @@ usage() { local RC=${1:-0}
echo "Usage: ${0##*/} [-opt] [command] echo "Usage: ${0##*/} [-opt] [command]
Options (fields in '[]' are optional, '<>' are required): Options (fields in '[]' are optional, '<>' are required):
-h This help -h This help
-c \"<from:to>\" setup character mapping for file/directory names
required arg: \"<from:to>\" character mappings separated by ','
-i \"<path>\" Import smbpassword -i \"<path>\" Import smbpassword
required arg: \"<path>\" - full file path in container required arg: \"<path>\" - full file path in container
-n Start the 'nmbd' daemon to advertise the shares -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 exit $RC
} }
while getopts ":hi:nps:t:u:w:" opt; do while getopts ":hc:i:nps:t:u:w:" opt; do
case "$opt" in case "$opt" in
h) usage ;; h) usage ;;
c) charmap "$OPTARG" ;;
i) import "$OPTARG" ;; i) import "$OPTARG" ;;
n) NMBD="true" ;; n) NMBD="true" ;;
p) PERMISSIONS="true" ;; p) PERMISSIONS="true" ;;
@ -157,6 +175,7 @@ while getopts ":hi:nps:t:u:w:" opt; do
done done
shift $(( OPTIND - 1 )) shift $(( OPTIND - 1 ))
[[ "${CHARMAP:-""}" ]] && charmap "$CHARMAP"
[[ "${TZ:-""}" ]] && timezone "$TZ" [[ "${TZ:-""}" ]] && timezone "$TZ"
[[ "${WORKGROUP:-""}" ]] && workgroup "$WORKGROUP" [[ "${WORKGROUP:-""}" ]] && workgroup "$WORKGROUP"
[[ "${PERMISSIONS:-""}" ]] && perms [[ "${PERMISSIONS:-""}" ]] && perms