Skip to content

Commit f083e6b

Browse files
Improve output for cmdline/fstab updates
This modifies fixup_device_references_in_file to accept the mountpoint and filename separately to prevent printing the destination mountpoint (which might be ugly and meaningless). fixup_boot_partition already had this. Then, a partition label is passed which is prefixed to this plain filename to tell the user which partition is being modified. This could just have used src_mount, but passing a separate label prepares for using this code for non-mounted partitions too. Finally, the UUID output is slightly reworded and some indentation is added (preparing for this output to also be intermixed with mounting and rsync calls later).
1 parent 31ec209 commit f083e6b

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

rpi-clone

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -640,22 +640,24 @@ get_src_disk()
640640
# Fix PARTUUID/UUID or device name references in cmdline.txt
641641
fixup_boot_partition()
642642
{
643-
src_mount=$1
644-
dst_mount=$2
643+
partition=$1
644+
src_mount=$2
645+
dst_mount=$3
645646

646647
# Just try all flavors
647648
# Paths are below the /boot directory/mountpoint
648-
fixup_cmdline_txt "${src_mount}" "${dst_mount}" /cmdline.txt /cmdline.boot
649-
fixup_cmdline_txt "${src_mount}" "${dst_mount}" /armbianEnv.txt /armbianEnv.boot
650-
fixup_cmdline_txt "${src_mount}" "${dst_mount}" /firmware/cmdline.txt /firmware/cmdline.boot # Ubuntu
649+
fixup_cmdline_txt "${partition}" "${src_mount}" "${dst_mount}" /cmdline.txt /cmdline.boot
650+
fixup_cmdline_txt "${partition}" "${src_mount}" "${dst_mount}" /armbianEnv.txt /armbianEnv.boot
651+
fixup_cmdline_txt "${partition}" "${src_mount}" "${dst_mount}" /firmware/cmdline.txt /firmware/cmdline.boot # Ubuntu
651652
}
652653

653654
fixup_cmdline_txt()
654655
{
655-
src_mount=$1
656-
dst_mount=$2
657-
cmdline_txt=$3
658-
cmdline_boot=$4
656+
partition=$1
657+
src_mount=$2
658+
dst_mount=$3
659+
cmdline_txt=$4
660+
cmdline_boot=$5
659661

660662
if [ -f "${dst_mount}${cmdline_txt}" ]
661663
then
@@ -666,7 +668,7 @@ fixup_cmdline_txt()
666668
cmdline_txt=${cmdline_boot}
667669
fi
668670

669-
fixup_device_references_in_file "${dst_mount}${cmdline_txt}"
671+
fixup_device_references_in_file "${partition}" "${dst_mount}" "${cmdline_txt}"
670672

671673
if ((leave_sd_usb_boot && SD_slot_boot))
672674
then
@@ -680,29 +682,31 @@ fixup_cmdline_txt()
680682
}
681683

682684
fixup_device_references_in_file() {
683-
file=$1
684-
if grep -q $src_disk_ID $file
685+
partition=$1
686+
dst_mount=$2
687+
file=$3
688+
if grep -q "${src_disk_ID}" "${dst_mount}${file}"
685689
then
686-
qecho "Editing $file PARTUUID to use $dst_disk_ID"
687-
sed -i "s/${src_disk_ID}/${dst_disk_ID}/g" "$file"
688-
elif grep -q UUID= $file
690+
qecho " Editing $partition$file PARTUUID to use $dst_disk_ID"
691+
sed -i "s/${src_disk_ID}/${dst_disk_ID}/g" "${dst_mount}${file}"
692+
elif grep -q UUID= "${dst_mount}${file}"
689693
then
690694
for ((p = 1; p <= n_src_parts; p++))
691695
do
692696
old_fsuuid=${src_fsuuid[p]}
693697
new_fsuuid=${dst_fsuuid[p]}
694-
if [ "$old_fsuuid" == "" -o "$new_fsuuid" == "" ] || ! grep -q "$old_fsuuid" "$file";
698+
if [ "$old_fsuuid" == "" -o "$new_fsuuid" == "" ] || ! grep -q "$old_fsuuid" "${dst_mount}${file}";
695699
then
696700
continue
697701
fi
698702

699-
qecho "Editing $file partition $p UUID to use $new_fsuuid"
700-
sed -i "s/$old_fsuuid/${new_fsuuid}/" "$file"
703+
qecho " Editing $partition$file UUID to use $new_fsuuid for partition $p"
704+
sed -i "s/$old_fsuuid/${new_fsuuid}/" "${dst_mount}${file}"
701705
done
702-
elif [ "$edit_fstab_name" != "" ] && grep -q ${src_part_base} $file
706+
elif [ "$edit_fstab_name" != "" ] && grep -q ${src_part_base} "${dst_mount}${file}"
703707
then
704-
qecho "Editing $file references from $src_part_base to $edit_fstab_name"
705-
sed -i "s/${src_part_base}/${edit_fstab_name}/" "$file"
708+
qecho " Editing $partition$file references from $src_part_base to $edit_fstab_name"
709+
sed -i "s/${src_part_base}/${edit_fstab_name}/" "${dst_mount}${file}"
706710
fi
707711
}
708712

@@ -1856,8 +1860,8 @@ do
18561860
done
18571861
qecho ""
18581862

1859-
fixup_boot_partition /boot "${clone}/boot"
1860-
fixup_device_references_in_file "${clone}/etc/fstab"
1863+
fixup_boot_partition /boot /boot "${clone}/boot"
1864+
fixup_device_references_in_file "" "${clone}" /etc/fstab
18611865

18621866
rm -f $clone/etc/udev/rules.d/70-persistent-net.rules
18631867

0 commit comments

Comments
 (0)