438 lines
17 KiB
Python
438 lines
17 KiB
Python
from InquirerPy import inquirer
|
|
from shutil import which
|
|
import distro, subprocess, sys, ast, os
|
|
|
|
if getattr(sys, 'frozen', False):
|
|
dir = sys._MEIPASS + "/"
|
|
else:
|
|
dir = os.path.dirname(os.path.realpath(__file__)) + "/"
|
|
|
|
menu = []
|
|
|
|
def detect_distro():
|
|
detected_distro = distro.like()
|
|
if detected_distro == "ubuntu debian":
|
|
detected_distro = "debian"
|
|
if not distro.like():
|
|
detected_distro = distro.id()
|
|
|
|
return detected_distro
|
|
|
|
def choices():
|
|
global menu
|
|
data = []
|
|
if not data:
|
|
detected_distro = detect_distro()
|
|
if detected_distro == "arch":
|
|
data = open(f"{dir}prompts/arch.txt")
|
|
elif detected_distro == "debian":
|
|
data = open(f"{dir}prompts/debian.txt")
|
|
elif detected_distro == "fedora":
|
|
data = open(f"{dir}prompts/fedora.txt")
|
|
else:
|
|
data
|
|
choices1 = ast.literal_eval(data.read())
|
|
if "Exit" not in choices1:
|
|
choices1.append("Exit")
|
|
else:
|
|
choices1
|
|
menu = inquirer.select(
|
|
message = f"Choose an option on detected distro i.e. {detected_distro}",
|
|
choices = choices1,
|
|
default = None,
|
|
multiselect = False
|
|
).execute()
|
|
if "Exit" in menu:
|
|
sys.exit()
|
|
if detected_distro == "arch":
|
|
arch_choices()
|
|
elif detected_distro == "debian":
|
|
debian_choices()
|
|
elif detected_distro == "fedora":
|
|
fedora_choices()
|
|
|
|
def arch_choices():
|
|
if menu == "Select and Install Programs":
|
|
install_programs()
|
|
elif menu == "Select and Install Flatpak Apps":
|
|
install_flatpaks()
|
|
elif menu == "Update System":
|
|
update_system()
|
|
elif menu == "Install Programs from AUR":
|
|
install_aur()
|
|
elif menu == "Drivers":
|
|
driver_choice()
|
|
|
|
def debian_choices():
|
|
if menu == "Select and Install Programs":
|
|
install_programs()
|
|
elif menu == "Select and Install Flatpak Apps":
|
|
install_flatpaks()
|
|
elif menu == "Update System":
|
|
update_system()
|
|
elif menu == "Install Programs not Included in Distro repos":
|
|
third_party()
|
|
elif menu == "Drivers":
|
|
driver_choice()
|
|
|
|
def fedora_choices():
|
|
if menu == "Select and Install Programs":
|
|
install_programs()
|
|
elif menu == "Select and Install Flatpak Apps":
|
|
install_flatpaks()
|
|
elif menu == "Update System":
|
|
update_system()
|
|
elif menu == "Install Programs not Included in Distro repos":
|
|
third_party()
|
|
elif menu == "Enable RPM Fusion":
|
|
rpm_fusion()
|
|
elif menu == "Drivers":
|
|
driver_choice()
|
|
|
|
def install_programs():
|
|
data = open(f"{dir}prompts/programs.txt")
|
|
program_list = ast.literal_eval(data.read())
|
|
program_list.append("Back")
|
|
|
|
program_prompt = inquirer.select(
|
|
message = "Select programs to install",
|
|
choices = program_list,
|
|
default = None,
|
|
multiselect = True
|
|
).execute()
|
|
|
|
distro = detect_distro()
|
|
|
|
if "Back" in program_prompt:
|
|
choices()
|
|
elif distro == "debian":
|
|
try:
|
|
command = subprocess.run(["sudo", "apt", "update"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to update cache {e.returncode}")
|
|
for i in program_prompt:
|
|
if distro == "arch":
|
|
if which("yay") != None:
|
|
try:
|
|
command = subprocess.run(["yay", "-S", i], text = True)
|
|
print(command)
|
|
except subprocess.ChildProcessError as e:
|
|
print(f"Failed to install {i} with {e.returncode}")
|
|
else:
|
|
try:
|
|
command = subprocess.run(["sudo", "pacman", "-S", i], text = True)
|
|
print(command)
|
|
except subprocess.ChildProcessError as e:
|
|
print(f"Failed to install {i} with {e.returncode}")
|
|
elif distro == "debian":
|
|
try:
|
|
command = subprocess.run(["sudo", "apt", "install", i], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install {i} with {e.returncode}")
|
|
elif distro == "fedora":
|
|
try:
|
|
command = subprocess.run(["sudo", "dnf", "install", i], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install {i} with {e.returncode}")
|
|
choices()
|
|
|
|
def install_flatpaks():
|
|
if which("flatpak") == None:
|
|
yes_no = ["yes", "no"]
|
|
flatpak_install = inquirer.select(
|
|
message = "No flatpak installation detected. Install flatpak now?",
|
|
choices = yes_no,
|
|
default = None,
|
|
multiselect = False,
|
|
).execute()
|
|
detected_distro = detect_distro()
|
|
if flatpak_install == "yes":
|
|
if detected_distro == "arch":
|
|
try:
|
|
command = subprocess.run(["sudo", "pacman", "-S", "flatpak"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install flatpak with {e.returncode}")
|
|
elif detected_distro == "debian":
|
|
try:
|
|
command1 = subprocess.run(["sudo", "apt", "update"], text = True)
|
|
command2 = subprocess.run(["sudo", "apt", "install", "flatpak"], text = True)
|
|
print(command1, command2)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install flatpak with {e.returncode}")
|
|
elif detected_distro == "fedora":
|
|
try:
|
|
command = subprocess.run(["sudo", "dnf", "install", "flatpak"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install flatpak with {e.returncode}")
|
|
else:
|
|
choices()
|
|
else:
|
|
try:
|
|
command = subprocess.run(["flatpak", "remote-add", "--if-not-exists", "flathub", "https://flathub.org/repo/flathub.flatpakrepo"], text=True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to add flathub as source with {e.returncode}")
|
|
with open(f"{dir}prompts/flatpaks.txt") as data:
|
|
flatpak_dict = ast.literal_eval(data.read())
|
|
flatpaks = []
|
|
for description in flatpak_dict.values():
|
|
flatpaks.append(description)
|
|
flatpaks.append("Back")
|
|
prompt = inquirer.select(
|
|
message = "Select flatpaks",
|
|
choices = flatpaks,
|
|
multiselect = True,
|
|
default = None
|
|
).execute()
|
|
selected = []
|
|
if "Back" in prompt:
|
|
choices()
|
|
else:
|
|
for i in prompt:
|
|
for key, value in flatpak_dict.items():
|
|
if i == value:
|
|
selected.append(key)
|
|
for i in selected:
|
|
try:
|
|
command = subprocess.run(["flatpak", "install", i], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install {i} with {e.returncode}")
|
|
choices()
|
|
|
|
def update_system():
|
|
distro = detect_distro()
|
|
if distro == "arch":
|
|
if which("yay") != None:
|
|
try:
|
|
command = subprocess.run(["yay", "-Syu"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to update {distro} with {e.returncode}")
|
|
else:
|
|
try:
|
|
command = subprocess.run(["sudo", "pacman", "-Syu"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to update {distro} with {e.returncode}")
|
|
elif distro == "debian":
|
|
try:
|
|
command1 = subprocess.run(["sudo", "apt", "update"], text = True)
|
|
command2 = subprocess.run(["sudo", "apt", "upgrade"], text = True)
|
|
print(command1, command2)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to update {distro} with {e.returncode}")
|
|
elif distro == "fedora":
|
|
try:
|
|
command = subprocess.run(["sudo", "dnf", "up"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to update {distro} with {e.returncode}")
|
|
choices()
|
|
|
|
def install_aur():
|
|
if which("yay") == None:
|
|
yes_no = ["yes", "no"]
|
|
prompt = inquirer.select(
|
|
message = "AUR helper not detected. Install yay?",
|
|
choices = yes_no,
|
|
default = None,
|
|
multiselect = False
|
|
).execute()
|
|
if prompt == "yes":
|
|
try:
|
|
command1 = subprocess.run(["sudo", "pacman", "-S", "--needed", "git", "base-devel"], text = True)
|
|
command2 = subprocess.run(["git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si"],shell = True, text = True)
|
|
print(command1, command2)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install yay with {e.returncode}")
|
|
else:
|
|
choices()
|
|
elif which("yay") != None:
|
|
with open(f"{dir}prompts/aur.txt") as data:
|
|
aur = ast.literal_eval(data.read())
|
|
aur.append("Back")
|
|
action = inquirer.select(
|
|
message = "Select programs",
|
|
choices = aur,
|
|
default = None,
|
|
multiselect = True
|
|
).execute()
|
|
if "Back" in action:
|
|
choices()
|
|
elif "Back" not in action:
|
|
for i in action:
|
|
try:
|
|
command = subprocess.run(["yay", "-S", i], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install {i} with {e.returncode}")
|
|
choices()
|
|
|
|
def third_party():
|
|
global dir
|
|
with open(f"{dir}prompts/third-party.txt") as data:
|
|
programs = ast.literal_eval(data.read())
|
|
programs.append("Back")
|
|
action = inquirer.select(
|
|
message = "Select programs",
|
|
default = None,
|
|
choices = programs,
|
|
multiselect = True
|
|
).execute()
|
|
if "Back" in action:
|
|
choices()
|
|
elif "Back" not in action:
|
|
for i in action:
|
|
if i == "docker":
|
|
try:
|
|
command = subprocess.run(["curl -sSL https://get.docker.com | sh"], shell = True, text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install docker with {e.returncode}")
|
|
elif i == "tailscale":
|
|
try:
|
|
command = subprocess.run(["curl -fsSL https://tailscale.com/install.sh | sh"], shell = True, text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install tailscale with {e.returncode}")
|
|
elif i == "oh-my-posh":
|
|
try:
|
|
command = subprocess.run(["curl -s https://ohmyposh.dev/install.sh | sudo bash -s"], shell = True, text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install oh-my-posh with {e.returncode}")
|
|
elif i == "openvpn3":
|
|
ovpn_script_path = dir + "bash/openvpn3.sh"
|
|
nl_ovpn = os.path.join(dir, "config/nl.ovpn")
|
|
creds = os.path.join(dir, "config/pass.txt")
|
|
try:
|
|
command = subprocess.run(["bash", ovpn_script_path, nl_ovpn, creds], text=True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Command failed with {e.returncode}")
|
|
|
|
choices()
|
|
|
|
def rpm_fusion():
|
|
try:
|
|
fedora_version = subprocess.check_output(["rpm", "-E", "%fedora"], text=True).strip() # Detect fedora version
|
|
command = subprocess.run([
|
|
"sudo", "dnf", "install",
|
|
f"https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-{fedora_version}.noarch.rpm",
|
|
f"https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-{fedora_version}.noarch.rpm"
|
|
], text=True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Command failed with {e.returncode}")
|
|
|
|
def driver_choice():
|
|
gpu = inquirer.select(
|
|
message = "Select your gpu",
|
|
default = None,
|
|
multiselect = False,
|
|
choices = ["intel", "nvidia", "amd", "Back"]
|
|
).execute()
|
|
if gpu == "Back":
|
|
choices()
|
|
elif gpu == "intel":
|
|
intel_drivers()
|
|
elif gpu == "amd":
|
|
amd_drivers()
|
|
elif gpu == "nvidia":
|
|
nvidia_drivers()
|
|
|
|
def intel_drivers():
|
|
distro = detect_distro()
|
|
if distro == "arch":
|
|
intel_model = inquirer.select(
|
|
message = "Select intel gpu driver",
|
|
default = None,
|
|
multiselect = False,
|
|
choices = ["intel-media-driver", "libva-intel-driver", "Back"]
|
|
).execute()
|
|
if "Back" in intel_model:
|
|
driver_choice()
|
|
elif "Back" not in intel_model:
|
|
if "intel-media-driver" in intel_model:
|
|
try:
|
|
command = subprocess.run(["sudo","pacman", "-S", "mesa", "intel-media-driver"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
else:
|
|
try:
|
|
command = subprocess.run(["sudo", "pacman", "-S", "mesa" "libva-intel-driver"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
elif distro == "debian":
|
|
try:
|
|
command1 = subprocess.run(["sudo", "apt", "update"], text = True)
|
|
command2 = subprocess.run(["sudo", "apt", "install", "mesa-va-drivers", "intel-media-va-driver"], text = True)
|
|
print(command1, command2)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
elif distro == "fedora":
|
|
rpm_fusion()
|
|
try:
|
|
command = subprocess.run(["sudo", "dnf", "install", "intel-media-driver", "libva", "mesa-dri-drivers", "mesa-dri-drivers", "mesa-va-drivers"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
choices()
|
|
|
|
def amd_drivers():
|
|
distro = detect_distro()
|
|
if distro == "arch":
|
|
try:
|
|
command = subprocess.run(["sudo", "pacman", "-S", "mesa"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
elif distro == "debian":
|
|
try:
|
|
command1 = subprocess.run(["sudo", "apt", "update"], text = True)
|
|
command2 = subprocess.run(["sudo", "apt", "install", "mesa-va-drivers", "mesa-vulkan-drivers", "mesa-vdpau-drivers"], text = True)
|
|
print(command1, command2)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
elif distro == "fedora":
|
|
try:
|
|
command = subprocess.run(["sudo", "dnf", "install", "mesa-va-drivers", "mesa-dri-drivers"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
choices()
|
|
|
|
def nvidia_drivers():
|
|
distro = detect_distro()
|
|
if distro == "arch":
|
|
try:
|
|
command = subprocess.run(["sudo", "pacman", "-S", "nvidia-open"], text = True)
|
|
print(command)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
elif distro == "fedora":
|
|
try:
|
|
rpm_fusion()
|
|
command1 = subprocess.run(["sudo", "dnf", "up"], text = True)
|
|
command2 = subprocess.run(["sudo", "dnf", "install", "akmod-nvidia"], text = True)
|
|
print(command1, command2)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
elif distro == "debian":
|
|
try:
|
|
install_nvidia_script = dir + "bash/nvidia-debian.sh"
|
|
command = subprocess.run(["bash", install_nvidia_script], text = True)
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Failed to install with {e.returncode}")
|
|
choices()
|
|
|
|
choices()
|