From 7dfcd8f6e49243fd08001d2b472560357d8c84cf Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Mon, 19 Sep 2022 00:10:20 +0200 Subject: [PATCH] Configure multiple preinstalled images paths Precedence: /etc/waydroid-extra/images /usr/share/waydroid-extra/images --- tools/actions/initializer.py | 21 ++++++++++++--------- tools/actions/upgrader.py | 5 ++--- tools/config/__init__.py | 5 ++++- tools/helpers/lxc.py | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tools/actions/initializer.py b/tools/actions/initializer.py index 2ce6cb4..c3e133d 100644 --- a/tools/actions/initializer.py +++ b/tools/actions/initializer.py @@ -29,13 +29,16 @@ def setup_config(args): args.arch = helpers.arch.host() cfg["waydroid"]["arch"] = args.arch - preinstalled_images = tools.config.defaults["preinstalled_images_path"] + preinstalled_images_paths = tools.config.defaults["preinstalled_images_paths"] if not args.images_path: - if os.path.isdir(preinstalled_images): - if os.path.isfile(preinstalled_images + "/system.img") and os.path.isfile(preinstalled_images + "/vendor.img"): - args.images_path = preinstalled_images - else: - logging.error("Missing system or vendor on preinstalled images dir, fallback to default") + for preinstalled_images in preinstalled_images_paths: + if os.path.isdir(preinstalled_images): + if os.path.isfile(preinstalled_images + "/system.img") and os.path.isfile(preinstalled_images + "/vendor.img"): + args.images_path = preinstalled_images + break + else: + logging.warning("Found directory {} but missing system or vendor image, ignoring...".format(preinstalled_images)) + if not args.images_path: args.images_path = tools.config.defaults["images_path"] cfg["waydroid"]["images_path"] = args.images_path @@ -54,7 +57,7 @@ def setup_config(args): "/waydroid_" + args.arch + "/" + args.system_type + ".json" system_request = helpers.http.retrieve(args.system_ota) if system_request[0] != 200: - if args.images_path != preinstalled_images: + if args.images_path not in preinstalled_images_paths: raise ValueError( "Failed to get system OTA channel: {}, error: {}".format(args.system_ota, system_request[0])) else: @@ -72,7 +75,7 @@ def setup_config(args): break if not args.vendor_type: - if args.images_path != preinstalled_images: + if args.images_path not in preinstalled_images_paths: raise ValueError( "Failed to get vendor OTA channel: {}".format(vendor_ota)) else: @@ -103,7 +106,7 @@ def init(args): logging.info("Stopping container") helpers.lxc.stop(args) helpers.images.umount_rootfs(args) - if args.images_path != tools.config.defaults["preinstalled_images_path"]: + if args.images_path not in tools.config.defaults["preinstalled_images_paths"]: helpers.images.get(args) if not os.path.isdir(tools.config.defaults["rootfs"]): os.mkdir(tools.config.defaults["rootfs"]) diff --git a/tools/actions/upgrader.py b/tools/actions/upgrader.py index 2acf464..b788f50 100644 --- a/tools/actions/upgrader.py +++ b/tools/actions/upgrader.py @@ -25,11 +25,10 @@ def upgrade(args): helpers.images.umount_rootfs(args) helpers.drivers.loadBinderNodes(args) if not args.offline: - preinstalled_images_path = tools.config.defaults["preinstalled_images_path"] - if args.images_path != preinstalled_images_path: + if args.images_path not in tools.config.defaults["preinstalled_images_paths"]: helpers.images.get(args) else: - logging.info("Upgrade refused because a pre-installed image is detected at {}.".format(preinstalled_images_path)) + logging.info("Upgrade refused because a pre-installed image is detected at {}.".format(args.images_path)) helpers.lxc.setup_host_perms(args) helpers.lxc.set_lxc_config(args) helpers.lxc.make_base_props(args) diff --git a/tools/config/__init__.py b/tools/config/__init__.py index 99db257..f91d76d 100644 --- a/tools/config/__init__.py +++ b/tools/config/__init__.py @@ -43,7 +43,10 @@ defaults = { "vendor_type": "MAINLINE", "system_datetime": "0", "vendor_datetime": "0", - "preinstalled_images_path": "/usr/share/waydroid-extra/images" + "preinstalled_images_paths": [ + "/etc/waydroid-extra/images", + "/usr/share/waydroid-extra/images", + ] } defaults["images_path"] = defaults["work"] + "/images" defaults["rootfs"] = defaults["work"] + "/rootfs" diff --git a/tools/helpers/lxc.py b/tools/helpers/lxc.py index ee84c61..8348c0c 100644 --- a/tools/helpers/lxc.py +++ b/tools/helpers/lxc.py @@ -253,7 +253,7 @@ def make_base_props(args): opengles = "196608" props.append("ro.opengles.version=" + opengles) - if args.images_path != tools.config.defaults["preinstalled_images_path"]: + if args.images_path not in tools.config.defaults["preinstalled_images_paths"]: props.append("waydroid.system_ota=" + args.system_ota) props.append("waydroid.vendor_ota=" + args.vendor_ota) else: -- 2.47.3