#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later set -eux set -o pipefail [[ -e /dev/loop-control ]] || exit 77 repart="${1:?}" udevadm="${2:?}" test -x "$repart" test -x "$udevadm" PATH=$PATH:/sbin:/usr/sbin D="$(mktemp --tmpdir --directory "test-repart.XXXXXXXXXX")" # shellcheck disable=SC2064 trap "rm -rf '$D'" EXIT INT QUIT PIPE mkdir -p "$D/definitions" SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8 echo "### Testing systemd-repart --empty=create ###" "$repart" "$D/zzz" --empty=create --size=1G --seed="$SEED" --no-pager sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/empty" cmp "$D/empty" - <"$D/definitions/root.conf" <"$D/definitions/home.conf" <"$D/definitions/swap.conf" <"$D/populated" cmp "$D/populated" - <"$D/definitions/swap.conf" <"$D/definitions/extra.conf" <>"$D/definitions/home.conf" echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>"$D/definitions/home.conf" "$repart" "$D/zzz" --dry-run=no --seed="$SEED" --definitions="$D/definitions" --no-pager sfdisk -d "$D/zzz" | grep -v -e 'sector-size' -e '^$' >"$D/populated2" cmp "$D/populated2" - <"$D/populated3" cmp "$D/populated3" - <"$D/definitions/extra2.conf" <"$D/populated4" cmp "$D/populated4" - </dev/null ; then echo "### Testing Format=/Encrypt=/CopyFiles=" # These tests require privileges unfortunately cat >"$D/definitions/extra3.conf" <"$D/populated5" cmp "$D/populated5" - </dev/null umount "$D/mount" else echo "### Skipping Format=/Encrypt=/CopyFiles= test, lacking privileges or missing cryptsetup/diff/losetup" fi echo "### Testing json output ###" "$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions" --no-pager --json=help "$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions" --no-pager --json=pretty "$repart" "$D/zzz" --size=3G --dry-run=no --seed="$SEED" --definitions="$D/definitions" --no-pager --json=short