summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorTrainDoctor <traindoctor@protonmail.com>2022-10-30 16:37:19 -0700
committerGitHub <noreply@github.com>2022-10-30 16:37:19 -0700
commit5e3de747d37b4b7042485a6733b2cd8a883b16ef (patch)
tree2aec58e119ab2e34f2a4a88b4a3076db08f0e8bd /backend
parentd389b403b521c48920d872c6ddd133b63ada2528 (diff)
downloaddecky-loader-5e3de747d37b4b7042485a6733b2cd8a883b16ef.tar.gz
decky-loader-5e3de747d37b4b7042485a6733b2cd8a883b16ef.zip
Systemd service updating (#240)v2.3.1-pre2
* Add services and updated installer files * Loader updates service file during update! * Testing update branch doesn't exist lol * Update to dfl 3.7.12 * Fix services and add working service updater * Revert services but replace their aliases * Fix install scripts as well * Move leftover service files to .systemd dir * No wonder it's not trimming the file... * fix whitespace * Remove unused imports * Remove another un-used import Co-authored-by: AAGaming <aa@mail.catvibers.me>
Diffstat (limited to 'backend')
-rw-r--r--backend/updater.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/backend/updater.py b/backend/updater.py
index a209f103..7647d204 100644
--- a/backend/updater.py
+++ b/backend/updater.py
@@ -1,3 +1,5 @@
+import os
+import shutil
import uuid
from asyncio import sleep
from ensurepip import version
@@ -79,6 +81,20 @@ class Updater:
async def _get_branch(self, manager: SettingsManager):
return self.get_branch(manager)
+ # retrieve relevant service file's url for each branch
+ def get_service_url(self):
+ logger.debug("Getting service URL")
+ branch = self.get_branch(self.context.settings)
+ match branch:
+ case 0:
+ url = "https://raw.githubusercontent.com/SteamDeckHomebrew/decky-loader/service-updater/dist/plugin_loader-release.service"
+ case 1 | 2:
+ url = "https://raw.githubusercontent.com/SteamDeckHomebrew/decky-loader/service-updater/dist/plugin_loader-prerelease.service"
+ case _:
+ logger.error("You have an invalid branch set... Defaulting to prerelease service, please send the logs to the devs!")
+ url = "https://raw.githubusercontent.com/SteamDeckHomebrew/decky-loader/service-updater/dist/plugin_loader-prerelease.service"
+ return str(url)
+
async def get_version(self):
if self.localVer:
return {
@@ -122,14 +138,44 @@ class Updater:
await sleep(60 * 60 * 6) # 6 hours
async def do_update(self):
+ logger.debug("Starting update.")
version = self.remoteVer["tag_name"]
download_url = self.remoteVer["assets"][0]["browser_download_url"]
+ service_url = self.get_service_url()
+ logger.debug("Retrieved service URL")
tab = await get_gamepadui_tab()
await tab.open_websocket()
async with ClientSession() as web:
+ logger.debug("Downloading systemd service")
+ # download the relevant systemd service depending upon branch
+ async with web.request("GET", service_url, ssl=helpers.get_ssl_context(), allow_redirects=True) as res:
+ logger.debug("Downloading service file")
+ data = await res.content.read()
+ logger.debug(str(data))
+ service_file_path = path.join(getcwd(), "plugin_loader.service")
+ try:
+ with open(path.join(getcwd(), "plugin_loader.service"), "wb") as out:
+ out.write(data)
+ except Exception as e:
+ logger.error(f"Error at %s", exc_info=e)
+ with open(path.join(getcwd(), "plugin_loader.service"), 'r') as service_file:
+ service_data = service_file.read()
+ service_data = service_data.replace("${HOMEBREW_FOLDER}", "/home/"+helpers.get_user()+"/homebrew")
+ with open(path.join(getcwd(), "plugin_loader.service"), 'w') as service_file:
+ service_file.write(service_data)
+
+ logger.debug("Saved service file")
+ logger.debug("Copying service file over current file.")
+ shutil.copy(service_file_path, "/etc/systemd/system/plugin_loader.service")
+ if not os.path.exists(path.join(getcwd(), ".systemd")):
+ os.mkdir(path.join(getcwd(), ".systemd"))
+ shutil.move(service_file_path, path.join(getcwd(), ".systemd")+"/plugin_loader.service")
+
+ logger.debug("Downloading binary")
async with web.request("GET", download_url, ssl=helpers.get_ssl_context(), allow_redirects=True) as res:
total = int(res.headers.get('content-length', 0))
+ # we need to not delete the binary until we have downloaded the new binary!
try:
remove(path.join(getcwd(), "PluginLoader"))
except:
@@ -149,9 +195,9 @@ class Updater:
out.write(version)
call(['chmod', '+x', path.join(getcwd(), "PluginLoader")])
-
logger.info("Updated loader installation.")
await tab.evaluate_js("window.DeckyUpdater.finish()", False, False)
+ await self.do_restart()
await tab.client.close()
async def do_restart(self):