]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/actions/upgrader.py
Upver to 1.4.1
[waydroid.git] / tools / actions / upgrader.py
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 import logging
4 import os
5 from tools import helpers
6 from tools.helpers.version import versiontuple
7 import tools.config
8 import dbus
9
10 def get_config(args):
11 cfg = tools.config.load(args)
12 args.arch = cfg["waydroid"]["arch"]
13 args.images_path = cfg["waydroid"]["images_path"]
14 args.vendor_type = cfg["waydroid"]["vendor_type"]
15 args.system_ota = cfg["waydroid"]["system_ota"]
16 args.vendor_ota = cfg["waydroid"]["vendor_ota"]
17 args.session = None
18
19 def migration(args):
20 try:
21 old_ver = tools.helpers.props.file_get(args, args.work + "/waydroid_base.prop", "waydroid.tools_version")
22 if versiontuple(old_ver) <= versiontuple("1.3.4"):
23 chmod_paths = ["cache_http", "host-permissions", "lxc", "images", "rootfs", "data", "waydroid_base.prop", "waydroid.prop", "waydroid.cfg"]
24 tools.helpers.run.user(args, ["chmod", "-R", "g-w,o-w"] + [os.path.join(args.work, f) for f in chmod_paths], check=False)
25 tools.helpers.run.user(args, ["chmod", "g-w,o-w", args.work], check=False)
26 os.remove(os.path.join(args.work, "session.cfg"))
27 except:
28 pass
29
30 def upgrade(args):
31 get_config(args)
32 status = "STOPPED"
33 if os.path.exists(tools.config.defaults["lxc"] + "/waydroid"):
34 status = helpers.lxc.status(args)
35 if status != "STOPPED":
36 logging.info("Stopping container")
37 try:
38 container = tools.helpers.ipc.DBusContainerService()
39 args.session = container.GetSession()
40 container.Stop(False)
41 except Exception as e:
42 logging.debug(e)
43 tools.actions.container_manager.stop(args)
44 migration(args)
45 helpers.drivers.loadBinderNodes(args)
46 if not args.offline:
47 if args.images_path not in tools.config.defaults["preinstalled_images_paths"]:
48 helpers.images.get(args)
49 else:
50 logging.info("Upgrade refused because a pre-installed image is detected at {}.".format(args.images_path))
51 helpers.drivers.probeAshmemDriver(args)
52 helpers.lxc.setup_host_perms(args)
53 helpers.lxc.set_lxc_config(args)
54 helpers.lxc.make_base_props(args)
55 if status != "STOPPED":
56 logging.info("Starting container")
57 try:
58 container.Start(args.session)
59 except Exception as e:
60 logging.debug(e)
61 logging.error("Failed to restart container. Please do so manually.")