-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c9caee
commit a4246fc
Showing
1 changed file
with
16 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |