def undo_troubleshoot_nvidia_2():
    if os.path.isfile("/etc/modprobe.d/50-bbswitch.conf"):
        subprocess.call("sudo rm /etc/modprobe.d/50-bbswitch.conf", shell=True)
        talwin("Please do not power off or unplug your machine.\n", "red")
        subprocess.call(" sudo dracut -f", shell=True)
    else:
        return main("Nothing To Do.")
def undo_troubleshoot_nvidia_2():
	if os.path.isfile("/etc/modprobe.d/50-bbswitch.conf"):
		subprocess.call("sudo rm /etc/modprobe.d/50-bbswitch.conf",shell=True)
		talwin ("Please do not power off or unplug your machine.\n","red")
		subprocess.call(" sudo dracut -f",shell=True)
	else:
		return main("Nothing To Do.")
def msg(m):
	while True:
		subprocess.call("clear")
		print()
		talwin (m,"red")
		talwin("\nY To Continue || N To Back || Q To Quit : \n-","blue",end="")
		y_n=input().strip()
		if y_n=="Y" or y_n=="y":
			break
		elif y_n=="N" or y_n=="n":
			return main()
		elif y_n=="q" or y_n=="Q":
			sys.exit("\nBye...\n")
def msg(m):
    while True:
        subprocess.call("clear")
        print()
        talwin(m, "red")
        talwin("\nY To Continue || N To Back || Q To Quit : \n-",
               "blue",
               end="")
        y_n = input().strip()
        if y_n == "Y" or y_n == "y":
            break
        elif y_n == "N" or y_n == "n":
            return main()
        elif y_n == "q" or y_n == "Q":
            sys.exit("\nBye...\n")
def main(ms=""):
	if len(ms)!=0:
		ms="((((%s))))"%ms
	while True:
		welcome()
		talwin("Do You Want Install Open Source Driver Or Closed Source Driver?\n","blue")
		print("1-Install Nouveau Open Source Driver.\t\t\t\t\t\t 2-Install Nvidia Closed Source Driver.\n\n\n3-Level 1 Troubleshoot Nvidia Closed Source Driver\t\t\t\t 4-Level 2 Troubleshoot Nvidia Closed Source Driver\n\n\n5-Undo Level 2 Troubleshoot Nvidia Closed Source Driver.\t\t\t 6-Troubleshoot Nouveau Open Source Driver\n\n\n7-Remove Nouveau Open Source Driver.                                             8-Remove Nvidia CLosed Source Driver.\n\n\n9-Remove All Driver.                                                             10-Install Gnome Shell Extentios.")
		talwin("\n%s\n"%ms,"red")
		talwin("Choice Number || q to Exit.\n-","blue",end="")
		answer=input().strip()
		ms=""
		if answer=="1":
			msg("Remove Nvidia Closed Source Driver || Install Nouveau Open Source Driver.")
			nouveau()
			return main("Finish Reboot Your Machine.")
		elif answer=="2":
			msg("Remove Nouveau Open Source Driver || Install Nvidia Closed Source Driver.")
			nvidia()
			return main("Finish Reboot Your Machine.")
			
			
		elif answer=="3":
			msg("Remove Nouveau Open Source Driver ||Reinstall Nvidia Closed Source Driver.")
			troubleshoot_nvidia_1()
			return main("Finish Reboot Your Machine.")
		elif answer=="4":
			msg("Add Option \"options bbswitch load_state=-1 unload_state=1\" To /etc/modprobe.d/50-bbswitch.conf And Rebuild initramfs.")
			troubleshoot_nvidia_2()
			return main("Finish Reboot Your Machine.")
		elif answer=="5":
			msg("Remove File /etc/modprobe.d/50-bbswitch.conf And Rebuild initramfs.")
			undo_troubleshoot_nvidia_2()
			return main("Finish Reboot Your Machine.")
		elif answer=="6":
			msg("Remove Nvidia Closed Source Driver || Reinstall Nouveau Open Source Driver.")
			troubleshoot_nouveau()
			return main("Finish Reboot Your Machine.")
			
			
		elif answer=="7":
			msg("Remove Nouveau Open Source Driver.")
			remove_nouveau()
			return main("Finish Reboot Your Machine.")
		elif answer=="8":
			msg("Remove Nvidia Closed Source Driver.")
			remove_nvidia()
			return main("Finish Reboot Your Machine.")
		elif answer=="9":
			msg("Remove Nouveau And Nvidia Drivers.")
			remove_nouveau()
			remove_nvidia()
			return main("Finish Reboot Your Machine.")
			
		elif answer=="10":
			msg("Install Gnome Shell Extentions.")
			gnome_extensions()
			return main("Finish Reboot Your Machine.")
			
		elif answer=="q" or answer=="Q":
			sys.exit("\nBye...\n")
def main(ms=""):
    if len(ms) != 0:
        ms = "((((%s))))" % ms
    while True:
        welcome()
        talwin("Do You Want Install Nvidia Closed Source Driver?\n", "blue")
        print(
            "1-Install Nvidia Closed Source Driver.\t\t\t\t\t2-Level 1 Troubleshoot Nvidia Closed Source Driver\n\n\n3-Level 2 Troubleshoot Nvidia Closed Source Driver\t\t\t4-Undo Level 2 Troubleshoot Nvidia Closed Source Driver.\n\n\n5-Remove Nvidia CLosed Source Driver.\t\t\t\t\t6-Install Gnome Shell Extentions."
        )
        talwin("\n%s\n" % ms, "red")
        talwin("Choice Number || q to Exit.\n-", "blue", end="")
        answer = input().strip()
        ms = ""
        if answer == "1":
            msg("Install Nvidia Closed Source Driver.")
            nvidia()
            return main("Finish Reboot Your Machine.")

        elif answer == "2":
            msg("Reinstall Nvidia Closed Source Driver.")
            troubleshoot_nvidia_1()
            return main("Finish Reboot Your Machine.")

        elif answer == "3":
            msg("Add Option \"options bbswitch load_state=-1 unload_state=1\" To /etc/modprobe.d/50-bbswitch.conf And Rebuild initramfs."
                )
            troubleshoot_nvidia_2()
            return main("Finish Reboot Your Machine.")

        elif answer == "4":
            msg("Remove File /etc/modprobe.d/50-bbswitch.conf And Rebuild initramfs."
                )
            undo_troubleshoot_nvidia_2()
            return main("Finish Reboot Your Machine.")

        elif answer == "5":
            msg("Remove Nvidia Closed Source Driver.")
            remove_nvidia()
            return main("Finish Reboot Your Machine.")

        elif answer == "6":
            msg("Install Gnome Shell Extentions.")
            gnome_extensions()
            return main("Finish Reboot Your Machine.")

        elif answer == "q" or answer == "Q":
            sys.exit("\nBye...\n")
def welcome():
	subprocess.call("clear")
	welcom="""
*******************************************************************
*[[[[[[[[[[[[[[[[[[[[[[[[          ~~~~~~~~~~~~~~~~~~~~~~~~~      *
*[[[[[[[[[[[[[[[[[[[[[[[[          ~~~~~~~~~~~~~~~~~~~~~~~~~      *
*{{{{{{{{{{{,{{{{{{{{{{{{          [{{{{{{{{{{{{{{{{{{{{{{{{      *
*{{{{{{{{{{,,,{{{{{{{{{{{          [[{{{{{{{{{{{{{{{{{{{{{{{      *
*{{{{{{{{{,,,,,{{{{{{{{{{          [[[{{{{{{{{{{{{{{{{{{{{{{      *
*{{{{{{{{,,,,,,,{{{{{{{{{          [[{{{{{{{{{{{{{{{{{{{{{{{      *
*{{{{{{{{{{,,,{{{{{{{{{{{          [{{{{{{{{{{{{{{{{{{{{{{{{      *
*[[[[[[[[[[[[[[[[[[[[[[[[          ,,,,,,,,,,,,,,,,,,,,,,,,,      *
*[[[[[[[[[[[[[[[[[[[[[[[[          ,,,,,,,,,,,,,,,,,,,,,,,,,      *
*                                                                 *
*Welcome to arfedora-nvidiab Copyright 2016 version 1.0           *
*youssef sourani <*****@*****.**>                    *
*www.arfedora.blogspot.com                                        *
*This is python script to install Bumblebee + Nvidia or Nouveau   *
*fedora    link:http://spins.fedoraproject.org/                   *
*favorite  link:http://www.linuxac.org/forum/forum.php            *
*******************************************************************\n\n"""              

	for i in welcom:
		if i=="*":
			talwin(i,"blue",end='')
		elif i=="["  :
			talwin(i,"red",bg="red",end='')
		elif i=="~"  :
			talwin(i,"black",bg="black",end='')
		elif i=="{"  :
			talwin(i,"white",bg="white",end='')
		elif i==",":
			talwin(i,"green",bg="green",end='')
		else :
			talwin(i,"yellow",end='')
def troubleshoot_nvidia_2():
	subprocess.call("echo \"options bbswitch load_state=-1 unload_state=1\" |sudo tee /etc/modprobe.d/50-bbswitch.conf",shell=True)
	talwin("Please do not power off or unplug your machine.\n","red")
	subprocess.call(" sudo dracut -f",shell=True)
def welcome():
    subprocess.call("clear")
    welcom = """
*******************************************************************
*[[[[[[[[[[[[[[[[[[[[[[[[          ~~~~~~~~~~~~~~~~~~~~~~~~~      *
*[[[[[[[[[[[[[[[[[[[[[[[[          ~~~~~~~~~~~~~~~~~~~~~~~~~      *
*{{{{{{{{{{{,{{{{{{{{{{{{          [{{{{{{{{{{{{{{{{{{{{{{{{      *
*{{{{{{{{{{,,,{{{{{{{{{{{          [[{{{{{{{{{{{{{{{{{{{{{{{      *
*{{{{{{{{{,,,,,{{{{{{{{{{          [[[{{{{{{{{{{{{{{{{{{{{{{      *
*{{{{{{{{,,,,,,,{{{{{{{{{          [[{{{{{{{{{{{{{{{{{{{{{{{      *
*{{{{{{{{{{,,,{{{{{{{{{{{          [{{{{{{{{{{{{{{{{{{{{{{{{      *
*[[[[[[[[[[[[[[[[[[[[[[[[          ,,,,,,,,,,,,,,,,,,,,,,,,,      *
*[[[[[[[[[[[[[[[[[[[[[[[[          ,,,,,,,,,,,,,,,,,,,,,,,,,      *
*                                                                 *
*Welcome to arfedora-nvidiab Copyright 2016 version 1.0           *
*youssef sourani <*****@*****.**>                    *
*www.arfedora.blogspot.com                                        *
*This is python script to install Bumblebee + Nvidia Driver       *
*fedora    link:http://spins.fedoraproject.org/                   *
*favorite  link:http://www.linuxac.org/forum/forum.php            *
*******************************************************************\n\n"""

    for i in welcom:
        if i == "*":
            talwin(i, "blue", end='')
        elif i == "[":
            talwin(i, "red", bg="red", end='')
        elif i == "~":
            talwin(i, "black", bg="black", end='')
        elif i == "{":
            talwin(i, "white", bg="white", end='')
        elif i == ",":
            talwin(i, "green", bg="green", end='')
        else:
            talwin(i, "yellow", end='')
def troubleshoot_nvidia_2():
    subprocess.call(
        "echo \"options bbswitch load_state=-1 unload_state=1\" |sudo tee /etc/modprobe.d/50-bbswitch.conf",
        shell=True)
    talwin("Please do not power off or unplug your machine.\n", "red")
    subprocess.call(" sudo dracut -f", shell=True)