From 09c95ece52456dc008283e626dd2a8b8ce2a0eec Mon Sep 17 00:00:00 2001 From: Marc Liyanage Date: Sun, 2 Jun 2013 12:43:49 -0700 Subject: [PATCH] Re-run mitmproxywrapper.py with sudo if necessary. --- examples/mitmproxywrapper.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/mitmproxywrapper.py b/examples/mitmproxywrapper.py index 751332b7f..344cd53b8 100755 --- a/examples/mitmproxywrapper.py +++ b/examples/mitmproxywrapper.py @@ -11,6 +11,8 @@ import subprocess import re import argparse import contextlib +import os +import sys class Wrapper(object): @@ -103,6 +105,12 @@ class Wrapper(object): if self.proxy_enabled_for_service(service_name): self.disable_proxy_for_service(service_name) + @classmethod + def ensure_superuser(cls): + if os.getuid() != 0: + print 'Relaunching with sudo...' + os.execv('/usr/bin/sudo', ['/usr/bin/sudo'] + sys.argv) + @classmethod def main(cls): parser = argparse.ArgumentParser(description='Helper tool for OS X proxy configuration and mitmproxy') @@ -122,5 +130,6 @@ class Wrapper(object): if __name__ == '__main__': + Wrapper.ensure_superuser() Wrapper.main()