Skip to content

Instantly share code, notes, and snippets.

@thefotios
Created May 10, 2012 04:54
Show Gist options
  • Save thefotios/2651093 to your computer and use it in GitHub Desktop.
Save thefotios/2651093 to your computer and use it in GitHub Desktop.
This script disables certain yum repos when disconnected from a VPN
#!/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