1
0
This repository has been archived on 2025-01-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Anderson Luiz Alves 0464e230c1 stock 103961
2017-07-30 16:48:04 -03:00

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