Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
felipealfonsog committed Feb 21, 2024
1 parent 5c9caee commit a4246fc
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions src/upd8all_updater.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a4246fc

Please sign in to comment.