54 lines
1.1 KiB
Bash
Executable File
54 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# vim: set ts=2 sw=2 et:
|
|
|
|
#
|
|
# Sanitize the input string to use it as an identifier
|
|
#
|
|
|
|
if [ ${STRING_LIB_LOADED:-0} -eq 1 ]; then
|
|
return
|
|
fi
|
|
|
|
String_sanitizeIdentifier ()
|
|
{
|
|
local str="$@"
|
|
|
|
base_log "sanitizeIdentifier( ${str} )" debug
|
|
# remove white spaces (multiples, trailing and starting)
|
|
str=`echo "${str}" | sed "s/ /_/g"`
|
|
str=`echo "${str}" | sed "s/__*/_/g"`
|
|
str=`echo "${str}" | sed "s/^_//g"`
|
|
str=`echo "${str}" | sed "s/_$//g"`
|
|
|
|
echo "${str}"
|
|
return 0
|
|
}
|
|
|
|
#
|
|
# Sanitize the input string to use it as a Share name
|
|
# in samba, url, etc...
|
|
#
|
|
String_sanitizeShareName ()
|
|
{
|
|
local namecut=$1
|
|
shift
|
|
local str="$@"
|
|
|
|
base_log "sanitizeShareName( ${str} )" debug
|
|
# A share name is an identifier, so sanitize it...
|
|
str=$( String_sanitizeIdentifier "${str}" )
|
|
|
|
# Since Apple MacOSX (10.4.8) and Microsoft Windows Vista
|
|
# contains some bug features making samba share
|
|
# useless when the names are (respectively) longuer than
|
|
# 12 and 11 characters, we have to truncate mountpoints
|
|
# names.
|
|
str=`echo "${str}" |cut -c-${namecut}`
|
|
str=$( String_sanitizeIdentifier "${str}" )
|
|
|
|
echo "${str}"
|
|
return 0
|
|
}
|
|
|
|
STRING_LIB_LOADED=1
|