summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-04-05 20:51:53 +0300
committerMaxim Devaev <[email protected]>2022-04-05 20:51:53 +0300
commit5be17cb75616dbcffee384ba65df74684c7d1fca (patch)
treebec907160edde791ee419080d1a2d553130edb02
parentfa3aeb79ae071245a27178ac4fa8d0a9938c792f (diff)
common helpers
-rw-r--r--kvmd/helpers/otgmsd/__init__.py20
-rw-r--r--kvmd/helpers/remount/__init__.py (renamed from kvmd/helpers/otgmsd/remount/__init__.py)22
-rw-r--r--kvmd/helpers/remount/__main__.py (renamed from kvmd/helpers/otgmsd/remount/__main__.py)0
-rw-r--r--kvmd/helpers/unlock/__init__.py (renamed from kvmd/helpers/otgmsd/unlock/__init__.py)0
-rw-r--r--kvmd/helpers/unlock/__main__.py (renamed from kvmd/helpers/otgmsd/unlock/__main__.py)0
-rwxr-xr-xsetup.py9
6 files changed, 21 insertions, 30 deletions
diff --git a/kvmd/helpers/otgmsd/__init__.py b/kvmd/helpers/otgmsd/__init__.py
deleted file mode 100644
index 4a6824c1..00000000
--- a/kvmd/helpers/otgmsd/__init__.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# ========================================================================== #
-# #
-# 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/>. #
-# #
-# ========================================================================== #
diff --git a/kvmd/helpers/otgmsd/remount/__init__.py b/kvmd/helpers/remount/__init__.py
index c66a5a17..e432ca05 100644
--- a/kvmd/helpers/otgmsd/remount/__init__.py
+++ b/kvmd/helpers/remount/__init__.py
@@ -27,6 +27,8 @@ import shutil
import dataclasses
import subprocess
+from typing import List
+
# ====
_MOUNT_PATH = "/bin/mount"
@@ -46,21 +48,22 @@ def _log(msg: str) -> None:
print(msg, file=sys.stderr)
-def _find_storage() -> _Storage:
+def _find_storage(target: str) -> _Storage:
+ assert target
with open(_FSTAB_PATH) as fstab_file:
for line in fstab_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\.otgmsd-(root|user)=([^,]+)", parts[3]))
+ options = dict(re.findall(r"X-kvmd\.%s-(root|user)=([^,]+)" % (target), parts[3]))
if options:
return _Storage(
mount_path=parts[1],
root_path=options.get("root", ""),
user=options.get("user", ""),
)
- raise RuntimeError(f"Can't find MSD mountpoint in {_FSTAB_PATH}")
+ raise SystemExit(f"Can't find {target!r} mountpoint in {_FSTAB_PATH}")
def _remount(path: str, rw: bool) -> None:
@@ -94,13 +97,22 @@ def main() -> None:
if len(sys.argv) != 2 or sys.argv[1] not in ["ro", "rw"]:
raise SystemExit(f"Usage: {sys.argv[0]} [ro|rw]")
+ target = ""
+ dirs: List[str] = []
+ app = os.path.basename(sys.argv[0])
+ if app == "kvmd-helper-otgmsd-remount":
+ target = "otgmsd"
+ dirs = ["images", "meta"]
+ else:
+ raise SystemExit("Unknown application target")
+
rw = (sys.argv[1] == "rw")
- storage = _find_storage()
+ storage = _find_storage(target)
_remount(storage.mount_path, rw)
if rw:
if storage.root_path:
- for name in ["images", "meta"]:
+ for name in dirs:
path = os.path.join(storage.root_path, name)
_mkdir(path)
if storage.user:
diff --git a/kvmd/helpers/otgmsd/remount/__main__.py b/kvmd/helpers/remount/__main__.py
index 3849d1b9..3849d1b9 100644
--- a/kvmd/helpers/otgmsd/remount/__main__.py
+++ b/kvmd/helpers/remount/__main__.py
diff --git a/kvmd/helpers/otgmsd/unlock/__init__.py b/kvmd/helpers/unlock/__init__.py
index 140e0e7c..140e0e7c 100644
--- a/kvmd/helpers/otgmsd/unlock/__init__.py
+++ b/kvmd/helpers/unlock/__init__.py
diff --git a/kvmd/helpers/otgmsd/unlock/__main__.py b/kvmd/helpers/unlock/__main__.py
index 3849d1b9..3849d1b9 100644
--- a/kvmd/helpers/otgmsd/unlock/__main__.py
+++ b/kvmd/helpers/unlock/__main__.py
diff --git a/setup.py b/setup.py
index f2c3f7ee..d5546eab 100755
--- a/setup.py
+++ b/setup.py
@@ -108,9 +108,8 @@ def main() -> None:
"kvmd.apps.janus",
"kvmd.apps.watchdog",
"kvmd.helpers",
- "kvmd.helpers.otgmsd",
- "kvmd.helpers.otgmsd.unlock",
- "kvmd.helpers.otgmsd.remount",
+ "kvmd.helpers.unlock",
+ "kvmd.helpers.remount",
],
package_data={
@@ -130,8 +129,8 @@ def main() -> None:
"kvmd-vnc = kvmd.apps.vnc:main",
"kvmd-janus = kvmd.apps.janus:main",
"kvmd-watchdog = kvmd.apps.watchdog:main",
- "kvmd-helper-otgmsd-unlock = kvmd.helpers.otgmsd.unlock:main",
- "kvmd-helper-otgmsd-remount = kvmd.helpers.otgmsd.remount:main",
+ "kvmd-helper-otgmsd-unlock = kvmd.helpers.unlock:main",
+ "kvmd-helper-otgmsd-remount = kvmd.helpers.remount:main",
],
},