Sutff about my job and comments about personal activities. Take a look to the first idea.

Thursday, June 01, 2017

NetworkManager

When using NetworkManager, it is posible to start a VPN connection after a successful wireless connection.
I have autofs configured on my home directory, so I need to start autofs after VPN connection:
/etc/NetworkManager/dispatcher.d/10autofs

#!/bin/bash
SERVER='172.16.1.1'
# Nothing to do if user does not have requisite binaries.
ping -c 1 $SERVER &>/dev/null
if [ $? -ne 0 ]; then
        # server is down so unmount
        /etc/init.d/autofs stop
else
        # server is up
        /etc/init.d/autofs start
fi
Whenever a VPN or wireless disconnection ocurrs, I've to stop autofs:
/etc/NetworkManager/dispatcher.d/pre-down.d/autofs
#!/bin/bash
interface=$1 
status=$2
if [ "$interface" == "wlan0" ] || [ "$CONNECTION_ID" == "reyesdf-tap" ]; then
        for dir in $(mount | grep "/mnt/auto" | awk '{print $3}' | tail -n +2)
        do
            umount $dir
        done
        sleep 5
        /etc/init.d/autofs stop
fi

References for understanding the scripts:
https://wiki.archlinux.org/index.php/NetworkManager
https://developer.gnome.org/NetworkManager/unstable/NetworkManager.html