diff options
| author | Derek J. Clark <derkejohn.clark@gmail.com> | 2022-08-08 11:32:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-08 11:32:14 -0700 |
| commit | 20094c5f752046a33287ef372fa973e919e83226 (patch) | |
| tree | ed298251be183fc5f3151b19a10f7499c7d66e0d /backend/browser.py | |
| parent | 198591dbd7b0b6dd311ab9265d4cda4a733ee280 (diff) | |
| download | decky-loader-20094c5f752046a33287ef372fa973e919e83226.tar.gz decky-loader-20094c5f752046a33287ef372fa973e919e83226.zip | |
Use Environment Variables (#123)
Uses environment variables instead of hard coding the "deck" user/group.
This adds support for systems other than the steam deck that are using the DeckUI.
* Use Environment Variables
* Use method to get USER from a systemd root process
* Fix imports. Add get_user and get_user_group methods in helpers.py. Removed duplicated code
* Add separate setters/getters for user vars. Ensure sleep prevents race condition of user setter in while loop
Diffstat (limited to 'backend/browser.py')
| -rw-r--r-- | backend/browser.py | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/backend/browser.py b/backend/browser.py index c58a97e5..190f8bd5 100644 --- a/backend/browser.py +++ b/backend/browser.py @@ -1,20 +1,22 @@ -from injector import get_tab +# Full imports +import json + +# Partial imports +from aiohttp import ClientSession, web +from asyncio import get_event_loop +from concurrent.futures import ProcessPoolExecutor +from hashlib import sha256 +from io import BytesIO from logging import getLogger from os import path, rename, listdir from shutil import rmtree -from aiohttp import ClientSession, web -from io import BytesIO -from zipfile import ZipFile -from concurrent.futures import ProcessPoolExecutor -from asyncio import get_event_loop +from subprocess import call from time import time -from hashlib import sha256 -from subprocess import Popen -from injector import inject_to_tab - -import json +from zipfile import ZipFile -import helpers +# Local modules +from helpers import get_ssl_context, get_user, get_user_group +from injector import get_tab, inject_to_tab class PluginInstallContext: def __init__(self, artifact, name, version, hash) -> None: @@ -41,8 +43,11 @@ class PluginBrowser: return False zip_file = ZipFile(zip) zip_file.extractall(self.plugin_path) - Popen(["chown", "-R", "deck:deck", self.plugin_path]) - Popen(["chmod", "-R", "555", self.plugin_path]) + code_chown = call(["chown", "-R", get_user()+":"+get_user_group(), self.plugin_path]) + code_chmod = call(["chmod", "-R", "555", self.plugin_path]) + if code_chown != 0 or code_chmod != 0: + logger.error(f"chown/chmod exited with a non-zero exit code (chown: {code_chown}, chmod: {code_chmod})") + return False return True def find_plugin_folder(self, name): @@ -83,7 +88,7 @@ class PluginBrowser: self.log.info(f"Installing {name} (Version: {version})") async with ClientSession() as client: self.log.debug(f"Fetching {artifact}") - res = await client.get(artifact, ssl=helpers.get_ssl_context()) + res = await client.get(artifact, ssl=get_ssl_context()) if res.status == 200: self.log.debug("Got 200. Reading...") data = await res.read() |
