summaryrefslogtreecommitdiff
path: root/kvmd/fstab.py
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-11-07 03:23:06 +0300
committerMaxim Devaev <[email protected]>2022-11-07 03:23:06 +0300
commit53f8b052de48843ece433362ba66633c8b16b7f6 (patch)
tree1d3ced9fd2f44bbb91c1604478eacd7bace1e6f5 /kvmd/fstab.py
parent648316931a8c5204945a5100a5530c15f7515a23 (diff)
common fstab and libc funcs
Diffstat (limited to 'kvmd/fstab.py')
-rw-r--r--kvmd/fstab.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/kvmd/fstab.py b/kvmd/fstab.py
new file mode 100644
index 00000000..b8c26e68
--- /dev/null
+++ b/kvmd/fstab.py
@@ -0,0 +1,50 @@
+# ========================================================================== #
+# #
+# KVMD - The main PiKVM daemon. #
+# #
+# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <https://www.gnu.org/licenses/>. #
+# #
+# ========================================================================== #
+
+
+import re
+import dataclasses
+
+
+# =====
[email protected](frozen=True)
+class FstabStorage:
+ mount_path: str
+ root_path: str
+ user: str
+
+
+def find_storage(target: str) -> FstabStorage:
+ fstab_path = "/etc/fstab"
+ with open(fstab_path) as file:
+ for line in file.read().split("\n"):
+ line = line.strip()
+ if line and not line.startswith("#"):
+ parts = line.split()
+ if len(parts) == 6:
+ options = dict(re.findall(r"X-kvmd\.%s-(root|user)(?:=([^,]+))?" % (target), parts[3]))
+ if options:
+ return FstabStorage(
+ mount_path=parts[1],
+ root_path=(options.get("root", "") or parts[1]),
+ user=options.get("user", ""),
+ )
+ raise RuntimeError(f"Can't find {target!r} mountpoint in {fstab_path}")