selftest: Document --testenv in --help output, remove documentation for
[Samba.git] / examples / scripts / mount / mount.smbfs
blob3b57bc5141b2b2963f8872ebede09d4935fc8a5a
1 #!/bin/bash
2 # Debian mount.smbfs compatibility wrapper
3 # Copyright 2007, Steve Langasek <vorlon at debian.org>
4 # Licensed under the GNU General Public License, version 2. See the
5 # file /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
7 # This script accepts all documented mount options for mount.smbfs,
8 # passing through those that are also recognized by mount.cifs,
9 # converting those that are not recognized but map to available cifs
10 # options, and warning about the use of options for which no equivalent
11 # exists.
13 # known bugs: quoted spaces in arguments are not passed intact
15 set -e
17 # reverse the order of username and password in a "username" parameter,
18 # taking care to leave any "%password" bit intact
20 reverse_username_workgroup() {
21 local workgroup password username
23 username="$1"
24 case "$username" in
25 *%*) password="${username#*%}"
26 username="${username%%%*}"
28 *) ;;
29 esac
30 case "$username" in
31 */*) workgroup="${username#*/}"
32 username="${username%%/*}"
34 *) ;;
35 esac
36 if [ -n "$workgroup" ]; then
37 username="$workgroup\\$username"
39 if [ -n "$password" ]; then
40 username="$username%$password"
42 echo "$username"
46 # parse out the mount options that have been specified using -o, and if
47 # necessary, convert them for use by mount.cifs
49 parse_mount_options () {
50 local OLD_IFS IFS options option username
51 OLD_IFS="$IFS"
52 IFS=","
53 options=""
54 workgroup=""
55 password=""
57 for option in $@; do
58 case "$option" in
59 sockopt=* | scope=* | codepage=* | ttl=* | debug=*)
60 echo "Warning: ignoring deprecated smbfs option '$option'" >&2
63 krb)
64 options="$options${options:+,}sec=krb5"
67 guest)
68 echo "Warning: mapping 'guest' to 'guest,sec=none'" >&2
69 options="$options${options:+,}guest,sec=none"
72 # username and workgroup are reversed in username= arguments,
73 # so need to be parsed out
74 username=*/*)
75 IFS="$OLD_IFS"
76 username="${option#username=}"
77 username="$(reverse_username_workgroup "$username")"
78 IFS=","
79 options="$options${options:+,}username=$username"
83 options="$options${options:+,}$option"
85 esac
86 done
87 IFS="$OLD_IFS"
88 echo $options
91 args=()
92 while [ "$#" -gt 0 ]; do
93 case "$1" in
94 -o*)
95 arg=${1#-o}
96 shift
97 if [ -z "$arg" ]; then
98 arg=$1
99 shift
101 arg="$(parse_mount_options "$arg")"
102 if [ -n "$arg" ]; then
103 args=("${args[@]}" "-o" "$arg")
107 args=("${args[@]}" "$1")
108 shift
110 esac
111 done
113 USER="$(reverse_username_workgroup "$USER")"
115 exec /sbin/mount.cifs "${args[@]}"