-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_smb
More file actions
47 lines (40 loc) · 1.07 KB
/
auto_smb
File metadata and controls
47 lines (40 loc) · 1.07 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
#!/bin/bash
#####################################
# Create .smb_credentials file in user home dir
# format:
# username=[username]
# password=[password]
#####################################
LOCAL_USER=[local_osx_user]
SMB_SERVER=[hostname_of_the_synology_nas]
CACHE_TIME=900
SMB_CRED_FILE=/Users/${LOCAL_USER}/.smb_credentials
SMB_CACHE_FILE=/tmp/.smb_cache
OPTIONS="-fstype=url"
# getting connection-string to the server
if [ -e $SMB_CRED_FILE ]; then
. $SMB_CRED_FILE
SERVER=$username:$password@$SMB_SERVER
else
SERVER=$SMB_SERVER
fi
if [ $# = 0 ]; then
if [ -e $SMB_CACHE_FILE ]; then
eTime=`date +%s`
eval $(stat -s -t %s $SMB_CACHE_FILE)
if [ $(($eTime-$st_mtime)) -lt $CACHE_TIME ]; then
cat $SMB_CACHE_FILE
exit 0
fi
fi
rm -rf $SMB_CACHE_FILE
sudo -u $LOCAL_USER smbutil view //$SERVER | grep Disk | grep -v homes | cut -d " " -f 1 | while read MOUNT;
do
if [ -n "$MOUNT" ]; then
echo "\"${MOUNT}\" ${OPTIONS} cifs://${SERVER}/${MOUNT}" | tee -a $SMB_CACHE_FILE;
chmod 0600 $SMB_CACHE_FILE
fi
done
exit 0
fi
echo "${OPTIONS} cifs://${SERVER}/$1"