Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Does anyone know how to automatically mount a network share once a VPN connection using Tunnelblick has connected?

Right now I have to connect and then do a cmd+K in the finder to connect to the AFP share. It'd be nice if it would connect automatically.

The share doesn't have a password (TimeCapsule without any passwords, and no, not using it for backup, we use it for a fileserver).

share|improve this question

1 Answer 1

1.

Edit the file /Applications/Tunnelblick.app/Contents/Resources/client.up.osx.sh and add these commands at the end of the file, just before exit 0 :

su USERNAME -c '
mkdir /Volumes/TimeCapsule
mount_afp afp://afp_username@server/volumename /Volumes/TimeCapsule
'
open /Volumes/TimeCapsule

Replace USERNAME with your username on the system.

2.

Then add the following at the end of /Applications/Tunnelblick.app/Contents/Resources/client.down.osx.sh :

umount /Volumes/TimeCapsule

3.

Do not forget to check the set nameserver option for your configuration :

nameserver

Warning : Configuration files client.(up|down).osx.sh are executed for every connections made using OpenVPN.

This could also be made using launchd for watching if the vpn connection is up, but I don't know how to use launchd.

share|improve this answer
    
Did you forget a line? It isn't working, and when I stick the code directly into Terminal, it asks for my password. Possibly that's why it isn't running in the up script too? Actually, removing the su line (and it's counterpart ' below) doesn't work either. I would expect it to at least make the dir and possibly connect, but not let me access the folder. (and yep, set nameserver is checked) –  Cameron Conner Aug 22 '10 at 1:16
    
The su command is used to impersonate someone (you in this case). Both scripts are executed as root and he doesn't need a password when using su but another user will need one. If the command inside su isn't working alone, the problem comes from here. What exactly did you type ? –  Studer Aug 22 '10 at 11:28
    
Okay, wasn't sure that tunnelblick would run it as root. If I take the command inside of the su and drop it directly into terminal, it runs fine. If I remove the su part and just have the command in the up script, nothing happens. # Generate an updated plist with the proper path DIR="$(dirname "${0}")" LEASE_WATCHER="${DIR}/LeaseWatch.plist" sed -e "s|\${DIR}|${DIR}|g" "${LEASE_WATCHER}.template" > "${LEASE_WATCHER}" launchctl load "${LEASE_WATCHER}" # autoconnect server2 mkdir /Volumes/Data mount_afp afp://192.168.2.2/Data /Volumes/Data open /Volumes/Data exit 0 –  Cameron Conner Aug 22 '10 at 17:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.