| 1 |
#!/usr/bin/python3 |
| 2 |
|
| 3 |
import json |
| 4 |
import sys |
| 5 |
|
| 6 |
def check_children(blk, search) -> (bool, str): |
| 7 |
pname = blk["name"] |
| 8 |
if blk["mountpoints"]: |
| 9 |
# Note: mountpoint we are usually looking for is /tmp/calamares-root-o1cvofyt |
| 10 |
# where the last block is random |
| 11 |
for mp in blk["mountpoints"]: |
| 12 |
if mp and search in mp: |
| 13 |
return True, pname |
| 14 |
if "children" in blk.keys(): |
| 15 |
for child in blk["children"]: |
| 16 |
found, uppername = check_children(child, search) |
| 17 |
if found: |
| 18 |
return True, pname |
| 19 |
return False, "" |
| 20 |
|
| 21 |
|
| 22 |
if len(sys.argv) >= 2: |
| 23 |
search = sys.argv[1] |
| 24 |
else: |
| 25 |
search = "/tmp/calamares-root" |
| 26 |
blkdevs = json.load(sys.stdin) |
| 27 |
|
| 28 |
for blkdev in blkdevs["blockdevices"]: |
| 29 |
found, pname = check_children(blkdev, search) |
| 30 |
if found: |
| 31 |
print(pname) |
| 32 |
sys.exit(0) |
| 33 |
|