Move mounting code to utils.py, move a lot of chroot-logic from packages to chroot.py, cmd_chroot

also moar crossdirect

Signed-off-by: InsanePrawn <insane.prawny@gmail.com>
This commit is contained in:
InsanePrawn 2021-10-01 18:25:42 +02:00
parent a4c06446e3
commit d85c00fa12
8 changed files with 207 additions and 110 deletions

View file

@ -1,4 +1,6 @@
from shutil import which
import atexit
import subprocess
def programs_available(programs) -> bool:
@ -8,3 +10,33 @@ def programs_available(programs) -> bool:
if not which(program):
return False
return True
def umount(dest):
return subprocess.run(
[
'umount',
'-lc',
dest,
],
stderr=subprocess.DEVNULL,
)
def mount(src: str, dest: str, options=['bind'], type=None) -> subprocess.CompletedProcess:
opts = []
type = []
for opt in options:
opts += ['-o', opt]
if type:
type = ['-t', type]
result = subprocess.run(['mount'] + type + opts + [
src,
dest,
])
if result.returncode == 0:
atexit.register(umount, dest)
return result