add a password prompt for luks

This commit is contained in:
Andreas Zweili 2021-12-20 10:41:11 +01:00
parent b0902cd334
commit 88e8bebe37
1 changed files with 17 additions and 7 deletions

View File

@ -1,14 +1,22 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import getpass
import os import os
import subprocess import subprocess
import sys import sys
def _run_command(command): def _run_command(command, input=""):
result = subprocess.run(command, if input:
capture_output=True, result = subprocess.run(command,
text=True, capture_output=True,
check=True) text=True,
check=True,
input=input)
else:
result = subprocess.run(command,
capture_output=True,
text=True,
check=True)
return result return result
@ -91,10 +99,12 @@ def _create_swap():
def _encrypt_disk(partition_path, container_name): def _encrypt_disk(partition_path, container_name):
password = getpass.getpass()
print("Encrypting disk.") print("Encrypting disk.")
_run_command(["cryptsetup", "luksFormat", "-q" _run_command(["cryptsetup", "luksFormat", "-q"
"--type", "luks1", partition_path]) "--type", "luks1", partition_path], input=password)
_run_command(["cryptsetup", "open", partition_path, "cryptlvm"]) _run_command(["cryptsetup", "open", partition_path, "cryptlvm"],
input=password)
def _setup_lvm(lvm_target): def _setup_lvm(lvm_target):