Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
fix: robust check for image hybridness
Browse files Browse the repository at this point in the history
The last version of "file" utility changed behavior regarding non-hybrid
images. From now on, sfdisk is used to check for presence of a table
partition. If there is one, the image must be hybrid.

Closes #61
  • Loading branch information
jsamr committed Oct 4, 2020
1 parent ab5d1a0 commit 549ec91
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
56 changes: 28 additions & 28 deletions bootiso
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# shellcheck disable=SC2181
# shellcheck disable=SC2236
#
# Version 4.1.1
# Version 4.2.0
#
# bootiso - create a bootable USB drive from an image file
# Copyright (C) 2018-2020 jules randolph <[email protected]>
Expand All @@ -26,7 +26,7 @@
set -o pipefail
set -E

version="4.1.1"
version="4.2.0"
scriptName=$(basename "$0")
bashVersion=$(echo "$BASH_VERSION" | cut -d. -f1)

Expand Down Expand Up @@ -309,7 +309,7 @@ function term_printLog() {
function term_indentAll() {
while read -r line; do
term_printColumn " " "$term_logPrefixLength" "$line"
done < "${1:-/dev/stdin}"
done <"${1:-/dev/stdin}"
}

# $*: The message to print.
Expand Down Expand Up @@ -480,15 +480,15 @@ function fs_mountUSB() {
st_usbMountPoint=$(fs_createMountFolder usb) || exit "$?"
st_temporaryAssets+=("$st_usbMountPoint")
term_echoinfo "Created USB device mount point at '$st_usbMountPoint'"
if ! mount -t "$_type" "$st_targetPartition" "$st_usbMountPoint" > /dev/null; then
if ! mount -t "$_type" "$st_targetPartition" "$st_usbMountPoint" >/dev/null; then
ps_failAndExit IO_ERROR "Could not mount USB device."
fi
}

# $1 - mountPoint
function fs_mountElToritoFile() {
local -r _mountPoint="$1"
if ! mount -r -o loop -- "$sourceImageFile" "$_mountPoint" > /dev/null; then
if ! mount -r -o loop -- "$sourceImageFile" "$_mountPoint" >/dev/null; then
ps_failAndExit IO_ERROR "Could not mount image file."
else
st_temporaryAssets+=("$_mountPoint")
Expand Down Expand Up @@ -587,7 +587,7 @@ function fs_syncWithProgress() {

# $1 - The name of the command to check in $PATH.
function sys_hasCommand() {
command -v "$1" &> /dev/null
command -v "$1" &>/dev/null
return $?
}

Expand Down Expand Up @@ -928,7 +928,7 @@ function asrt_checkSudo() {
if [[ -t 1 ]] && sys_hasCommand sudo; then
sudo --preserve-env "$0" "$@"
elif sys_hasCommand gksu; then
exec 1> output_file
exec 1>output_file
gksu --preserve-env "$0" "$@"
else
ps_failAndExit MISSING_PRIVILEGE "You must run $scriptName as root."
Expand Down Expand Up @@ -975,14 +975,14 @@ function asrt_checkImageHash() {
printf "%s" \
"You can disable this check with $(term_boldify "-H, --no-hash-check") flags." | term_indentAll
st_temporaryAssets+=("$_hashStoreFile")
(
(
local _hash
local -i
_hash=$($_hashName "$_imageName" | awk "{print \$1; exit }")
if (($? == 0)); then
printf "%s" "$_hash" > "$_hashStoreFile"
printf "%s" "$_hash" >"$_hashStoreFile"
else
printf "%s" 1 > "$_hashStoreFile"
printf "%s" 1 >"$_hashStoreFile"
fi
) &
st_backgroundProcess=$!
Expand Down Expand Up @@ -1083,11 +1083,11 @@ function asrt_checkPackages() {
sys_checkCommand "$_pkg"
done
# test grep supports -P option
if ! echo 1 | grep -P '1' &> /dev/null; then
if ! echo 1 | grep -P '1' &>/dev/null; then
ps_failAndExit MISSING_DEPENDENCY \
"You're using an old version of grep which does not support perl regular expression (-P option)."
fi
if echo "" | column -t -N t -W t &> /dev/null; then
if echo "" | column -t -N t -W t &>/dev/null; then
st_hasLegacyColumn=false
else
# Old BSD command, see https://git.io/JfauE
Expand Down Expand Up @@ -1174,7 +1174,7 @@ function asrt_checkFSType() {
ps_failAndExit SYNOPSIS_NONCOMPL "Filesystem type '$_fsType' not supported." \
"Supported filesystem types: $(sh_joinBy "," "${asrt_supportedFS[*]}")."
fi
if ! command -v "mkfs.$_fsType" &> /dev/null; then
if ! command -v "mkfs.$_fsType" &>/dev/null; then
ps_failAndExit MISSING_DEPENDENCY \
"Program 'mkfs.$_fsType' could not be found on your system." \
"Please install it and retry."
Expand Down Expand Up @@ -1377,7 +1377,7 @@ function devi_configureLabel() {
# Fallback to "USER_VENDOR" if format
if [[ "$targetAction" == format ]]; then
_user=${SUDO_USER:-$USER}
_vendor=$(lsblk -ldno VENDOR "$targetDevice" 2> /dev/null)
_vendor=$(lsblk -ldno VENDOR "$targetDevice" 2>/dev/null)
_vendor=${_vendor:-FLASH}
targetPartitionLabel=${targetPartitionLabel:-"${_user^^}_${_vendor^^}"}
else
Expand Down Expand Up @@ -1530,7 +1530,7 @@ function devi_partitionUSB() {
# unmount any partition on selected device
mapfile -t devicePartitions < <(grep -oP "^\\K$targetDevice\\S*" /proc/mounts)
for _partition in "${devicePartitions[@]}"; do
if ! umount "$_partition" > /dev/null; then
if ! umount "$_partition" >/dev/null; then
ps_failAndExit IO_ERROR \
"Failed to unmount $_partition. It's likely that the partition is busy."
fi
Expand All @@ -1539,7 +1539,7 @@ function devi_partitionUSB() {
function _eraseDevice() {
term_echoinfo "Erasing contents of '$targetDevice'..."
# clean signature from selected device
wipefs --all --force "$targetDevice" &> /dev/null
wipefs --all --force "$targetDevice" &>/dev/null
# erase drive
dd if=/dev/zero of="$targetDevice" bs=512 count=1 conv=notrunc status=none |&
term_indentAll ||
Expand Down Expand Up @@ -1773,8 +1773,8 @@ function devi_inspectHybridImage() {
_supportsEFIBoot=false
fi
}
_diskReport=$(sfdisk -lJ -- "$sourceImageFile" 2> /dev/null) \
|| ps_failAndExit IO_ERROR "sfdisk couldn't read the partition table on the image file, which is likely corrupted."
_diskReport=$(sfdisk -lJ -- "$sourceImageFile" 2>/dev/null) ||
ps_failAndExit IO_ERROR "sfdisk couldn't read the partition table on the image file, which is likely corrupted."
_partScheme=$(echo "$_diskReport" | jq -r '.partitiontable.label')
case $_partScheme in
dos) _inspectMBRPartTable ;;
Expand Down Expand Up @@ -1850,11 +1850,11 @@ function step_initDevicesList() {
function step_inspectImageFile() {
local _isHybrid
function _inspectImageFilesystem() {
file -b -- "$sourceImageFile" | grep -q '^ISO 9660 CD-ROM filesystem'
sfdisk -J -- "$sourceImageFile" | jq -e .partitiontable.label &>/dev/null
if (($? == 0)); then
_isHybrid=false
else
_isHybrid=true
else
_isHybrid=false
fi
}
_inspectImageFilesystem
Expand Down Expand Up @@ -1905,7 +1905,7 @@ function step_installBootloader() {
fi
fi
term_echoinfo "Found local SYSLINUX version '$_localSyslinuxVersion'"
sh_compute "$_localSyslinuxVersion == ${st_isoInspections[syslinuxVer]}" > /dev/null
sh_compute "$_localSyslinuxVersion == ${st_isoInspections[syslinuxVer]}" >/dev/null
_versionsMatch=$?
if ((_versionsMatch == 0)); then
term_echogood "image SYSLINUX version matches local version."
Expand Down Expand Up @@ -1951,7 +1951,7 @@ function step_installBootloader() {
function _installWtKernelOrgExtlinux() {
local _isExt32 _isHost32 _fallbackToLocal=false
term_echoinfo "Installing SYSLINUX bootloader in '$_syslinuxFolder' with kernel.org version '$st_targetSyslinuxVersion'..."
file -b -- "${st_syslinuxBinaries['extBin']}" | awk '{print $2}' | grep -e '^32' &> /dev/null
file -b -- "${st_syslinuxBinaries['extBin']}" | awk '{print $2}' | grep -e '^32' &>/dev/null
_isExt32=$?
echo "$ct_architecture" | grep -e '32|i386'
_isHost32=$?
Expand All @@ -1975,7 +1975,7 @@ function step_installBootloader() {
fi
fi
if [[ "$_fallbackToLocal" == true ]]; then
_installWtLocalExtlinux > /dev/null
_installWtLocalExtlinux >/dev/null
fi
fs_syncdev
}
Expand Down Expand Up @@ -2015,7 +2015,7 @@ function step_copyWithRsync() {
term_echowarn "Detected a Windows install.wim file but wimsplit has been disabled with $(term_boldify '--no-wim-split') option."
fi
fi
(
(
# shellcheck disable=SC2086
rsync -r -q -I --no-links --no-perms --no-owner --no-group $_rsyncOptions "$st_elToritoMountPoint"/. "$st_usbMountPoint"
_status=$?
Expand All @@ -2024,7 +2024,7 @@ function step_copyWithRsync() {
echo
wimlib-imagex split "$_wimFile" "$st_usbMountPoint/sources/install.swm" 1024 |& term_indentAll
fi
echo "$_status" > "$_statusFile"
echo "$_status" >"$_statusFile"
) &
st_backgroundProcess=$!
echo -n "$scriptName: Copying files from image to USB device with 'rsync' "
Expand All @@ -2050,9 +2050,9 @@ function step_copyWithDD() {
local _status
_statusFile=$(fs_createTempFile "bootiso-status")
st_temporaryAssets+=("$_statusFile")
(
(
dd if="$sourceImageFile" of="$targetDevice" bs="$targetDDBusSize" status=none
echo "$?" > "$_statusFile"
echo "$?" >"$_statusFile"
) &
st_backgroundProcess=$!
echo -n "$scriptName: Copying files from image to USB device with 'dd' "
Expand Down
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v4.1.1
# v4.2.0

**Enhancements**

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ <h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1
<table class="foot">
<tr>
<td class="foot-date">May 22, 2020</td>
<td class="foot-os">bootiso 4.1.1</td>
<td class="foot-os">bootiso 4.2.0</td>
</tr>
</table>
</body>
2 changes: 1 addition & 1 deletion extra/man/bootiso.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.
.Dd May 22, 2020
.Dt BOOTISO 1
.Os bootiso 4.1.1
.Os bootiso 4.2.0
.Sh NAME
.Nm bootiso
.Nd create a bootable USB drive from an image file
Expand Down

0 comments on commit 549ec91

Please sign in to comment.