Skip to content

Commit 896fd9f

Browse files
committed
More formatting. Reverse order of destination disk mounted checks.
1 parent 08da1fe commit 896fd9f

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

rpi-clone

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
version=2.0.14
3+
version=2.0.15
44

55
# auto run grub-install if grub detected
66
grub_auto=1
@@ -1025,7 +1025,7 @@ then
10251025
exit 1
10261026
fi
10271027

1028-
for ((p = 1; p <= n_dst_parts; p++))
1028+
for ((p = n_dst_parts; p >= 1; --p))
10291029
do
10301030
if ((!dst_exists[p]))
10311031
then
@@ -1034,9 +1034,20 @@ do
10341034
dir=$(echo "$dst_mount_table" \
10351035
| grep -e "^${dst_device[p]}" | cut -d " " -f 2)
10361036
unmount_or_abort "$dir" \
1037-
"Destination disk partition ${dst_device[p]} is mounted on ${dst_mounted_dir[p]}."
1037+
"Destination disk partition ${dst_device[p]} is mounted on $dir."
10381038
done
10391039

1040+
mounted_dev=$(findmnt $clone -o source -n)
1041+
unmount_or_abort "$mounted_dev" \
1042+
"Directory $clone is already mounted with $mounted_dev."
1043+
1044+
mounted_dev=$(findmnt $clone_src -o source -n)
1045+
unmount_or_abort "$mounted_dev" \
1046+
"Directory $clone_src is already mounted with $mounted_dev."
1047+
1048+
mounted_dev=$(findmnt /mnt -o source -n)
1049+
unmount_or_abort "$mounted_dev" "$mounted_dev is currently mounted on /mnt."
1050+
10401051

10411052
if [ ! -d $clone ]
10421053
then
@@ -1059,19 +1070,6 @@ then
10591070
exclude_swapfile="--exclude $swapfile"
10601071
fi
10611072

1062-
# TODO: exclude fuse mounts (readlink_stat errors): process findmnt -D | fuse
1063-
1064-
mounted_dev=$(findmnt $clone -o source -n)
1065-
unmount_or_abort "$mounted_dev" \
1066-
"Directory $clone is already mounted with $mounted_dev."
1067-
1068-
mounted_dev=$(findmnt $clone_src -o source -n)
1069-
unmount_or_abort "$mounted_dev" \
1070-
"Directory $clone_src is already mounted with $mounted_dev."
1071-
1072-
mounted_dev=$(findmnt /mnt -o source -n)
1073-
unmount_or_abort "$mounted_dev" "$mounted_dev is currently mounted on /mnt."
1074-
10751073
print_partitions
10761074

10771075
if ((initialize))
@@ -1276,7 +1274,7 @@ Use -U for unattended even if initializing.
12761274
if [ "$fs_type" == "swap" ]
12771275
then
12781276
printf " => mkswap $dst_dev\n"
1279-
mkswap $dst_dev
1277+
mkswap $dst_dev &>> /tmp/$PGM-log
12801278
elif ((p != ext_part_num))
12811279
then
12821280
if [ "${src_mounted_dir[p]}" != "" ] || ((p == n_image_parts))
@@ -1289,7 +1287,7 @@ Use -U for unattended even if initializing.
12891287
fs_type="vfat -F 32"
12901288
fi
12911289
printf " => mkfs -t $fs_type $dst_dev ..."
1292-
mkfs -t "$fs_type" "$dst_dev" &> /dev/null <<< "yes"
1290+
mkfs -t "$fs_type" "$dst_dev" &>> /tmp/$PGM-output <<< "yes"
12931291
# mkfs -t "$fs_type" "$dst_dev" <<< "yes"
12941292
echo ""
12951293
if ((p == n_image_parts))
@@ -1302,9 +1300,14 @@ Use -U for unattended even if initializing.
13021300
fi
13031301
fi
13041302
else
1305-
printf "\n => dd if=${src_device[$p]} of=$dst_dev bs=1M ...\n"
1306-
dd if=${src_device[$p]} of=$dst_dev bs=1M
1307-
echo ""
1303+
printf " => dd if=${src_device[$p]} of=$dst_dev bs=1M ..."
1304+
dd if=${src_device[$p]} of=$dst_dev bs=1M &>> /tmp/$PGM-output
1305+
if [ "$?" != 0 ]
1306+
then
1307+
printf "\n dd failed. See /tmp/$PGM-output.\n"
1308+
else
1309+
echo ""
1310+
fi
13081311
fi
13091312
fi
13101313
fi
@@ -1417,10 +1420,9 @@ do
14171420
rsync_file_system "${clone_src}/" "${clone}" ""
14181421
unmount_list "$unmount_list"
14191422
fi
1420-
done
1421-
1423+
done
14221424

1423-
qprintf "\nSyncing mounted partitions:\n"
1425+
qprintf "Syncing mounted partitions:\n"
14241426
mount_partition $dst_root_dev $clone ""
14251427
unmount_list="$clone"
14261428

0 commit comments

Comments
 (0)