Skip to content

Commit

Permalink
0.9.23
Browse files Browse the repository at this point in the history
  • Loading branch information
vinifmor authored Dec 10, 2021
2 parents 68ae349 + f6e5b08 commit ad249b2
Show file tree
Hide file tree
Showing 29 changed files with 440 additions and 210 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [0.9.23] 2021-12-10
### Features
- General
- new configuration file `/etc/bauh/gems.forbidden` can be used by system administrators/distribution package managers to disable the management of supported packaging formats globally (more on that [here](https://github.com/vinifmor/bauh#forbidden_gems))

- Arch
- allowing AUR packages to be installed when bauh is launched by the root user [#196](https://github.com/vinifmor/bauh/issues/196)
- it creates a non-root user called **bauh-aur** for building the packages (`useradd` and `runuser` commands must be installed)

### Improvements
- code refactoring (String formatting method)

### Fixes
- Arch
- not updating the view (GUI) status correctly after uninstalling a package whose PKGBUILD file was edited (specifically the **name**)
- missing error handling when hard requirements for optional dependencies cannot be found by pacman


## [0.9.22] 2021-11-30
### Improvements
- General
Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ Key features


## Index
1. [Installation](#installation)
1. [Installation](#installation)
- [Ubuntu-based distros (20.04)](#inst_ubuntu)
- [Arch-based distros](#inst_arch)
2. [Isolated installation](#inst_iso)
3. [Desktop entry / menu shortcut](#desk_entry)
4. [Autostart: tray mode](#autostart)
5. [Distribution](#dist)
6. [Supported types](#types)
2. [Isolated installation](#inst_iso)
3. [Desktop entry / menu shortcut](#desk_entry)
4. [Autostart: tray mode](#autostart)
5. [Distribution](#dist)
6. [Supported types](#types)
- [AppImage](#type_appimage)
- [Arch packages/AUR](#type_arch)
- [Flatpak](#type_flatpak)
- [Snap](#type_snap)
- [Native Web applications](#type_web)
7. [General settings](#settings)
8. [Directory structure, caching and logs](#dirs)
9. [Custom themes](#custom_themes)
7. [General settings](#settings)
- [Forbidden packaging formats](#forbidden_gems)
8. [Directory structure, caching and logs](#dirs)
9. [Custom themes](#custom_themes)
10. [Tray icons](#tray_icons)
11. [CLI (Command Line Interface)](#cli)
12. [Improving performance](#performance)
Expand Down Expand Up @@ -240,6 +241,9 @@ suggestions:

- If you have AUR added as a repository on you pacman configuration, make sure to disable bauh's support (through the settings described below)
- AUR package compilation may require additional installed packages to work properly. Some of them are defined on the field `optdepends` of the [PKGBUILD](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=bauh)
- for a **root** user the following additional applications must be installed:
- `useradd`: required to create a simple user named **bauh-aur** (since **makepkg** does not allow building packages as the **root** user)
- `runuser`: required to run commands as another user
- **Repository packages currently do not support the following actions: Downgrade and History**
- If some of your installed packages are not categorized, open a PullRequest to the **bauh-files** repository changing [categories.txt](https://github.com/vinifmor/bauh-files/blob/master/arch/categories.txt)
- During bauh initialization a full AUR normalized index is saved at `~/.cache/bauh/arch/aur/index.txt`
Expand Down Expand Up @@ -410,6 +414,16 @@ boot:
load_apps: true # if the installed applications or suggestions should be loaded on the management panel after the initialization process. Default: true.
```

##### <a name="forbidden_gems">Forbidden packaging formats</a>
- System administrators and package managers of Linux distributions can disable the usage/management of supported packaging formats
by adding their ids to the file `/etc/bauh/gems.forbidden`. This will prevent their management code to be loaded.
- Example (one id per line):
```
arch
appimage
# flatpak # 'sharps' can be used to ignore a given line (comment)
```

#### <a name="dirs">Directory structure, caching and logs</a>
- `~/.config/bauh` (or `/etc/bauh` for **root**): stores configuration files
- `~/.cache/bauh` (or `/var/cache/bauh` for **root**): stores data about your installed applications, databases, indexes, etc. Files are stored here to provide a faster initialization and data recovery.
Expand Down
2 changes: 1 addition & 1 deletion bauh/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.9.22'
__version__ = '0.9.23'
__app_name__ = 'bauh'

import os
Expand Down
7 changes: 6 additions & 1 deletion bauh/api/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
from bauh import __app_name__
from bauh.api import user


def get_temp_dir(username: str) -> str:
return f'/tmp/{__app_name__}@{username}'


CACHE_DIR = f'/var/cache/{__app_name__}' if user.is_root() else f'{Path.home()}/.cache/{__app_name__}'
CONFIG_DIR = f'/etc/{__app_name__}' if user.is_root() else f'{Path.home()}/.config/{__app_name__}'
USER_THEMES_DIR = f'/usr/share/{__app_name__}/themes' if user.is_root() else f'{Path.home()}/.local/share/{__app_name__}/themes'
DESKTOP_ENTRIES_DIR = '/usr/share/applications' if user.is_root() else f'{Path.home()}/.local/share/applications'
TEMP_DIR = f'/tmp/{__app_name__}@{getuser()}'
TEMP_DIR = get_temp_dir(getuser())
LOGS_DIR = f'{TEMP_DIR}/logs'
AUTOSTART_DIR = f'/etc/xdg/autostart' if user.is_root() else f'{Path.home()}/.config/autostart'
BINARIES_DIR = f'/usr/local/bin' if user.is_root() else f'{Path.home()}/.local/bin'
Expand Down
3 changes: 2 additions & 1 deletion bauh/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def main():
internet_checker=InternetChecker(offline=False),
root_user=user.is_root())

managers = gems.load_managers(context=context, locale=i18n.current_key, config=app_config, default_locale=DEFAULT_I18N_KEY)
managers = gems.load_managers(context=context, locale=i18n.current_key, config=app_config,
default_locale=DEFAULT_I18N_KEY, logger=logger)

cli = CLIManager(GenericSoftwareManager(managers, context=context, config=app_config))

Expand Down
38 changes: 22 additions & 16 deletions bauh/commons/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ class SimpleProcess:
def __init__(self, cmd: List[str], cwd: str = '.', expected_code: int = 0,
global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG, root_password: str = None,
extra_paths: Set[str] = None, error_phrases: Set[str] = None, wrong_error_phrases: Set[str] = None,
shell: bool = False,
success_phrases: Set[str] = None, extra_env: Optional[Dict[str, str]] = None):
shell: bool = False, success_phrases: Set[str] = None, extra_env: Optional[Dict[str, str]] = None,
custom_user: Optional[str] = None):
pwdin, final_cmd = None, []

self.shell = shell
if root_password is not None:

if custom_user:
final_cmd.extend(['runuser', '-u', custom_user, '--'])
elif root_password is not None:
final_cmd.extend(['sudo', '-S'])
pwdin = self._new(['echo', root_password], cwd, global_interpreter, lang).stdout

Expand Down Expand Up @@ -219,14 +222,10 @@ def handle_simple(self, proc: SimpleProcess, output_handler=None, notify_watcher


def run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False, print_error: bool = True,
cwd: str = '.', global_interpreter: bool = USE_GLOBAL_INTERPRETER, extra_paths: Set[str] = None) -> str:
cwd: str = '.', global_interpreter: bool = USE_GLOBAL_INTERPRETER, extra_paths: Set[str] = None,
custom_user: Optional[str] = None) -> str:
"""
runs a given command and returns its default output
:param cmd:
:param expected_code:
:param ignore_return_code:
:param print_error:
:param global_interpreter
:return:
"""
args = {
Expand All @@ -239,13 +238,14 @@ def run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False,
if not print_error:
args["stderr"] = subprocess.DEVNULL

res = subprocess.run(cmd, **args)
final_cmd = f"runuser -u {custom_user} -- {cmd}" if custom_user else cmd
res = subprocess.run(final_cmd, **args)
return res.stdout.decode() if ignore_return_code or res.returncode == expected_code else None


def new_subprocess(cmd: List[str], cwd: str = '.', shell: bool = False, stdin = None,
global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG,
extra_paths: Set[str] = None) -> subprocess.Popen:
extra_paths: Set[str] = None, custom_user: Optional[str] = None) -> subprocess.Popen:
args = {
"stdout": PIPE,
"stderr": PIPE,
Expand All @@ -255,7 +255,8 @@ def new_subprocess(cmd: List[str], cwd: str = '.', shell: bool = False, stdin =
"stdin": stdin if stdin else subprocess.DEVNULL
}

return subprocess.Popen(cmd, **args)
final_cmd = ['runuser', '-u', custom_user, '--', *cmd] if custom_user else cmd
return subprocess.Popen(final_cmd, **args)


def new_root_subprocess(cmd: List[str], root_password: str, cwd: str = '.',
Expand Down Expand Up @@ -302,8 +303,9 @@ def get_human_size_str(size) -> str:
return str(int_size)


def run(cmd: List[str], success_code: int = 0) -> Tuple[bool, str]:
p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL)
def run(cmd: List[str], success_code: int = 0, custom_user: Optional[str] = None) -> Tuple[bool, str]:
final_cmd = ['runuser', '-u', custom_user, '--', *cmd] if custom_user else cmd
p = subprocess.run(final_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL)
return p.returncode == success_code, p.stdout.decode()


Expand All @@ -327,9 +329,13 @@ def check_enabled_services(*names: str) -> Dict[str, bool]:
return {s: status[i].strip().lower() == 'enabled' for i, s in enumerate(names) if s}


def execute(cmd: str, shell: bool = False, cwd: Optional[str] = None, output: bool = True, custom_env: Optional[dict] = None, stdin: bool = True) -> Tuple[int, Optional[str]]:
def execute(cmd: str, shell: bool = False, cwd: Optional[str] = None, output: bool = True, custom_env: Optional[dict] = None,
stdin: bool = True, custom_user: Optional[str] = None) -> Tuple[int, Optional[str]]:

final_cmd = f"runuser -u {custom_user} -- {cmd}" if custom_user else cmd

params = {
'args': cmd.split(' ') if not shell else [cmd],
'args': final_cmd.split(' ') if not shell else [final_cmd],
'stdout': subprocess.PIPE if output else subprocess.DEVNULL,
'stderr': subprocess.STDOUT if output else subprocess.DEVNULL,
'shell': shell
Expand Down
8 changes: 6 additions & 2 deletions bauh/gems/arch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
from typing import Optional

from bauh import __app_name__
from bauh.api.paths import CONFIG_DIR, TEMP_DIR, CACHE_DIR
from bauh.api.paths import CONFIG_DIR, TEMP_DIR, CACHE_DIR, get_temp_dir
from bauh.commons import resource

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
BUILD_DIR = f'{TEMP_DIR}/arch'
ARCH_CACHE_DIR = f'{CACHE_DIR}/arch'
CATEGORIES_FILE_PATH = f'{ARCH_CACHE_DIR}/categories.txt'
URL_CATEGORIES_FILE = f'https://raw.githubusercontent.com/vinifmor/{__app_name__}-files/master/arch/categories.txt'
Expand All @@ -21,6 +21,10 @@
IGNORED_REBUILD_CHECK_FILE = f'{ARCH_CONFIG_DIR}/aur/ignored_rebuild_check.txt'


def get_pkgbuild_dir(user: Optional[str] = None) -> str:
return f'{get_temp_dir(user) if user else TEMP_DIR}/arch'


def get_icon_path() -> str:
return resource.get_path('img/arch.svg', ROOT_DIR)

Expand Down
5 changes: 1 addition & 4 deletions bauh/gems/arch/aur.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
'conflicts')


def map_pkgbuild(pkgbuild: str) -> dict:
return {attr: val.replace('"', '').replace("'", '').replace('(', '').replace(')', '') for attr, val in re.findall(r'\n(\w+)=(.+)', pkgbuild)}


def map_srcinfo(string: str, pkgname: Optional[str], fields: Set[str] = None) -> dict:
subinfos, subinfo = [], {}

Expand Down Expand Up @@ -260,3 +256,4 @@ def fill_update_data(self, output: Dict[str, dict], pkgname: str, latest_version

def is_supported(arch_config: dict) -> bool:
return arch_config['aur'] and git.is_installed()

9 changes: 4 additions & 5 deletions bauh/gems/arch/config.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from pathlib import Path
from typing import Optional

from bauh.commons.config import YAMLConfigManager
from bauh.gems.arch import CONFIG_FILE, BUILD_DIR
from bauh.gems.arch import CONFIG_FILE, get_pkgbuild_dir


def get_build_dir(arch_config: dict) -> str:
def get_build_dir(arch_config: dict, user: Optional[str]) -> str:
build_dir = arch_config.get('aur_build_dir')

if not build_dir:
build_dir = BUILD_DIR
build_dir = get_pkgbuild_dir(user)

Path(build_dir).mkdir(parents=True, exist_ok=True)
return build_dir


Expand Down
Loading

0 comments on commit ad249b2

Please sign in to comment.