Skip to content

Commit 15ef588

Browse files
Refactor cmdline.txt with more variables
This removes all hardcoded references to cmdline.txt and cmdline.boot by removing the `$clone` prefix from cmdline_txt and introducing a cmdline_txt variable. In addition, this adds some quoting to any lines modified to be a bit more robust when spaces are involved. This should not change behavior (apart from maybe in cases with spaces that were previously broken), the commands ran should be identical.
1 parent 5640545 commit 15ef588

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

rpi-clone

+14-11
Original file line numberDiff line numberDiff line change
@@ -1789,35 +1789,38 @@ qecho ""
17891789
# Fix PARTUUID or device name references in cmdline.txt and fstab
17901790
#
17911791
fstab=${clone}/etc/fstab
1792-
cmdline_txt=${clone}/boot/cmdline.txt
1792+
cmdline_txt=/boot/cmdline.txt
1793+
cmdline_boot=/boot/cmdline.boot
17931794

1794-
if [ -f $cmdline_txt ]
1795+
if [ -f "${clone}${cmdline_txt}" ]
17951796
then
17961797
if ((leave_sd_usb_boot && SD_slot_dst))
17971798
then
17981799
qecho "Leaving SD to USB boot alone."
1799-
cp $cmdline_txt ${clone}/boot/cmdline.boot
1800-
cmdline_txt=${clone}/boot/cmdline.boot
1800+
cp "${clone}${cmdline_txt}" "${clone}${cmdline_boot}"
1801+
cmdline_txt=${cmdline_boot}
18011802
fi
1802-
if grep -q $src_disk_ID $cmdline_txt
1803+
if grep -q "$src_disk_ID" "${clone}${cmdline_txt}"
18031804
then
18041805
qecho "Editing $cmdline_txt PARTUUID to use $dst_disk_ID"
18051806
sed -i "s/${src_disk_ID}/${dst_disk_ID}/" "$cmdline_txt"
1806-
elif [ "${src_fsuuid[root_part_num]}" != "" ] && grep -q "${src_fsuuid[root_part_num]}" "$cmdline_txt"
1807+
elif [ "${src_fsuuid[root_part_num]}" != "" ] && grep -q "${src_fsuuid[root_part_num]}" "${clone}${cmdline_txt}"
18071808
then
18081809
new_fsuuid=${dst_fsuuid[root_part_num]}
18091810
qecho "Editing $cmdline_txt UUID to use $new_fsuuid"
1810-
sed -i "s/${src_fsuuid[root_part_num]}/${new_fsuuid}/" "$cmdline_txt"
1811-
elif [ "$edit_fstab_name" != "" ] && grep -q ${src_part_base} $cmdline_txt
1811+
sed -i "s/${src_fsuuid[root_part_num]}/${new_fsuuid}/" "${clone}${cmdline_txt}"
1812+
elif [ "$edit_fstab_name" != "" ] && grep -q "${src_part_base}" "${clone}${cmdline_txt}"
18121813
then
18131814
qecho "Editing $cmdline_txt references from $src_part_base to $edit_fstab_name"
1814-
sed -i "s/${src_part_base}/$edit_fstab_name/" "$cmdline_txt"
1815+
sed -i "s/${src_part_base}/$edit_fstab_name/" "${clone}${cmdline_txt}"
18151816
fi
18161817
if ((leave_sd_usb_boot && SD_slot_boot))
18171818
then
18181819
qecho "Copying USB cmdline.txt to SD card to set up USB boot."
1819-
cp /boot/cmdline.txt /boot/cmdline.boot
1820-
cp $cmdline_txt /boot/cmdline.txt
1820+
# Note that this leaves out $clone to modify the original SD
1821+
# card to boot from the clone instead
1822+
cp "${cmdline_txt}" "${cmdline_boot}"
1823+
cp "${clone}${cmdline_txt}" "${cmdline_txt}"
18211824
fi
18221825
fi
18231826

0 commit comments

Comments
 (0)