Last active
October 13, 2015 14:17
-
-
Save alecthegeek/4208339 to your computer and use it in GitHub Desktop.
Mount and unmount smb file systems on OS X
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Copyright (C) 2012-15 Alec Clews | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU General Public License | |
# as published by the Free Software Foundation; either version 2 | |
# of the License, or (at your option) any later version. | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# http://www.gnu.org/licenses/gpl-2.0.html#SEC1 | |
# Mount or Unmount SMB file systems from a config file | |
CONFIG_FILE=~/.smbfsconf | |
# File Layout is | |
# Server Sharename username password options | |
# Any lines that start with '#' are ignored. | |
# suggest running chmod 600 $CONFIG_FILE for security purposes | |
# Optional script parameter matches the server name or share name | |
# if the script is called umount (or similiar) then it will perform the unmount operation. So you can create | |
# a link called 'umountstuff' for instance | |
sed -Ee '/(^\s*#)|^\s*$/d' < $CONFIG_FILE | | |
while read server sharename user password options ; do | |
mount_point=$(echo $sharename | gsed -e 's/\(%20\)\| /_/g' ) | |
if [[ -z "$1" ]] || echo $server $sharename | grep "$1" > /dev/null; then | |
if mount | grep "//$user@$server/$sharename" > /dev/null ; then | |
if [[ $0 == *umount* ]] ; then | |
echo ummounting /Volumes/$mount_point | |
umount /Volumes/$mount_point | |
else | |
echo //$server/$mount_point aready mounted | |
fi | |
else | |
if [[ $0 == *umount* ]] ; then | |
echo //$server/$sharename not mounted | |
else | |
test -d /Volumes/$mount_point || mkdir /Volumes/$mount_point | |
echo mounting //$server/$sharename on /Volumes/$mount_point | |
mount_smbfs $options //$user:$password@$server/$sharename /Volumes/$mount_point | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment