From a4246fc369d9bdc46b4e34e664b0f7e291bd3eda Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 00:18:39 -0300 Subject: [PATCH] Updates --- src/upd8all_updater.py | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/upd8all_updater.py b/src/upd8all_updater.py index 5c9883a..e234d47 100644 --- a/src/upd8all_updater.py +++ b/src/upd8all_updater.py @@ -1,49 +1,41 @@ -import subprocess import os -import getpass +import sys def update_pacman(): print("Updating Pacman packages...") command = "sudo pacman -Syu --noconfirm" - execute_command_with_sudo(command) + os.system(command) def update_yay(): print("Updating AUR packages with Yay...") command = "yay -Syu --noconfirm" - execute_command_with_sudo(command) + os.system(command) def update_brew(): print("Updating packages with Homebrew...") command = "brew update && brew upgrade" - subprocess.run(command.split()) + os.system(command) def check_gh_update(): - command = "brew info gh" - output = subprocess.check_output(command.split()).decode("utf-8") - lines = output.splitlines() - for line in lines: - if "stable" in line and "gh" in line: - version = line.split()[1] - print(f"The updated gh version is: {version}") - -def execute_command_with_sudo(command): try: - subprocess.run(command.split(), check=True) - except subprocess.CalledProcessError: - # Command failed, request sudo password and retry - print("This command requires superuser privileges.") - password = getpass.getpass(prompt="Enter sudo password: ") - sudo_command = f"echo '{password}' | sudo -S {command}" - subprocess.run(sudo_command, shell=True) + command = "brew info gh" + output = os.popen(command).read() + lines = output.splitlines() + for line in lines: + if "stable" in line and "gh" in line: + version = line.split()[1] + print(f"The updated gh version is: {version}") + except Exception as e: + print(f"Error checking gh update: {e}") def main(): + if os.geteuid() == 0: + print("Error: Please do not run this script as root or using sudo.") + sys.exit(1) update_pacman() update_yay() update_brew() check_gh_update() if __name__ == "__main__": - if os.geteuid() != 0: - print("This program requires superuser privileges to run.") - exit(1) main()