From 449db67aed2a91f739d3edb41b5cb2639691ec10 Mon Sep 17 00:00:00 2001 From: Erfan Abdi Date: Mon, 20 Sep 2021 18:56:31 +0430 Subject: [PATCH] tools: Drop need of sudo as much as possible --- tools/actions/container_manager.py | 18 +++++++++--------- tools/helpers/drivers.py | 10 +++++----- tools/helpers/lxc.py | 20 ++++++++++---------- tools/helpers/mount.py | 18 +++++++++--------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tools/actions/container_manager.py b/tools/actions/container_manager.py index 7362899..37ab7e7 100644 --- a/tools/actions/container_manager.py +++ b/tools/actions/container_manager.py @@ -48,7 +48,7 @@ def start(args): def chmod(path, mode): if os.path.exists(path): command = ["chmod", mode, "-R", path] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) # Nodes list if not perm_list: @@ -118,10 +118,10 @@ def start(args): # Networking command = [tools.config.tools_src + "/data/scripts/waydroid-net.sh", "start"] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) # Sensors - tools.helpers.run.root( + tools.helpers.run.user( args, ["waydroid-sensord", "/dev/" + args.HWBINDER_DRIVER], output="background") # Mount rootfs @@ -134,13 +134,13 @@ def start(args): # Cgroup hacks if which("start"): command = ["start", "cgroup-lite"] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) helpers.mount.umount_all(args, "/sys/fs/cgroup/schedtune") #TODO: remove NFC hacks if which("stop"): command = ["stop", "nfcd"] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) # Set permissions set_permissions() @@ -191,20 +191,20 @@ def stop(args): # Networking command = [tools.config.tools_src + "/data/scripts/waydroid-net.sh", "stop"] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) #TODO: remove NFC hacks if which("start"): command = ["start", "nfcd"] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) # Sensors if which("waydroid-sensord"): command = ["pidof", "waydroid-sensord"] - pid = tools.helpers.run.root(args, command, check=False, output_return=True) + pid = tools.helpers.run.user(args, command, check=False, output_return=True) if pid: command = ["kill", "-9", pid] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) else: logging.error("WayDroid container is {}".format(status)) diff --git a/tools/helpers/drivers.py b/tools/helpers/drivers.py index 69ee56a..f5a5b11 100644 --- a/tools/helpers/drivers.py +++ b/tools/helpers/drivers.py @@ -58,20 +58,20 @@ def probeBinderDriver(args): if not isBinderfsLoaded(args): devices = ','.join(binder_dev_nodes) command = ["modprobe", "binder_linux", "devices=\"{}\"".format(devices)] - output = tools.helpers.run.root(args, command, check=False, output_return=True) + output = tools.helpers.run.user(args, command, check=False, output_return=True) if output: logging.error("Failed to load binder driver for devices: {}".format(devices)) logging.error(output.strip()) if isBinderfsLoaded(args): command = ["mkdir", "-p", "/dev/binderfs"] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) command = ["mount", "-t", "binder", "binder", "/dev/binderfs"] - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) command = ["ln", "-s"] command.extend(glob.glob("/dev/binderfs/*")) command.append("/dev/") - tools.helpers.run.root(args, command, check=False) + tools.helpers.run.user(args, command, check=False) else: return -1 @@ -80,7 +80,7 @@ def probeBinderDriver(args): def probeAshmemDriver(args): if not os.path.exists("/dev/ashmem"): command = ["modprobe", "ashmem_linux"] - output = tools.helpers.run.root(args, command, check=False, output_return=True) + output = tools.helpers.run.user(args, command, check=False, output_return=True) if output: logging.error("Failed to load ashmem driver") logging.error(output.strip()) diff --git a/tools/helpers/lxc.py b/tools/helpers/lxc.py index 5e7b310..8ed65a9 100644 --- a/tools/helpers/lxc.py +++ b/tools/helpers/lxc.py @@ -113,11 +113,11 @@ def set_lxc_config(args): config_path = tools.config.tools_src + "/data/configs/" + config_file command = ["mkdir", "-p", lxc_path] - tools.helpers.run.root(args, command) + tools.helpers.run.user(args, command) command = ["cp", "-fpr", config_path, lxc_path + "/config"] - tools.helpers.run.root(args, command) + tools.helpers.run.user(args, command) command = ["sed", "-i", "s/LXCARCH/{}/".format(platform.machine()), lxc_path + "/config"] - tools.helpers.run.root(args, command) + tools.helpers.run.user(args, command) nodes = generate_nodes_lxc_config(args) config_nodes_tmp_path = args.work + "/config_nodes" @@ -126,7 +126,7 @@ def set_lxc_config(args): config_nodes.write(node + "\n") config_nodes.close() command = ["mv", config_nodes_tmp_path, lxc_path] - tools.helpers.run.root(args, command) + tools.helpers.run.user(args, command) def make_base_props(args): @@ -144,7 +144,7 @@ def make_base_props(args): for lib in ["lib", "lib64"]: hal_file = "/vendor/" + lib + "/hw/" + hardware + "." + prop + ".so" command = ["readlink", "-f", hal_file] - hal_file_path = tools.helpers.run.root(args, command, output_return=True).strip() + hal_file_path = tools.helpers.run.user(args, command, output_return=True).strip() if os.path.isfile(hal_file_path): hal_prop = re.sub(".*" + hardware + ".", "", hal_file_path) hal_prop = re.sub(".so", "", hal_prop) @@ -226,27 +226,27 @@ def setup_host_perms(args): shutil.copy(filename, tools.config.defaults["host_perms"]) def status(args): - command = ["sudo", "lxc-info", "-P", tools.config.defaults["lxc"], "-n", "waydroid", "-sH"] + command = ["lxc-info", "-P", tools.config.defaults["lxc"], "-n", "waydroid", "-sH"] return subprocess.run(command, stdout=subprocess.PIPE).stdout.decode('utf-8').strip() def start(args): command = ["lxc-start", "-P", tools.config.defaults["lxc"], "-F", "-n", "waydroid", "--", "/init"] - tools.helpers.run.root(args, command, output="background") + tools.helpers.run.user(args, command, output="background") def stop(args): command = ["lxc-stop", "-P", tools.config.defaults["lxc"], "-n", "waydroid", "-k"] - tools.helpers.run.root(args, command) + tools.helpers.run.user(args, command) def freeze(args): command = ["lxc-freeze", "-P", tools.config.defaults["lxc"], "-n", "waydroid"] - tools.helpers.run.root(args, command) + tools.helpers.run.user(args, command) def unfreeze(args): command = ["lxc-unfreeze", "-P", tools.config.defaults["lxc"], "-n", "waydroid"] - tools.helpers.run.root(args, command) + tools.helpers.run.user(args, command) def shell(args): if status(args) != "RUNNING": diff --git a/tools/helpers/mount.py b/tools/helpers/mount.py index 4d77206..fdf6477 100644 --- a/tools/helpers/mount.py +++ b/tools/helpers/mount.py @@ -37,13 +37,13 @@ def bind(args, source, destination, create_folders=True, umount=False): if os.path.exists(path): continue if create_folders: - tools.helpers.run.root(args, ["mkdir", "-p", path]) + tools.helpers.run.user(args, ["mkdir", "-p", path]) else: raise RuntimeError("Mount failed, folder does not exist: " + path) # Actually mount the folder - tools.helpers.run.root(args, ["mount", "-o", "bind", source, destination]) + tools.helpers.run.user(args, ["mount", "-o", "bind", source, destination]) # Verify, that it has worked if not ismount(destination): @@ -64,12 +64,12 @@ def bind_file(args, source, destination, create_folders=False): if create_folders: dir = os.path.dirname(destination) if not os.path.isdir(dir): - tools.helpers.run.root(args, ["mkdir", "-p", dir]) + tools.helpers.run.user(args, ["mkdir", "-p", dir]) - tools.helpers.run.root(args, ["touch", destination]) + tools.helpers.run.user(args, ["touch", destination]) # Mount - tools.helpers.run.root(args, ["mount", "-o", "bind", source, + tools.helpers.run.user(args, ["mount", "-o", "bind", source, destination]) @@ -103,7 +103,7 @@ def umount_all(args, folder): Umount all folders, that are mounted inside a given folder. """ for mountpoint in umount_all_list(folder): - tools.helpers.run.root(args, ["umount", mountpoint]) + tools.helpers.run.user(args, ["umount", mountpoint]) if ismount(mountpoint): raise RuntimeError("Failed to umount: " + mountpoint) @@ -122,15 +122,15 @@ def mount(args, source, destination, create_folders=True, umount=False, readonly # Check/create folders if not os.path.exists(destination): if create_folders: - tools.helpers.run.root(args, ["mkdir", "-p", destination]) + tools.helpers.run.user(args, ["mkdir", "-p", destination]) else: raise RuntimeError("Mount failed, folder does not exist: " + destination) # Actually mount the folder - tools.helpers.run.root(args, ["mount", source, destination]) + tools.helpers.run.user(args, ["mount", source, destination]) if readonly: - tools.helpers.run.root(args, ["mount", "-o", "remount,ro", source, destination]) + tools.helpers.run.user(args, ["mount", "-o", "remount,ro", source, destination]) # Verify, that it has worked if not ismount(destination): -- 2.47.3