-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsmb_mount.sh
More file actions
55 lines (51 loc) · 1.58 KB
/
smb_mount.sh
File metadata and controls
55 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
smb_mount() {
if [ -f ~/.smbrc ]; then
. ~/.smbrc
fi
local smb_host=$1
local smb_host_uri=$smb_user:$smb_password@$smb_host
local smb_share=$2
local smb_mount_point=$3
local result exit_code
if [ -z $smb_host ] || [ -z $smb_share ]; then
cat <<-USAGE
smb_mount {host} {share_name} {mount_point}
Parameters
==========
Host: The hostname or ip address only.
Sharename: The name of the share on the remote host.
Mount point: Optional (will default to /Volumes/{Sharename})
Authentication
==============
This function will use smb_user and smb_password environment variables,
or it will pull those values from a ~/.smbrc file. syntax is:
smb_user={username}
smb_password={password}
NOTE: no spaces between the equal sign.
USAGE
return 1;
fi
if [ -z $smb_mount_point ]; then
smb_mount_point=/Volumes/$smb_share
fi
if ! mount | grep " $smb_mount_point " >/dev/null; then
mkdir -p $smb_mount_point
echo mount -t smbfs //${smb_host_uri}/$smb_share $smb_mount_point
result=$(mount -t smbfs //${smb_host_uri}/$smb_share $smb_mount_point 2>&1)
exit_code=$?
if [ $exit_code -ne 0 ]; then
re='server connection failed: Socket is not connected'
if [[ $result =~ $re ]]; then
echo "'mount -t smbfs' failed, falling back to mount_smbfs"
result=$(mount_smbfs -s //${smb_host_uri}/$smb_share $smb_mount_point 2>&1)
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "mount failed (exit_code: $exit_code): $result"
return 1
fi
fi
fi
else
echo "$smb_mount_point already mounted."
fi
}