]> glassweightruler.freedombox.rocks Git - waydroid.git/commitdiff
tools: Drop need of sudo as much as possible
authorErfan Abdi <erfangplus@gmail.com>
Mon, 20 Sep 2021 14:26:31 +0000 (18:56 +0430)
committerErfan Abdi <erfangplus@gmail.com>
Wed, 29 Sep 2021 16:35:59 +0000 (20:05 +0330)
tools/actions/container_manager.py
tools/helpers/drivers.py
tools/helpers/lxc.py
tools/helpers/mount.py

index 7362899787dfadc1bb6bb391b890133fe3ac4131..37ab7e7f6a7d7a25151fa82198dc1eaf3c437081 100644 (file)
@@ -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))
index 69ee56a0febd180e6ed711c6bd85a8c9145dee74..f5a5b118e7cb0c8f3c449c18df6d3619fa4e0255 100644 (file)
@@ -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())
index 5e7b31078900c472d7bef94fccd54c3a4b469e4e..8ed65a9b8e5ba3c80882cc9d7a1a83091716c3ab 100644 (file)
@@ -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":
index 4d772067fa76bcd152c6ec7053ef52ac8fecea0c..fdf647776b3412781757c3388da26b4b6bd7063c 100644 (file)
@@ -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):