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

Commit abda462

Browse files
committed
bootiso: simplify a few instances of return status handling
1 parent 6c6b3c6 commit abda462

File tree

1 file changed

+30
-51
lines changed

1 file changed

+30
-51
lines changed

bootiso

+30-51
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function term_printLog() {
309309
function term_indentAll() {
310310
while read -r line; do
311311
term_printColumn " " "$term_logPrefixLength" "$line"
312-
done <"${1:-/dev/stdin}"
312+
done < "${1:-/dev/stdin}"
313313
}
314314

315315
# $*: The message to print.
@@ -423,29 +423,15 @@ function fs_findFileFromPatterns() {
423423

424424
function fs_createTempFile() {
425425
local -r _prefix=$1
426-
local _tmpFileTemplate="$ct_tempRoot/$_prefix-XXX" _status
427-
mktemp "$_tmpFileTemplate"
428-
_status=$?
429-
if [ ! $_status -eq 0 ]; then
430-
ps_failAndExit IO_ERROR "Failed to create temporary file."
431-
fi
426+
local _tmpFileTemplate="$ct_tempRoot/$_prefix-XXX"
427+
mktemp "$_tmpFileTemplate" || ps_failAndExit IO_ERROR "Failed to create temporary file."
432428
}
433429
# Print the name of the new folder if operation
434430
# succeeded, fails otherwise.
435431
#
436432
# $1 - The folder name prefix
437433
function fs_createMountFolder() {
438-
local _tmpFileTemplate _status
439-
if ((EUID == 0)); then
440-
_tmpFileTemplate="$ct_mountRoot/$1-XXX"
441-
else
442-
_tmpFileTemplate="$ct_tempRoot/$1-XXX"
443-
fi
444-
mktemp -d "$_tmpFileTemplate"
445-
_status=$?
446-
if [ ! $_status -eq 0 ]; then
447-
ps_failAndExit IO_ERROR "Failed to create temporary mount point with pattern '$_tmpFileTemplate'."
448-
fi
434+
mktemp -d "$ct_mountRoot/$1-XXX" || ps_failAndExit IO_ERROR "Failed to create temporary mount point with pattern '$_tmpFileTemplate'."
449435
}
450436

451437
function fs_syncdev() {
@@ -494,15 +480,15 @@ function fs_mountUSB() {
494480
st_usbMountPoint=$(fs_createMountFolder usb) || exit "$?"
495481
st_temporaryAssets+=("$st_usbMountPoint")
496482
term_echoinfo "Created USB device mount point at '$st_usbMountPoint'"
497-
if ! mount -t "$_type" "$st_targetPartition" "$st_usbMountPoint" >/dev/null; then
483+
if ! mount -t "$_type" "$st_targetPartition" "$st_usbMountPoint" > /dev/null; then
498484
ps_failAndExit IO_ERROR "Could not mount USB device."
499485
fi
500486
}
501487

502488
# $1 - mountPoint
503489
function fs_mountElToritoFile() {
504490
local -r _mountPoint="$1"
505-
if ! mount -r -o loop -- "$sourceImageFile" "$_mountPoint" >/dev/null; then
491+
if ! mount -r -o loop -- "$sourceImageFile" "$_mountPoint" > /dev/null; then
506492
ps_failAndExit IO_ERROR "Could not mount image file."
507493
else
508494
st_temporaryAssets+=("$_mountPoint")
@@ -601,7 +587,7 @@ function fs_syncWithProgress() {
601587

602588
# $1 - The name of the command to check in $PATH.
603589
function sys_hasCommand() {
604-
command -v "$1" &>/dev/null
590+
command -v "$1" &> /dev/null
605591
return $?
606592
}
607593

@@ -942,7 +928,7 @@ function asrt_checkSudo() {
942928
if [[ -t 1 ]] && sys_hasCommand sudo; then
943929
sudo --preserve-env "$0" "$@"
944930
elif sys_hasCommand gksu; then
945-
exec 1>output_file
931+
exec 1> output_file
946932
gksu --preserve-env "$0" "$@"
947933
else
948934
ps_failAndExit MISSING_PRIVILEGE "You must run $scriptName as root."
@@ -989,15 +975,14 @@ function asrt_checkImageHash() {
989975
printf "%s" \
990976
"You can disable this check with $(term_boldify "-H, --no-hash-check") flags." | term_indentAll
991977
st_temporaryAssets+=("$_hashStoreFile")
992-
(
978+
(
993979
local _hash
994-
local -i _status=0
980+
local -i
995981
_hash=$($_hashName "$_imageName" | awk "{print \$1; exit }")
996-
_status=$?
997-
if ((_status == 0)); then
998-
printf "%s" "$_hash" >"$_hashStoreFile"
982+
if (($? == 0)); then
983+
printf "%s" "$_hash" > "$_hashStoreFile"
999984
else
1000-
printf "%s" 1 >"$_hashStoreFile"
985+
printf "%s" 1 > "$_hashStoreFile"
1001986
fi
1002987
) &
1003988
st_backgroundProcess=$!
@@ -1015,7 +1000,7 @@ function asrt_checkImageHash() {
10151000
local -r _hashPath=$1 # Path to file containing _hashes
10161001
local -r _imageName=$2 # File to be checked
10171002
local -r _hashName=$3 # Name of command of _hash
1018-
local _status _answer
1003+
local _answer
10191004
# Hash from _hash file
10201005
local _gHash
10211006
_gHash=$(awk -v pattern="$_imageName$" '$0 ~ pattern { print $1; exit }' "$_hashPath")
@@ -1042,11 +1027,7 @@ function asrt_checkImageHash() {
10421027
esac
10431028
fi
10441029
# Hash from iso
1045-
_computeHashWithProgress $_hashName "$_imageName"
1046-
_status=$?
1047-
if ((_status != 0)); then
1048-
ps_failAndExit THIRD_PARTY_ERROR "$_hashName command failed with status $_status"
1049-
fi
1030+
_computeHashWithProgress $_hashName "$_imageName" || ps_failAndExit THIRD_PARTY_ERROR "$_hashName command failed with status $?"
10501031
if [ "$_gHash" != "$_lHash" ]; then
10511032
if [ "$enableForceHashCheck" == 'true' ]; then
10521033
ps_failAndExit ASSERTION_FAILED "Hash mismatch in '$_hashPath' (${_hashName%sum})."
@@ -1102,11 +1083,11 @@ function asrt_checkPackages() {
11021083
sys_checkCommand "$_pkg"
11031084
done
11041085
# test grep supports -P option
1105-
if ! echo 1 | grep -P '1' &>/dev/null; then
1086+
if ! echo 1 | grep -P '1' &> /dev/null; then
11061087
ps_failAndExit MISSING_DEPENDENCY \
11071088
"You're using an old version of grep which does not support perl regular expression (-P option)."
11081089
fi
1109-
if echo "" | column -t -N t -W t &>/dev/null; then
1090+
if echo "" | column -t -N t -W t &> /dev/null; then
11101091
st_hasLegacyColumn=false
11111092
else
11121093
# Old BSD command, see https://git.io/JfauE
@@ -1193,7 +1174,7 @@ function asrt_checkFSType() {
11931174
ps_failAndExit SYNOPSIS_NONCOMPL "Filesystem type '$_fsType' not supported." \
11941175
"Supported filesystem types: $(sh_joinBy "," "${asrt_supportedFS[*]}")."
11951176
fi
1196-
if ! command -v "mkfs.$_fsType" &>/dev/null; then
1177+
if ! command -v "mkfs.$_fsType" &> /dev/null; then
11971178
ps_failAndExit MISSING_DEPENDENCY \
11981179
"Program 'mkfs.$_fsType' could not be found on your system." \
11991180
"Please install it and retry."
@@ -1396,7 +1377,7 @@ function devi_configureLabel() {
13961377
# Fallback to "USER_VENDOR" if format
13971378
if [[ "$targetAction" == format ]]; then
13981379
_user=${SUDO_USER:-$USER}
1399-
_vendor=$(lsblk -ldno VENDOR "$targetDevice" 2>/dev/null)
1380+
_vendor=$(lsblk -ldno VENDOR "$targetDevice" 2> /dev/null)
14001381
_vendor=${_vendor:-FLASH}
14011382
targetPartitionLabel=${targetPartitionLabel:-"${_user^^}_${_vendor^^}"}
14021383
else
@@ -1549,7 +1530,7 @@ function devi_partitionUSB() {
15491530
# unmount any partition on selected device
15501531
mapfile -t devicePartitions < <(grep -oP "^\\K$targetDevice\\S*" /proc/mounts)
15511532
for _partition in "${devicePartitions[@]}"; do
1552-
if ! umount "$_partition" >/dev/null; then
1533+
if ! umount "$_partition" > /dev/null; then
15531534
ps_failAndExit IO_ERROR \
15541535
"Failed to unmount $_partition. It's likely that the partition is busy."
15551536
fi
@@ -1558,7 +1539,7 @@ function devi_partitionUSB() {
15581539
function _eraseDevice() {
15591540
term_echoinfo "Erasing contents of '$targetDevice'..."
15601541
# clean signature from selected device
1561-
wipefs --all --force "$targetDevice" &>/dev/null
1542+
wipefs --all --force "$targetDevice" &> /dev/null
15621543
# erase drive
15631544
dd if=/dev/zero of="$targetDevice" bs=512 count=1 conv=notrunc status=none |&
15641545
term_indentAll ||
@@ -1792,10 +1773,8 @@ function devi_inspectHybridImage() {
17921773
_supportsEFIBoot=false
17931774
fi
17941775
}
1795-
_diskReport=$(sfdisk -lJ -- "$sourceImageFile" 2>/dev/null)
1796-
if (($? != 0)); then
1797-
ps_failAndExit IO_ERROR "sfdisk couldn't read the partition table on the image file, which is likely corrupted."
1798-
fi
1776+
_diskReport=$(sfdisk -lJ -- "$sourceImageFile" 2> /dev/null) \
1777+
|| ps_failAndExit IO_ERROR "sfdisk couldn't read the partition table on the image file, which is likely corrupted."
17991778
_partScheme=$(echo "$_diskReport" | jq -r '.partitiontable.label')
18001779
case $_partScheme in
18011780
dos) _inspectMBRPartTable ;;
@@ -1926,7 +1905,7 @@ function step_installBootloader() {
19261905
fi
19271906
fi
19281907
term_echoinfo "Found local SYSLINUX version '$_localSyslinuxVersion'"
1929-
sh_compute "$_localSyslinuxVersion == ${st_isoInspections[syslinuxVer]}" >/dev/null
1908+
sh_compute "$_localSyslinuxVersion == ${st_isoInspections[syslinuxVer]}" > /dev/null
19301909
_versionsMatch=$?
19311910
if ((_versionsMatch == 0)); then
19321911
term_echogood "image SYSLINUX version matches local version."
@@ -1972,7 +1951,7 @@ function step_installBootloader() {
19721951
function _installWtKernelOrgExtlinux() {
19731952
local _isExt32 _isHost32 _fallbackToLocal=false
19741953
term_echoinfo "Installing SYSLINUX bootloader in '$_syslinuxFolder' with kernel.org version '$st_targetSyslinuxVersion'..."
1975-
file -b -- "${st_syslinuxBinaries['extBin']}" | awk '{print $2}' | grep -e '^32' &>/dev/null
1954+
file -b -- "${st_syslinuxBinaries['extBin']}" | awk '{print $2}' | grep -e '^32' &> /dev/null
19761955
_isExt32=$?
19771956
echo "$ct_architecture" | grep -e '32|i386'
19781957
_isHost32=$?
@@ -1996,7 +1975,7 @@ function step_installBootloader() {
19961975
fi
19971976
fi
19981977
if [[ "$_fallbackToLocal" == true ]]; then
1999-
_installWtLocalExtlinux >/dev/null
1978+
_installWtLocalExtlinux > /dev/null
20001979
fi
20011980
fs_syncdev
20021981
}
@@ -2036,7 +2015,7 @@ function step_copyWithRsync() {
20362015
term_echowarn "Detected a Windows install.wim file but wimsplit has been disabled with $(term_boldify '--no-wim-split') option."
20372016
fi
20382017
fi
2039-
(
2018+
(
20402019
# shellcheck disable=SC2086
20412020
rsync -r -q -I --no-links --no-perms --no-owner --no-group $_rsyncOptions "$st_elToritoMountPoint"/. "$st_usbMountPoint"
20422021
_status=$?
@@ -2045,7 +2024,7 @@ function step_copyWithRsync() {
20452024
echo
20462025
wimlib-imagex split "$_wimFile" "$st_usbMountPoint/sources/install.swm" 1024 |& term_indentAll
20472026
fi
2048-
echo "$_status" >"$_statusFile"
2027+
echo "$_status" > "$_statusFile"
20492028
) &
20502029
st_backgroundProcess=$!
20512030
echo -n "$scriptName: Copying files from image to USB device with 'rsync' "
@@ -2071,9 +2050,9 @@ function step_copyWithDD() {
20712050
local _status
20722051
_statusFile=$(fs_createTempFile "bootiso-status")
20732052
st_temporaryAssets+=("$_statusFile")
2074-
(
2053+
(
20752054
dd if="$sourceImageFile" of="$targetDevice" bs="$targetDDBusSize" status=none
2076-
echo "$?" >"$_statusFile"
2055+
echo "$?" > "$_statusFile"
20772056
) &
20782057
st_backgroundProcess=$!
20792058
echo -n "$scriptName: Copying files from image to USB device with 'dd' "

0 commit comments

Comments
 (0)