Created
April 3, 2012 10:05
-
-
Save rafeca/2290798 to your computer and use it in GitHub Desktop.
Script to connect to several VPNs that use different racoon config files from the command line
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
#!/usr/bin/env ruby | |
CONFIGURED_INTERFACES = ["O2", "TID"] | |
VPN_INTERFACE_NAMES = "%s VPN" | |
RACOON_CONFIG_FILES = "/etc/racoon/racoon.conf.%s" | |
unless (ARGV.length > 0 && CONFIGURED_INTERFACES.include?(ARGV[0].upcase)) | |
puts "usage: vpn_connect [#{CONFIGURED_INTERFACES.join('|')}]" | |
exit 1 | |
end | |
interface = ARGV[0].upcase | |
CONFIGURED_INTERFACES.each do |int| | |
interface_name = VPN_INTERFACE_NAMES % int | |
is_enabled = `networksetup -showpppoestatus "#{interface_name}"` | |
unless is_enabled.include? 'disconnected' | |
puts "Disconnecting VPN #{int}..." | |
`networksetup -disconnectpppoeservice "#{interface_name}"` | |
end | |
end | |
interface_filename = RACOON_CONFIG_FILES % interface.downcase | |
puts "Copying racoon config file from interface #{interface}" | |
`cp #{interface_filename} /etc/racoon/racoon.conf` | |
puts "Connecting to VPN #{interface}" | |
`networksetup -connectpppoeservice "#{interface} VPN"` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment