Last active
September 23, 2015 23:03
-
-
Save lazymutt/68cc5c4fd841d9a16734 to your computer and use it in GitHub Desktop.
Attempts to remove specific, duplicate profiles.
This file contains hidden or 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 python | |
# Copyright (c) 2015 University of Utah Student Computing Labs. ################ | |
# All Rights Reserved. | |
# | |
# Permission to use, copy, modify, and distribute this software and | |
# its documentation for any purpose and without fee is hereby granted, | |
# provided that the above copyright notice appears in all copies and | |
# that both that copyright notice and this permission notice appear | |
# in supporting documentation, and that the name of The University | |
# of Utah not be used in advertising or publicity pertaining to | |
# distribution of the software without specific, written prior | |
# permission. This software is supplied as is without expressed or | |
# implied warranties of any kind. | |
################################################################################ | |
# removeDuplicateVPNProfiles.py ################################################ | |
# 8/18/15, v0.1, [email protected] | |
# | |
# due to the way we're installing profiles in Mac OS X 10.10 with xhooks, multiple duplicate VPN profiles can appear. | |
# installing profiles by hand (terminal or finder) do not cause duplicates to appear, very odd. | |
# this script looks for duplicates and removes them. | |
# | |
################################################################################ | |
import subprocess | |
from management_tools import loggers | |
logger = loggers.file_logger(name='VPN_dupe_removal') | |
logger.info("Running duplicate VPN profile removal") | |
# dump network services and break into individual lines | |
checkForDupes = subprocess.check_output(["/usr/sbin/networksetup", "-listallnetworkservices"]) | |
checkForDupes = checkForDupes.split('\n') | |
# removes blank/empty lines | |
checkForDupes = [x for x in checkForDupes if x] | |
# copy out list of our VPN profiles | |
vpnProfiles = filter(lambda x: 'UofU VPN Profile' in x, checkForDupes) | |
logger.info("{} profiles found.".format(len(vpnProfiles))) | |
# if there's more than one, and it's got a number (ie "UofU VPN Profile 14") delete it and report | |
if len(vpnProfiles) > 1: | |
for x in vpnProfiles: | |
isDuplicate = any(c.isdigit() for c in x) | |
if isDuplicate == True: | |
logger.info("Deleting /usr/sbin/networksetup -removenetworkservice '{}'".format(x)) | |
clearingDupes = subprocess.check_output(["/usr/sbin/networksetup", "-removenetworkservice", x]) | |
else: | |
logger.info("No duplicate profiles found.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment