#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later set -ex [[ -f /dev/loop-control ]] || exit 77 repart=$1 test -x $repart D=$(mktemp --tmpdir --directory "test-repart.XXXXXXXXXX") 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 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 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 cryptsetup close $VOLUME losetup -d $LOOP 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 --json=help $repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=pretty $repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=short