#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#

import commands, os

# Do we use root?
if os.getuid() == 0:
#checks if the proxyswitch was started once, if not create copies of /etc/profile
    if commands.getoutput("ls -l /etc/profile").find("->") == -1:
        print("Der Proxyswitch wird vorbereitet, die Datei /etc/profile wird nach /etc/profile.none und /etc/profile.proxy kopiert. Bitte überprüfen sie die Dateien auf ihre Richtigkeit, bevor sie fortfahren.")
        os.system("cp /etc/profile /etc/profile.none")
        os.system("cp /etc/profile /etc/profile.proxy")
        os.system("rm /etc/profile")
        os.symlink("/etc/profile.none", "/etc/profile")
        quit()

#remove /etc/profile, no matter which file it is
    os.remove("/etc/profile")

#if a proxy is set, switch to none/if there's no proxy, use it
    if os.getenv("http_proxy"):
        print("Proxy gefunden, wechsle zu keinem...")
        os.symlink("/etc/profile.none", "/etc/profile")
    else:
        print("kein Proxy, wechsle auf Proxy...")
        os.symlink("/etc/profile.proxy", "/etc/profile")

    print("Die Datei wurde gewechselt, bitte neu anmelden!")
    
else: 
    print("""Der Proxyswitch muss mit root-Rechten gestartet werden, bitte versuche es noch einmal
Versuche auch sudo (-E)""")
