#!/bin/bash # # Mount Samba Share # # This script will mount a selected windows (smb) share. To use # this script within nautilus, it is necessary to first browse the # smb:/ protocol for a folder to mount. Right click on the folder # and choose the script "Mount share...", which will prompt for a # password and then execute the mount command. It is required that # the username and password be specified in a file named ~/.smb.cnf. # # Author: Dan Allen http://www.mojavelinux.com # License: GPL # Last Modified: 2005.08.12 call_sudo() { result=$(gksudo -m "$1" echo 'root?') if [ ${result:-0} == "'root?'" ]; then /bin/true else /bin/false fi } error_msg() { zenity --error --text "$1" # I have to put the exit here since I am unsure how to chain together # a failure execution path exit 0 } info_msg() { zenity --info --text "$1" } VFSSHARE= # only get the first one for SELECTED in $NAUTILUS_SCRIPT_SELECTED_URIS; do VFSSHARE=$SELECTED break; done FOLDER=${VFSSHARE/*\/} if [[ $VFSSHARE == smb://* ]]; then call_sudo "Please enter your password to run the mount command." || error_msg "Password incorrect." if [ ! -e $HOME/.smb.cnf ]; then error_msg "Please create the file $HOME/.smb.cnf with your network username and password. The file should be in the format: username=%WINDOWS_USERNAME% password=%WINDOWS_PASSWORD%" fi TARGET="$HOME/Network/$FOLDER" SERVICENAME=${VFSSHARE/smb:/} if [ $(mount | grep -c "$SERVICENAME") -gt 0 ]; then error_msg "The selected folder is already mounted." fi mkdir -p $TARGET sudo mount -t smbfs $SERVICENAME $TARGET -o credentials=$HOME/.smb.cnf,uid=$LOGNAME,gid=$LOGNAME,fmask=644,dmask=755 nautilus --no-desktop $TARGET else error_msg "The selected folder is not a windows share." fi exit 0