Skip to content

Commit de03424

Browse files
authored
Merge pull request #11 from st-matskevich/lsblk-uniq
Properly handle multiple entries for the same device in lsblk output.
2 parents 688ed4b + aee8cd7 commit de03424

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Linux/bcd-sys.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ if [[ "$firmware" == "uefi" ]]; then
237237
if [[ "$virtual" == "true" ]]; then umount_vpart; fi
238238
exit 1
239239
fi
240-
efifstype=$(lsblk -o path,fstype | grep "$efipart" | awk '{print $2}')
241-
syspath=$(lsblk -o path,mountpoint | grep "$efipart" | awk -v n=2 '{ for (i=n; i<=NF; i++) printf "%s%s", $i, (i<NF ? OFS : ORS)}')
240+
efifstype=$(lsblk -o path,fstype | grep "$efipart" | awk '{print $2}' | uniq)
241+
syspath=$(lsblk -o path,mountpoint | grep "$efipart" | awk -v n=2 '{ for (i=n; i<=NF; i++) printf "%s%s", $i, (i<NF ? OFS : ORS)}' | uniq)
242242
if [[ -z "${syspath// }" ]]; then
243243
rmsysmnt="true"
244244
syspath="/mnt/EFI"
@@ -285,8 +285,8 @@ elif [[ "$firmware" == "bios" || "$firmware" == "both" ]]; then
285285
if [[ "$virtual" == "true" ]]; then umount_vpart; fi
286286
exit 1
287287
fi
288-
sysfstype=$(lsblk -o path,fstype | grep "$syspart" | awk '{print $2}')
289-
syspath=$(lsblk -o path,mountpoint | grep "$syspart" | awk -v n=2 '{ for (i=n; i<=NF; i++) printf "%s%s", $i, (i<NF ? OFS : ORS)}')
288+
sysfstype=$(lsblk -o path,fstype | grep "$syspart" | awk '{print $2}' | uniq)
289+
syspath=$(lsblk -o path,mountpoint | grep "$syspart" | awk -v n=2 '{ for (i=n; i<=NF; i++) printf "%s%s", $i, (i<NF ? OFS : ORS)}' | uniq)
290290
if [[ -z "${syspath// }" ]]; then
291291
rmsysmnt="true"
292292
syspath="/mnt/winsys"
@@ -317,10 +317,10 @@ if [[ "$firmware" == "uefi" ]]; then
317317
if [[ "$virtual" == "false" || "$verbose" == "true" ]]; then
318318
echo "Get block device for mount point (sudo required later)..."
319319
fi
320-
efipart=$(lsblk -o path,mountpoint | grep "$syspath" | awk '{print $1}')
321-
efifstype=$(lsblk -o path,fstype | grep "$efipart" | awk '{print $2}')
320+
efipart=$(lsblk -o path,mountpoint | grep "$syspath" | awk '{print $1}' | uniq)
321+
efifstype=$(lsblk -o path,fstype | grep "$efipart" | awk '{print $2}' | uniq)
322322
elif [[ "$firmware" == "bios" || "$firmware" == "both" ]]; then
323-
syspart=$(lsblk -o path,mountpoint | grep "$syspath" | awk '{print $1}')
323+
syspart=$(lsblk -o path,mountpoint | grep "$syspath" | awk '{print $1}' | uniq)
324324
sysdisk=$(printf "$syspart" | sed 's/[0-9]\+$//;s/p\+$//')
325325
if [[ "$virtual" == "false" || "$verbose" == "true" ]]; then
326326
echo "Checking block device for active partition (sudo required)..."
@@ -349,7 +349,7 @@ elif [[ "$firmware" == "bios" || "$firmware" == "both" ]]; then
349349
if [[ "$virtual" == "true" ]]; then umount_vpart; fi
350350
exit 1
351351
fi
352-
sysfstype=$(lsblk -o path,fstype | grep "$syspart" | awk '{print $2}')
352+
sysfstype=$(lsblk -o path,fstype | grep "$syspart" | awk '{print $2}' | uniq)
353353
if [[ "$firmware" == "both" ]]; then
354354
efipart="$syspart"
355355
efifstype="$sysfstype"
@@ -383,7 +383,7 @@ mount_vpart () {
383383
vrtpath="/mnt/virtwin"
384384
echo "Partition table on: $imgpath"
385385
echo
386-
lsblk "$vrtdisk" -o path,pttype,fstype,parttypename,label,mountpoint | sed '2d'
386+
lsblk "$vrtdisk" -o path,pttype,fstype,parttypename,label,mountpoint | sed '2d' | uniq
387387
echo
388388
read -p "Enter device containing the Windows volume [nbd#p#]:" vtwinpart
389389
while [[ "$vtwinpart" != *"nbd"* || ! -e "/dev/$vtwinpart" ]]; do
@@ -526,11 +526,11 @@ fi
526526
# Check source for path to the WBM files then get the block device.
527527
# Get the mount point, file path and block device that contains the virtual disk file.
528528
if [[ -d "$winpath/Windows/Boot" ]]; then
529-
windisk=$(lsblk -o path,mountpoint | grep "$winpath" | awk '{print $1}' | sed 's/[0-9]\+$//;s/p\+$//')
529+
windisk=$(lsblk -o path,mountpoint | grep "$winpath" | awk '{print $1}' | sed 's/[0-9]\+$//;s/p\+$//' | uniq)
530530
elif [[ "$virtual" == "true" && -d "$vrtpath/Windows/Boot" ]]; then
531531
if [[ "$winpath" == *"/mnt"* ]]; then winpath=$(echo "$winpath" | cut -d/ -f1-3); fi
532532
if [[ "$winpath" == *"/media"* ]]; then winpath=$(echo "$winpath" | cut -d/ -f1-4); fi
533-
windisk=$(lsblk -o path,mountpoint | grep "$winpath" | awk '{print $1}' | sed 's/[0-9]\+$//;s/p\+$//')
533+
windisk=$(lsblk -o path,mountpoint | grep "$winpath" | awk '{print $1}' | sed 's/[0-9]\+$//;s/p\+$//' | uniq)
534534
if [[ "$imgpath" == *"/mnt"* ]]; then imgstring=$(echo "$imgpath" | cut -d/ -f4- | sed 's/^/\\/;s/\//\\/g'); fi
535535
if [[ "$imgpath" == *"/media"* ]]; then imgstring=$(echo "$imgpath" | cut -d/ -f5- | sed 's/^/\\/;s/\//\\/g'); fi
536536
else

0 commit comments

Comments
 (0)