Run as regular user and use sudo for installing

This commit is contained in:
ItsDrike 2020-10-22 21:51:08 +02:00
parent 5b30c96e4f
commit 1cd0451ddf
No known key found for this signature in database
GPG key ID: F4E8FF4F6AC7F3B4
2 changed files with 30 additions and 5 deletions

View file

@ -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`)?"):

View file

@ -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)