diff --git a/mender-convert-extract b/mender-convert-extract index 3981368..82a8e15 100755 --- a/mender-convert-extract +++ b/mender-convert-extract @@ -76,7 +76,8 @@ if [ ! -f ${MKFS_VFAT} ]; then MKFS_VFAT="/sbin/mkfs.vfat" fi -declare -i nr_of_parts=$(disk_get_nr_of_parts ${disk_image}) +declare -a part_nrs=($(disk_get_part_nums ${disk_image})) +declare -i nr_of_parts=${#part_nrs[@]} log_info "Validating disk image" @@ -87,7 +88,7 @@ fi log_info "Disk parsed successfully" log_info "NUMBER OF PARTS: ${nr_of_parts} TYPE: $(disk_get_part_value ${disk_image} 1 SCHEME)" -for ((n=1;n<=${nr_of_parts};n++)); do +for n in ${part_nrs[*]} ; do part_dst_file="work/part-${n}.fs" if [ "$(disk_get_part_value ${disk_image} ${n} TYPE)" == "0x8e" ]; then diff --git a/modules/disk.sh b/modules/disk.sh index 7c82470..10c8c32 100644 --- a/modules/disk.sh +++ b/modules/disk.sh @@ -40,15 +40,19 @@ disk_get_part_value() { echo "$(partx -o ${3} -g -r --nr ${2} ${1})" } -# Prints number of partitions found in disk image +# Prints the partition numbers of all the partitions # # Example usage: # -# nr_of_parts=$(disk_get_nr_of_parts ${disk_image_path}) +# part_nums=$(disk_get_part_nums ${disk_image_path}) # # $1 - path to disk image -disk_get_nr_of_parts() { - echo "$(partx -l ${1} | wc -l)" +disk_get_part_nums() { + partx --show $1 | tail -n +2 | + while read line + do + echo $line | awk '{printf "%d\n", $1}' + done } # Extract a file system image from a disk image