summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/dnbd3-rootfs/scripts/container-unpack-xmount.sh
blob: c7e1b45c9446db99ee13b4443a20a1ecce088291 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# region imports
source '/usr/lib/rebash/core.sh'
core.import logging
core.import utils
core.import exceptions
exceptions.activate
# endregion
logging.set_level info
logging.set_commands_level info

# NOTE: All output has to be forwarded to standard error because determined
# device should be printed on standard output.
in_device="$1"
mkdir --parents /mnt/xmount
loop_device="$(losetup --find)"
if ! utils.dependency_check xmount; then
    logging.warn "\"xmount\" not found, assuming raw image." 1>&2
elif systemd-preserve-process-marker xmount --in qemu "$in_device" --out raw \
    /mnt/xmount &>/dev/null
then
    in_device="/mnt/xmount/*.dd"
else
    logging.warn "\"xmount\" call failed, assuming raw image." 1>&2
fi
losetup "$loop_device" $in_device --partscan
udevadm settle
echo "$loop_device"

# region vim modline
# vim: set tabstop=4 shiftwidth=4 expandtab:
# vim: foldmethod=marker foldmarker=region,endregion:
# endregion