samba.sh add option to set the workgroup/domain

This commit is contained in:
David Personette 2016-02-12 18:13:20 -05:00
parent e0b3561b20
commit ff18817931
2 changed files with 19 additions and 2 deletions

View File

@ -49,6 +49,9 @@ OR set local storage:
required arg: "<username>;<passwd>" required arg: "<username>;<passwd>"
<username> for user <username> for user
<password> for user <password> for user
-w "<workgroup>" Configure the workgroup (domain) samba should use
required arg: "<workgroup>"
<workgroup> for samba
The 'command' (if provided and valid) will be run instead of samba The 'command' (if provided and valid) will be run instead of samba
@ -56,6 +59,7 @@ ENVIRONMENT VARIABLES (only available with `docker run`)
* `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
**NOTE**: if you enable nmbd (via `-n` or the `NMBD` environment variable), you **NOTE**: if you enable nmbd (via `-n` or the `NMBD` environment variable), you
will also want to expose port 137 with `-p 137:137`. will also want to expose port 137 with `-p 137:137`.

View File

@ -82,6 +82,14 @@ user() { local name="${1}" passwd="${2}"
echo "$passwd" | tee - | smbpasswd -s -a "$name" echo "$passwd" | tee - | smbpasswd -s -a "$name"
} }
### workgroup: set the workgroup
# Arguments:
# workgroup) the name to set
# Return: configure the correct workgroup
user() { local workgroup="${1}" file=/etc/samba/smb.conf
sed -i 's/^\( *workgroup = \).*/\1'"$workgroup"'/' $file
}
### usage: Help ### usage: Help
# Arguments: # Arguments:
# none) # none)
@ -109,20 +117,24 @@ Options (fields in '[]' are optional, '<>' are required):
required arg: \"<username>;<passwd>\" required arg: \"<username>;<passwd>\"
<username> for user <username> for user
<password> for user <password> for user
-w \"<workgroup>\" Configure the workgroup (domain) samba should use
required arg: \"<workgroup>\"
<workgroup> for samba
The 'command' (if provided and valid) will be run instead of samba The 'command' (if provided and valid) will be run instead of samba
" >&2 " >&2
exit $RC exit $RC
} }
while getopts ":hi:nt:u:s:" opt; do while getopts ":hi:ns:t:u:w:" opt; do
case "$opt" in case "$opt" in
h) usage ;; h) usage ;;
i) import "$OPTARG" ;; i) import "$OPTARG" ;;
n) NMBD="true" ;; n) NMBD="true" ;;
s) eval share $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;; s) eval share $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;;
u) eval user $(sed 's/;/ /g' <<< $OPTARG) ;;
t) timezone "$OPTARG" ;; t) timezone "$OPTARG" ;;
u) eval user $(sed 's/;/ /g' <<< $OPTARG) ;;
w) workgroup "$OPTARG" ;;
"?") echo "Unknown option: -$OPTARG"; usage 1 ;; "?") echo "Unknown option: -$OPTARG"; usage 1 ;;
":") echo "No argument value for option: -$OPTARG"; usage 2 ;; ":") echo "No argument value for option: -$OPTARG"; usage 2 ;;
esac esac
@ -130,6 +142,7 @@ done
shift $(( OPTIND - 1 )) shift $(( OPTIND - 1 ))
[[ "${TZ:-""}" ]] && timezone "$TZ" [[ "${TZ:-""}" ]] && timezone "$TZ"
[[ "${WORKGROUP:-""}" ]] && workgroup "$WORKGROUP"
if [[ $# -ge 1 && -x $(which $1 2>&-) ]]; then if [[ $# -ge 1 && -x $(which $1 2>&-) ]]; then
exec "$@" exec "$@"