Created
May 10, 2012 04:54
-
-
Save thefotios/2651093 to your computer and use it in GitHub Desktop.
This script disables certain yum repos when disconnected from a VPN
This file contains 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/bash | |
# This script will disable/enable yum repos when something happens to your VPN | |
# The first thing you will need to do is make copies of the repos you want to swap | |
# Modify the settings appropriately and set up symlinks for your current status | |
# Place this script in /etc/NetworkManager/dispatcher.d, chown to root, and chmod u+x | |
# | |
# RTFM: http://linux.die.net/man/8/networkmanager | |
# Inspired by http://www.techytalk.info/start-script-on-network-manager-successfull-connection/ | |
IF=$1 | |
STATUS=$2 | |
function modify(){ | |
status=$1 | |
pushd /etc/yum.repos.d > /dev/null | |
# Find any files like foo.repo.down | |
for repo in *.$status | |
do | |
target=$(echo "$repo" | sed "s/\.$status\$//") | |
ln -sf $target.$status $target | |
done | |
popd > /dev/null | |
} | |
if [ "$IF" == "tun0" ] | |
then | |
case "$2" in | |
vpn-up) | |
logger -s "VPN up" | |
modify "up" | |
;; | |
vpn-down) | |
logger -s "VPN down" | |
modify "down" | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment