11#! /usr/bin/env bash
22# SPDX-License-Identifier: LGPL-2.1-or-later
3- set -ex
3+ set -eux
4+ set -o pipefail
45
56[[ -e /dev/loop-control ]] || exit 77
67
7- repart=$1
8- test -x $repart
8+ repart=" ${1 :? } "
9+ test -x " $repart "
910
10- D=$( mktemp --tmpdir --directory " test-repart.XXXXXXXXXX" )
11+ D=" $( mktemp --tmpdir --directory " test-repart.XXXXXXXXXX" ) "
12+
13+ # shellcheck disable=SC2064
1114trap " rm -rf '$D '" EXIT INT QUIT PIPE
12- mkdir -p $D /definitions
15+ mkdir -p " $D /definitions"
1316
1417SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8
1518
1619echo " ### Testing systemd-repart --empty=create ###"
1720
18- $repart $D /zzz --empty=create --size=1G --seed=$SEED
21+ " $repart " " $D /zzz" --empty=create --size=1G --seed=" $SEED "
1922
20- sfdisk -d $D /zzz | grep -v -e ' sector-size' -e ' ^$' > $D /empty
23+ sfdisk -d " $D /zzz" | grep -v -e ' sector-size' -e ' ^$' > " $D /empty"
2124
22- cmp $D /empty - << EOF
25+ cmp " $D /empty" - << EOF
2326label: gpt
2427label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
2528device: $D /zzz
3033
3134echo " ### Testing with root, root2, home, & swap ###"
3235
33- cat > $D /definitions/root.conf << EOF
36+ cat > " $D /definitions/root.conf" << EOF
3437[Partition]
3538Type=root-x86-64
3639EOF
3740
38- ln -s root.conf $D /definitions/root2.conf
41+ ln -s root.conf " $D /definitions/root2.conf"
3942
40- cat > $D /definitions/home.conf << EOF
43+ cat > " $D /definitions/home.conf" << EOF
4144[Partition]
4245Type=home
4346Label=home-first
4447Label=home-always-too-long-xxxxxxxxxxxxxx-%v
4548EOF
4649
47- cat > $D /definitions/swap.conf << EOF
50+ cat > " $D /definitions/swap.conf" << EOF
4851[Partition]
4952Type=swap
5053SizeMaxBytes=64M
5154PaddingMinBytes=92M
5255EOF
5356
54- $repart $D /zzz --dry-run=no --seed=$SEED --definitions=$D /definitions
57+ " $repart " " $D /zzz" --dry-run=no --seed=" $SEED " --definitions=" $D /definitions"
5558
56- sfdisk -d $D /zzz | grep -v -e ' sector-size' -e ' ^$' > $D /populated
59+ sfdisk -d " $D /zzz" | grep -v -e ' sector-size' -e ' ^$' > " $D /populated"
5760
58- cmp $D /populated - << EOF
61+ cmp " $D /populated" - << EOF
5962label: gpt
6063label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
6164device: $D /zzz
7073
7174echo " ### Testing with root, root2, home, swap, & another partition ###"
7275
73- cat > $D /definitions/swap.conf << EOF
76+ cat > " $D /definitions/swap.conf" << EOF
7477[Partition]
7578Type=swap
7679SizeMaxBytes=64M
7780EOF
7881
79- cat > $D /definitions/extra.conf << EOF
82+ cat > " $D /definitions/extra.conf" << EOF
8083[Partition]
8184Type=linux-generic
8285Label=custom_label
8386UUID=a0a1a2a3a4a5a6a7a8a9aaabacadaeaf
8487EOF
8588
86- echo " Label=ignored_label" >> $D /definitions/home.conf
87- echo " UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >> $D /definitions/home.conf
89+ echo " Label=ignored_label" >> " $D /definitions/home.conf"
90+ echo " UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >> " $D /definitions/home.conf"
8891
89- $repart $D /zzz --dry-run=no --seed=$SEED --definitions=$D /definitions
92+ " $repart " " $D /zzz" --dry-run=no --seed=" $SEED " --definitions=" $D /definitions"
9093
91- sfdisk -d $D /zzz | grep -v -e ' sector-size' -e ' ^$' > $D /populated2
94+ sfdisk -d " $D /zzz" | grep -v -e ' sector-size' -e ' ^$' > " $D /populated2"
9295
93- cmp $D /populated2 - << EOF
96+ cmp " $D /populated2" - << EOF
9497label: gpt
9598label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
9699device: $D /zzz
@@ -106,11 +109,11 @@ EOF
106109
107110echo " ### Resizing to 2G ###"
108111
109- $repart $D /zzz --size=2G --dry-run=no --seed=$SEED --definitions=$D /definitions
112+ " $repart " " $D /zzz" --size=2G --dry-run=no --seed=" $SEED " --definitions=" $D /definitions"
110113
111- sfdisk -d $D /zzz | grep -v -e ' sector-size' -e ' ^$' > $D /populated3
114+ sfdisk -d " $D /zzz" | grep -v -e ' sector-size' -e ' ^$' > " $D /populated3"
112115
113- cmp $D /populated3 - << EOF
116+ cmp " $D /populated3" - << EOF
114117label: gpt
115118label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
116119device: $D /zzz
@@ -124,23 +127,23 @@ $D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-09
124127$D /zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name="custom_label"
125128EOF
126129
127- dd if=/dev/urandom of=$D /block-copy bs=4096 count=10240
130+ dd if=/dev/urandom of=" $D /block-copy" bs=4096 count=10240
128131
129132echo " ### Testing with root, root2, home, swap, another partition, & partition copy ###"
130133
131- cat > $D /definitions/extra2.conf << EOF
134+ cat > " $D /definitions/extra2.conf" << EOF
132135[Partition]
133136Type=linux-generic
134137Label=block-copy
135138UUID=2a1d97e1d0a346cca26eadc643926617
136139CopyBlocks=$D /block-copy
137140EOF
138141
139- $repart $D /zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D /definitions
142+ " $repart " " $D /zzz" --size=3G --dry-run=no --seed=" $SEED " --definitions=" $D /definitions"
140143
141- sfdisk -d $D /zzz | grep -v -e ' sector-size' -e ' ^$' > $D /populated4
144+ sfdisk -d " $D /zzz" | grep -v -e ' sector-size' -e ' ^$' > " $D /populated4"
142145
143- cmp $D /populated4 - << EOF
146+ cmp " $D /populated4" - << EOF
144147label: gpt
145148label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
146149device: $D /zzz
@@ -155,14 +158,14 @@ $D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D
155158$D /zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2A1D97E1-D0A3-46CC-A26E-ADC643926617, name="block-copy"
156159EOF
157160
158- cmp --bytes=41943040 --ignore-initial=0:$(( 512 * 4194264 )) $D /block-copy $D /zzz
161+ cmp --bytes=41943040 --ignore-initial=0:$(( 512 * 4194264 )) " $D /block-copy" " $D /zzz"
159162
160- if [ ` id -u` == 0 ] && type -P cryptsetup diff losetup > /dev/null ; then
163+ if [ " $( id -u) " -eq 0 ] && type -P cryptsetup diff losetup > /dev/null ; then
161164 echo " ### Testing Format=/Encrypt=/CopyFiles="
162165
163166 # These tests require privileges unfortunately
164167
165- cat > $D /definitions/extra3.conf << EOF
168+ cat > " $D /definitions/extra3.conf" << EOF
166169[Partition]
167170Type=linux-generic
168171Label=luks-format-copy
@@ -173,11 +176,11 @@ CopyFiles=$D/definitions:/def
173176SizeMinBytes=48M
174177EOF
175178
176- $repart $D /zzz --size=auto --dry-run=no --seed=$SEED --definitions=$D /definitions
179+ " $repart " " $D /zzz" --size=auto --dry-run=no --seed=" $SEED " --definitions=" $D /definitions"
177180
178- sfdisk -d $D /zzz | grep -v -e ' sector-size' -e ' ^$' > $D /populated5
181+ sfdisk -d " $D /zzz" | grep -v -e ' sector-size' -e ' ^$' > " $D /populated5"
179182
180- cmp $D /populated5 - << EOF
183+ cmp " $D /populated5" - << EOF
181184label: gpt
182185label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
183186device: $D /zzz
@@ -193,23 +196,23 @@ $D/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D
193196$D /zzz7 : start= 6291416, size= 98304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=7B93D1F2-595D-4CE3-B0B9-837FBD9E63B0, name="luks-format-copy"
194197EOF
195198
196- LOOP=` losetup -P --show --find $D /zzz`
197- VOLUME=test-repart-$RANDOM
199+ LOOP=" $( losetup -P --show --find " $D /zzz" ) "
200+ VOLUME=" test-repart-$RANDOM "
198201
199- touch $D /empty-password
200- cryptsetup open --type=luks2 --key-file=$D /empty-password ${LOOP} p7 $VOLUME
201- mkdir $D /mount
202- mount -t ext4 /dev/mapper/$VOLUME $D /mount
202+ touch " $D /empty-password"
203+ cryptsetup open --type=luks2 --key-file=" $D /empty-password" " ${LOOP} p7" " $VOLUME "
204+ mkdir " $D /mount"
205+ mount -t ext4 " /dev/mapper/$VOLUME " " $D /mount"
203206 # Use deferred closing on the mapper and autoclear on the loop, so they are cleaned up on umount
204- cryptsetup close --deferred $VOLUME
205- losetup -d $LOOP
206- diff -r $D /mount/def $D /definitions > /dev/null
207- umount $D /mount
207+ cryptsetup close --deferred " $VOLUME "
208+ losetup -d " $LOOP "
209+ diff -r " $D /mount/def" " $D /definitions" > /dev/null
210+ umount " $D /mount"
208211else
209212 echo " ### Skipping Format=/Encrypt=/CopyFiles= test, lacking privileges or missing cryptsetup/diff/losetup"
210213fi
211214
212215echo " ### Testing json output ###"
213- $repart $D /zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D /definitions --json=help
214- $repart $D /zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D /definitions --json=pretty
215- $repart $D /zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D /definitions --json=short
216+ " $repart " " $D /zzz" --size=3G --dry-run=no --seed=" $SEED " --definitions=" $D /definitions" --json=help
217+ " $repart " " $D /zzz" --size=3G --dry-run=no --seed=" $SEED " --definitions=" $D /definitions" --json=pretty
218+ " $repart " " $D /zzz" --size=3G --dry-run=no --seed=" $SEED " --definitions=" $D /definitions" --json=short
0 commit comments