From 1cd0451ddf5e059a29d430a511690113dfd135d2 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Thu, 22 Oct 2020 21:51:08 +0200 Subject: [PATCH] Run as regular user and use sudo for installing --- src/__main__.py | 4 ++-- src/util/install.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index 8d34a8a..42e71b7 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -5,8 +5,8 @@ from src.util.user import Input, Print def main(): - if os.geteuid() != 0: - Print.err("You need to run this program as root user") + if os.geteuid() == 0: + Print.err("You can't to run this program as root user") return if Input.yes_no("Do you wish to perform package install (from `packages.yaml`)?"): diff --git a/src/util/install.py b/src/util/install.py index bd7c408..bac53b0 100644 --- a/src/util/install.py +++ b/src/util/install.py @@ -1,4 +1,8 @@ +import shutil +import os + from src.util import command +from src.util.user import Print class Install: @@ -9,11 +13,11 @@ class Install: def upgrade_pacman() -> None: """Run full sync, refresh the package database and upgrade.""" - command.execute("pacman -Syu") + command.execute("sudo pacman -Syu") def pacman_install(package: str) -> None: """Install given `package`""" - command.execute(f"pacman -S {package}") + command.execute(f"sudo pacman -S {package}") def yay_install(package: str) -> None: """Install give package via `yay` (from AUR)""" @@ -21,4 +25,25 @@ class Install: def git_install(url: str) -> None: """Clone a git repository with given `url`""" - command.execute(f"git clone {url}") + dir_name = url.split("/")[-1].replace(".git", "") + if os.path.exists(dir_name): + Print.cancel(f"Git repository {dir_name} already exists") + + ret_code = command.get_return_code(f"git clone {url}") + if ret_code == 128: + Print.warning(f"Unable to install git repository {url}") + return + + if not os.path.exists(f"{dir_name}/PKGBUILD"): + Print.comment(f"Git repository {dir_name} doesn't contain PKGBUILD, only downloaded.") + return + + cwd = os.getcwd() + print(cwd) + + os.chdir(dir_name) + + command.execute("makepkg -si") + + os.chdir(cwd) + shutil.rmtree(dir_name)