Skip to content

Commit

Permalink
Merge branch 'patch/issue-226-impl-target-detection-for-partition-cre…
Browse files Browse the repository at this point in the history
…ation-mode'
  • Loading branch information
brlin-tw committed Dec 24, 2018
2 parents 289edfe + b7338d3 commit e46281b
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/woeusb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ init(){
"${install_mode}" \
"${target_media}" \
target_device \
target_partition
target_partition \
target_filesystem_type

check_source_and_target_not_busy \
"${install_mode}" \
Expand Down Expand Up @@ -831,16 +832,46 @@ check_runtime_parameters(){
}; declare -fr check_runtime_parameters

determine_target_parameters(){
util_check_function_parameters_quantity 4 $#
util_check_function_parameters_quantity 5 $#
local install_mode="${1}"; shift
local target_media="${1}"; shift
local -n target_device_ref="${1}"; shift
local -n target_partition_ref="${1}"; shift
local -n target_filesystem_type_ref="${1}"; shift

if [ "${install_mode}" = partition ]; then
local target_filesystem_type_libblkid

target_partition_ref="${target_media}"
# BASHDOC: Basic Shell Features » Shell Expansions » Shell Parameter Expansion(`${PARAMETER/PATTERN/STRING}')
target_device_ref="${target_media/%[0-9]/}"

# Detect target filesystem
target_filesystem_type_libblkid="$(
lsblk \
--noheadings \
--output FSTYPE \
"${target_partition_ref}"
)"

case "${target_filesystem_type_libblkid}" in
vfat)
target_filesystem_type_ref=FS_FAT
;;
ntfs)
target_filesystem_type_ref=FS_NTFS
;;
*)
printf -- \
'%s: Error: Unsupported target filesystem "%s", currently supported target filesystems: %s, %s' \
"${FUNCNAME[0]}" \
"${target_filesystem_type_libblkid}" \
"${ENUM_SUPPORTED_FILESYSTEMS[FS_FAT]}" \
"${ENUM_SUPPORTED_FILESYSTEMS[FS_NTFS]}"
return 1
;;
esac
unset target_filesystem_type_libblkid
else # install_mode = device
target_device_ref="${target_media}"
target_partition_ref="${target_device}1"
Expand All @@ -849,6 +880,9 @@ determine_target_parameters(){
if [ "${verbose}" = true ]; then
echo "${FUNCNAME[0]}: Info: Target device is '${target_device_ref}'."
echo "${FUNCNAME[0]}: Info: Target partition is '${target_partition_ref}'."
if [ "${install_mode}" = partition ]; then
echo "${FUNCNAME[0]}: Info: Target filesystem is '${ENUM_SUPPORTED_FILESYSTEMS[$target_filesystem_type]}'."
fi
fi
return 0
}; declare -fr determine_target_parameters
Expand Down

0 comments on commit e46281b

Please sign in to comment.