TUTO - recent script for SMB auto-connect

75 views
Skip to first unread message

RainStars

unread,
Mar 11, 2021, 3:14:09 PM3/11/21
to tunnelblick-discuss
Hi everyone,

I recently tried to find a script that:
1. Auto-connect my smb share when I connect to my VPN
2. Eject when disconnecting
3. Prevent from errors and remount at awakening of the mac.

I didn't find anything recent that can do that, so I made it myself. It's not hard but I took some hours to collect all the data and commands I needed. Today i'm gonna share it with you.
Firstly, it seems to be difficult for a lot of people (me included) to know WHERE the scripts have to be set. 
In fact, it's quite simple. You don't need to edit the files of the tunnelblick app. Don't do this.
All you need to do, is to create your own *.tblk (config) file. 
yea, but how? 

All you need is all the OPENVPN files you have excepted the *.opnvpn. 
Set your *.config , your *.key and your *.crt file in a folder on your desktop for instance.

Then, add in this folder all the BASH (*.sh) scripts you want to use. For us, we'll need:
- pre-connect.sh
- connected.sh
- pre-diconnect.sh 
I wrote them in their order of execution.
 Those files are in attachement.

The pre-connect and post disconnect are both the same file, they have for job to unmount the smb share if it's mounted before and after the connection to prevent errors like "mountpoint already exists"

The connected file connects you to your share folder.

I used an important and very useful feature in this one:
Usually, scripts that tunnelblick uses are shell script, more complicated and less useful than apple scripts. The script connected.sh call Apple script, that allows to mount my smb volume WITHOUT opening it each time.
The config is made for, if your computer go to standbye, when it wakes-up, your smb share will automatically be reconnected with your vpn connection.

When all this is done, rename your folder with <A NAME.tblk>
(<A NAME> can be replaced by the word of your choice)
Then, make your folder slide into the tunnelblick window to add the configuration you made.

I'm not a pro for scripting but these are very useful and ask me anything if you need it or don't understand something!

scripts.zip

RainStars

unread,
Mar 11, 2021, 3:17:25 PM3/11/21
to tunnelblick-discuss
Let me know if I helped you, that would makes me happy (:
Reply all
Reply to author
Forward
0 new messages