main script

This commit is contained in:
2025-06-19 17:53:04 +05:30
parent 90b2aba7c2
commit 268204b7a8

291
setup.py Normal file
View File

@@ -0,0 +1,291 @@
from InquirerPy import inquirer
import sys, os, ast
from shutil import which
if getattr(sys, 'frozen', False):
dir = sys._MEIPASS + "/"
else:
dir = os.path.dirname(os.path.realpath(__file__)) + "/"
menu2 = []
def detect_distro():
if which("pacman") is not None:
return "arch"
elif which("apt") is not None:
return "debian"
elif which("dnf") is not None or which("yum") is not None:
return "fedora"
else:
return "unknown"
def choices():
detected = detect_distro()
if detected == "arch":
with open(f"{dir}data/prompts/arch.txt") as menu:
return menu.read()
elif detected == "debian":
with open(f"{dir}data/prompts/debian.txt") as menu:
return menu.read()
elif detected == "fedora":
with open(f"{dir}data/prompts/fedora.txt") as menu:
return menu.read()
else:
return "Unsupported distro"
def menu():
global menu2
choices_list = choices().splitlines()
choices_list.append("Exit")
menu1 = inquirer.select(
message = "Main Menu",
choices = choices_list,
default = None,
multiselect = False
).execute()
if menu1 == "Exit":
sys.exit(0)
elif menu1 == "Select and Install Programs":
with open(f"{dir}data/prompts/programs.txt") as programs:
programs_list = programs.read().splitlines()
programs_list.append("Back to Main Menu")
menu2 = inquirer.select(
message = "Select programs to install",
choices = programs_list,
default = None,
multiselect = True
).execute()
if "Back to Main Menu" in menu2:
menu()
else:
install_programs()
elif menu1 == "Select and Install Flatpak Apps":
if "Back to Main Menu" in menu2:
menu()
else:
install_flatpaks()
elif menu1 == "Update System":
update_system()
elif menu1 == "Install Programs not Included in Distro repos":
with open(f"{dir}data/prompts/third-party.txt") as other:
other_list = other.read().splitlines()
other_list.append("Back to Main Menu")
menu2 = inquirer.select(
message = "Select programs to install",
choices = other_list,
default = None,
multiselect = True
).execute()
if "Back to Main Menu" in menu2:
menu()
else:
install_other()
elif menu1 == "Drivers":
vendors = ["NVIDIA", "AMD", "Intel", "Back to Main Menu"]
menu2 = inquirer.select(
message = "Select your GPU vendor",
choices = vendors,
default = None,
multiselect = False
).execute()
if menu2 == "Back to Main Menu":
menu()
else:
install_drivers(menu2)
elif menu1 == "Enable RPM Fusion":
enable_rpmfusion()
elif menu1 == "Install Programs from AUR":
with open(f"{dir}data/prompts/aur.txt") as aur:
aur_list = aur.read().splitlines()
aur_list.append("Back to Main Menu")
menu2 = inquirer.select(
message = "Select programs to install from AUR",
choices = aur_list,
default = None,
multiselect = True
).execute()
if "Back to Main Menu" in menu2:
menu()
else:
install_aur()
def install_programs():
detected_distro = detect_distro()
selected_programs = menu2
if detected_distro == "arch":
for program in selected_programs:
if program != "Back to Main Menu":
os.system(f"sudo pacman -S --noconfirm {program}")
else:
break
elif detected_distro == "debian":
for program in selected_programs:
if program != "Back to Main Menu":
os.system(f"sudo apt install -y {program}")
else:
break
elif detected_distro == "fedora":
for program in selected_programs:
if program != "Back to Main Menu":
os.system(f"sudo dnf install -y {program}")
else:
break
def install_flatpaks():
selected_flatpaks = []
if which("flatpak") == None:
y_n = [ "Yes", "No" ]
install_flatpak = inquirer.select(
message = "Flatpak is not installed. Do you want to install it?",
default = False,
choices = y_n,
multiselect = False
).execute()
if install_flatpak == "Yes":
if which("apt") is not None:
os.system("sudo apt install -y flatpak")
elif which("dnf") is not None or which("yum") is not None:
os.system("sudo dnf install -y flatpak")
elif which("pacman") is not None:
os.system("sudo pacman -S --noconfirm flatpak")
os.system("flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo")
else:
print("Flatpak installation aborted.")
menu()
else:
with open(f"{dir}data/prompts/flatpaks.txt") as flatpaks:
flatpaks_dict = ast.literal_eval(flatpaks.read())
flatpaks_list = list(flatpaks_dict.values())
flatpaks_list.append("Back to Main Menu")
menu2 = inquirer.select(
message = "Select Flatpak apps to install",
choices = flatpaks_list,
default = None,
multiselect = True
).execute()
if "Back to Main Menu" in menu2:
menu()
else:
seleted_flatpaks = []
for i in menu2:
for key, value in flatpaks_dict.items():
if i == value:
selected_flatpaks.append(key)
for flatpak in selected_flatpaks:
if flatpak != "Back to Main Menu":
os.system(f"flatpak install -y flathub {flatpak}")
else:
break
menu()
def update_system():
if which("yay") is not None:
os.system("yay --noconfirm")
elif which("pacman") is not None:
os.system("sudo pacman -Syu --noconfirm")
elif which("apt") is not None:
os.system("sudo apt update && sudo apt upgrade -y")
elif which("dnf") is not None or which("yum") is not None:
os.system("sudo dnf upgrade -y")
if which("flatpak") is not None:
os.system("flatpak update -y")
menu()
def install_aur():
selected_aur = menu2
if which("yay") is None:
y_n = [ "Yes", "No" ]
install_yay = inquirer.select(
message = "Yay is not installed. Do you want to install it?",
default = False,
choices = y_n,
multiselect = False
).execute()
if install_yay == "Yes":
os.system("sudo pacman -S git base-devel --noconfirm")
os.system("git clone https://aur.archlinux.org/yay.git")
os.chdir("yay")
os.system("makepkg -si --noconfirm")
else:
print("Yay installation aborted.")
menu()
elif which("yay") is not None:
for aur in selected_aur:
if aur != "Back to Main Menu":
os.system(f"yay -S --noconfirm {aur}")
else:
break
menu()
def enable_rpmfusion():
os.system("sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm -y")
os.system("sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm -y")
print("RPM Fusion has been enabled.")
menu()
def install_drivers(vendor):
if vendor == "AMD":
if which("apt") is not None:
os.system("sudo apt install -y mesa-vulkan-drivers mesa-va-drivers")
elif which("dnf") is not None or which("yum") is not None:
os.system("sudo dnf install -y mesa-va-drivers mesa-dri-drivers")
elif which("pacman") is not None:
os.system("sudo pacman -S --noconfirm mesa vulkan-radeon")
elif vendor == "Intel":
if which("apt") is not None:
os.system("sudo apt install -y mesa-va-drivers intel-media-va-driver")
elif which("dnf") is not None or which("yum") is not None:
os.system("sudo dnf install -y intel-media-driver")
elif which("pacman") is not None:
driver = ["intel-media-driver", "libva-intel-driver"]
gpu = inquirer.select(
message = "Choose driver",
choices = driver,
default = None,
multiselect = False
).execute()
if gpu == "intel-media-driver":
os.system("sudo pacman -S --noconfirm intel-media-driver")
elif gpu == "libva-intel-driver":
os.system("sudo pacman -S --noconfirm libva-intel-driver")
elif vendor == "NVIDIA":
if which("apt") is not None:
os.system("sudo apt install -y nvidia-driver")
elif which("dnf") is not None or which("yum") is not None:
os.system("sudo dnf install -y akmod-nvidia")
elif which("pacman") is not None:
os.system("sudo pacman -S --noconfirm nvidia")
menu()
def install_other():
selected_other = menu2
for other in selected_other:
os.system(f"bash {dir}data/scripts/third-party/" + other + ".sh")
menu()