refactor!: port shell scripts to Python package
Bash scripts were untestable and duplicated device/LUKS/mount logic; the lim/ package centralizes it behind one subprocess wrapper and a YAML image catalog (single point of truth). BREAKING CHANGE: scripts/*.sh removed. Use `lim --type <cmd>`; new types mount/umount/single-boot/raid1-boot/lock/unlock/import/export replace direct script calls. --extra is deprecated and ignored. - distributions.yml + lim/catalog.py hold the image catalog (PyYAML) - pytest suite: 102 tests with mocked subprocess (tests/unit) and a 250-line max file-length guard (tests/lint) - ruff strict (select ALL), GitHub Actions CI, Dependabot; Travis gone - Makefile: install (symlink ~/.local/bin/lim) and test targets - fixes over bash: SUDO_USER-aware chown, mmcblk/nvme partition paths, sha512 checksum support, whole-pipeline failure detection, blkid UUID fallback for pre-mounted images, conditional fstab seeding for PARTUUID/LABEL images, clean errors for missing binaries
This commit is contained in:
32
lim/image/backup.py
Normal file
32
lim/image/backup.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""Create an image backup from a memory device into a file."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from lim import device as device_module
|
||||
from lim import runner, ui
|
||||
|
||||
|
||||
def run_backup() -> None:
|
||||
ui.info("Backupscript for memory devices started...")
|
||||
print()
|
||||
device = device_module.select_device()
|
||||
|
||||
working_dir = Path.cwd()
|
||||
path = ""
|
||||
while not path:
|
||||
path = ui.ask(f"Please type in backup image path+name relative to {working_dir}:")
|
||||
output_file = f"{path}.img" if path.startswith("/") else f"{working_dir}/{path}.img"
|
||||
|
||||
ui.info(f"Input file: {device.path}")
|
||||
ui.info(f"Output file: {output_file}")
|
||||
ui.ask('Please confirm by pushing "Enter". To cancel use "Ctrl + C"')
|
||||
|
||||
ui.info("Imagetransfer starts. This can take a while...")
|
||||
runner.run(
|
||||
["dd", f"if={device.path}", f"of={output_file}", "bs=1M", "status=progress"],
|
||||
sudo=True,
|
||||
error_msg='"dd" failed.',
|
||||
)
|
||||
runner.sync_disks()
|
||||
|
||||
ui.success("Imagetransfer successfull.")
|
||||
Reference in New Issue
Block a user