[arch] feature: allowing AUR packages to be installed when bauh is launched by the root user

This commit is contained in:
Vinicius Moreira
2021-12-07 15:41:02 -03:00
parent afcc94b934
commit 6d3917ee99
21 changed files with 330 additions and 158 deletions

View File

@@ -1,20 +1,61 @@
import os
import re
from typing import Tuple, Optional, Set
from typing import Optional, Set, Tuple
from bauh.commons.system import SimpleProcess, ProcessHandler, run_cmd
from bauh.commons import system
from bauh.commons.system import ProcessHandler, SimpleProcess
from bauh.gems.arch import CUSTOM_MAKEPKG_FILE
from bauh.gems.arch.proc_util import write_as_user
RE_DEPS_PATTERN = re.compile(r'\n?\s+->\s(.+)\n')
RE_UNKNOWN_GPG_KEY = re.compile(r'\(unknown public key (\w+)\)')
RE_DEPS_PATTERN = re.compile(r'\n?\s+->\s(.+)\n')
def gen_srcinfo(build_dir: str, custom_pkgbuild_path: Optional[str] = None) -> str:
return run_cmd('makepkg --printsrcinfo{}'.format(' -p {}'.format(custom_pkgbuild_path) if custom_pkgbuild_path else ''),
cwd=build_dir)
def gen_srcinfo(build_dir: str, custom_pkgbuild_path: Optional[str] = None, custom_user: Optional[str] = None) -> str:
cmd = f"makepkg --printsrcinfo{' -p {}'.format(custom_pkgbuild_path) if custom_pkgbuild_path else ''}"
return system.run_cmd(cmd, cwd=build_dir, custom_user=custom_user)
def check(pkgdir: str, optimize: bool, missing_deps: bool, handler: ProcessHandler, custom_pkgbuild: Optional[str] = None) -> dict:
def update_srcinfo(project_dir: str, custom_user: Optional[str] = None) -> bool:
updated_src = system.run_cmd('makepkg --printsrcinfo', cwd=project_dir, custom_user=custom_user)
if updated_src:
return write_as_user(content=updated_src, file_path=f"{project_dir}/.SRCINFO", user=custom_user)
return False
def list_output_files(project_dir: str, custom_pkgbuild_path: Optional[str] = None,
custom_user: Optional[str] = None) -> Set[str]:
cmd = f"makepkg --packagelist{' -p {}'.format(custom_pkgbuild_path) if custom_pkgbuild_path else ''}"
output = system.run_cmd(cmd=cmd, print_error=False, cwd=project_dir, custom_user=custom_user)
if output:
return {p.strip() for p in output.split('\n') if p}
return set()
def build(pkgdir: str, optimize: bool, handler: ProcessHandler, custom_pkgbuild: Optional[str] = None,
custom_user: Optional[str] = None) -> Tuple[bool, str]:
cmd = ['makepkg', '-ALcsmf', '--skipchecksums', '--nodeps']
if custom_pkgbuild:
cmd.append('-p')
cmd.append(custom_pkgbuild)
if optimize:
if os.path.exists(CUSTOM_MAKEPKG_FILE):
handler.watcher.print(f'Using custom makepkg.conf -> {CUSTOM_MAKEPKG_FILE}')
cmd.append(f'--config={CUSTOM_MAKEPKG_FILE}')
else:
handler.watcher.print(f'Custom optimized makepkg.conf ({CUSTOM_MAKEPKG_FILE}) not found')
return handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir, shell=True, custom_user=custom_user))
def check(project_dir: str, optimize: bool, missing_deps: bool, handler: ProcessHandler,
custom_pkgbuild: Optional[str] = None, custom_user: Optional[str] = None) -> dict:
res = {}
cmd = ['makepkg', '-ALcfm', '--check', '--noarchive', '--nobuild', '--noprepare']
@@ -28,12 +69,12 @@ def check(pkgdir: str, optimize: bool, missing_deps: bool, handler: ProcessHandl
if optimize:
if os.path.exists(CUSTOM_MAKEPKG_FILE):
handler.watcher.print('Using custom makepkg.conf -> {}'.format(CUSTOM_MAKEPKG_FILE))
cmd.append('--config={}'.format(CUSTOM_MAKEPKG_FILE))
handler.watcher.print(f'Using custom makepkg.conf -> {CUSTOM_MAKEPKG_FILE}')
cmd.append(f'--config={CUSTOM_MAKEPKG_FILE}')
else:
handler.watcher.print('Custom optimized makepkg.conf ( {} ) not found'.format(CUSTOM_MAKEPKG_FILE))
handler.watcher.print(f'Custom optimized makepkg.conf ({CUSTOM_MAKEPKG_FILE}) not found')
success, output = handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir, shell=True))
success, output = handler.handle_simple(SimpleProcess(cmd, cwd=project_dir, shell=True, custom_user=custom_user))
if missing_deps and 'Missing dependencies' in output:
res['missing_deps'] = RE_DEPS_PATTERN.findall(output)
@@ -47,42 +88,3 @@ def check(pkgdir: str, optimize: bool, missing_deps: bool, handler: ProcessHandl
res['validity_check'] = True
return res
def make(pkgdir: str, optimize: bool, handler: ProcessHandler, custom_pkgbuild: Optional[str] = None) -> Tuple[bool, str]:
cmd = ['makepkg', '-ALcsmf', '--skipchecksums', '--nodeps']
if custom_pkgbuild:
cmd.append('-p')
cmd.append(custom_pkgbuild)
if optimize:
if os.path.exists(CUSTOM_MAKEPKG_FILE):
handler.watcher.print('Using custom makepkg.conf -> {}'.format(CUSTOM_MAKEPKG_FILE))
cmd.append('--config={}'.format(CUSTOM_MAKEPKG_FILE))
else:
handler.watcher.print('Custom optimized makepkg.conf ( {} ) not found'.format(CUSTOM_MAKEPKG_FILE))
return handler.handle_simple(SimpleProcess(cmd, cwd=pkgdir, shell=True))
def update_srcinfo(project_dir: str) -> bool:
updated_src = run_cmd('makepkg --printsrcinfo', cwd=project_dir)
if updated_src:
with open('{}/.SRCINFO'.format(project_dir), 'w+') as f:
f.write(updated_src)
return True
return False
def list_output_files(project_dir: str, custom_pkgbuild_path: Optional[str] = None) -> Set[str]:
output = run_cmd(cmd='makepkg --packagelist{}'.format(' -p {}'.format(custom_pkgbuild_path) if custom_pkgbuild_path else ''),
print_error=False,
cwd=project_dir)
if output:
return {p.strip() for p in output.split('\n') if p}
return set()