Skip to content

Commit

Permalink
Merge pull request #21 from felipealfonsog/development
Browse files Browse the repository at this point in the history
Updates - new futures
  • Loading branch information
felipealfonsog committed Feb 22, 2024
2 parents ce72596 + b6b2ddf commit 2b4fa99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/upd8all_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import getpass
import subprocess
import select
import pty
import json

# Function to print the welcome message
Expand All @@ -20,7 +19,7 @@ def print_welcome_message():
""")

# Function to execute a command with sudo as needed
def execute_command_with_sudo(command):
def execute_command_with_sudo(command, sudo_password):
proc = subprocess.Popen(
["sudo", "-S", *command.split()],
stdin=subprocess.PIPE,
Expand All @@ -30,7 +29,11 @@ def execute_command_with_sudo(command):
)

# Send sudo password
stdout, stderr = proc.communicate(input=sudo_password + '\n')
proc.stdin.write(sudo_password + '\n')
proc.stdin.flush()

# Wait for the process to complete
proc.communicate()
if proc.returncode != 0:
print(f"Error executing command with sudo: {command}")
sys.exit(1)
Expand All @@ -40,7 +43,7 @@ def update_pacman():
print("\nUpdating Pacman packages...")
print("-------------------------------------")
command = "pacman -Syu --noconfirm"
execute_command_with_sudo(command)
execute_command_with_sudo(command, sudo_password)

# Function to update AUR packages with Yay
def update_yay():
Expand Down
11 changes: 7 additions & 4 deletions src/upd8all_updater_unstable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import getpass
import subprocess
import select
import pty
import json

# Function to print the welcome message
Expand All @@ -20,7 +19,7 @@ def print_welcome_message():
""")

# Function to execute a command with sudo as needed
def execute_command_with_sudo(command):
def execute_command_with_sudo(command, sudo_password):
proc = subprocess.Popen(
["sudo", "-S", *command.split()],
stdin=subprocess.PIPE,
Expand All @@ -30,7 +29,11 @@ def execute_command_with_sudo(command):
)

# Send sudo password
stdout, stderr = proc.communicate(input=sudo_password + '\n')
proc.stdin.write(sudo_password + '\n')
proc.stdin.flush()

# Wait for the process to complete
proc.communicate()
if proc.returncode != 0:
print(f"Error executing command with sudo: {command}")
sys.exit(1)
Expand All @@ -40,7 +43,7 @@ def update_pacman():
print("\nUpdating Pacman packages...")
print("-------------------------------------")
command = "pacman -Syu --noconfirm"
execute_command_with_sudo(command)
execute_command_with_sudo(command, sudo_password)

# Function to update AUR packages with Yay
def update_yay():
Expand Down

0 comments on commit 2b4fa99

Please sign in to comment.