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

Commit 82ce6be

Browse files
committed
v2.5.0
1 parent 5a911f5 commit 82ce6be

File tree

3 files changed

+72
-25
lines changed

3 files changed

+72
-25
lines changed

bootiso

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Author: jules randolph <[email protected]> https://github.com/jsamr
44
# License: MIT
5-
# Version 2.4.2
5+
# Version 2.5.0
66
#
77
# Usage: [<options>...] <file.iso>
88
#
@@ -22,6 +22,7 @@
2222
# Enabled by default when neither -d nor --no-usb-check options are given.
2323
# -J, --no-eject Do not eject device after unmounting.
2424
# -l, --list-usb-drives List available USB drives and exit.
25+
# -s, --strict-mime-check Disallow loose application/octet-stream mime type in ISO file.
2526
# -- POSIX end of options.
2627
# --dd Use dd utility and create an iso9660 fs instead of mounting + rsync.
2728
# Does not allow bootloader installation with syslinux.
@@ -53,8 +54,9 @@ if [ -z "$BASH_VERSION" ] || [ "$bashVersion" -lt 4 ]; then
5354
exit 1
5455
fi
5556

56-
typeset commandDependencies=('lsblk' 'sfdisk' 'mkfs' 'blkid' 'wipefs' 'grep' 'file' 'awk' 'mlabel')
57+
typeset -a commandDependencies=('lsblk' 'sfdisk' 'mkfs' 'blkid' 'wipefs' 'grep' 'file' 'awk' 'mlabel')
5758
typeset -A commandPackages=([lsblk]='util-linux' [sfdisk]='util-linux' [mkfs]='util-linux' [blkid]='util-linux' [wipefs]='util-linux' [grep]='grep' [file]='file' [awk]='gawk' [mlabel]='mtools' [syslinux]='syslinux' [rsync]='rsync')
59+
typeset shortOptions='bydJahls'
5860

5961
typeset selectedDevice
6062
typeset selectedPartition
@@ -78,8 +80,9 @@ typeset shouldMakeFAT32Partition=true
7880
typeset ejectDevice=true
7981
typeset autoselect=false
8082
typeset isEndOfOptions=false
83+
typeset strictMimeCheck=false
8184

82-
typeset version="2.4.2"
85+
typeset version="2.5.0"
8386
typeset help_message="\
8487
Usage: $scriptName [<options>...] <file.iso>
8588
@@ -105,6 +108,7 @@ Options
105108
Enabled by default when neither -d nor --no-usb-check options are given.
106109
-J, --no-eject Do not eject device after unmounting.
107110
-l, --list-usb-drives List available USB drives.
111+
-s, --strict-mime-check Disallow loose application/octet-stream mime type in ISO file.
108112
-- POSIX end of options.
109113
--dd Use \`dd' utility instead of mounting + \`rsync'.
110114
Does not allow bootloader installation with syslinux.
@@ -180,16 +184,34 @@ checkSudo() {
180184
fi
181185
}
182186

187+
failISOCheck() {
188+
echoerr "Provided file \`$selectedIsoFile' doesn't seem to be an ISO file (wrong mime type: \`$mimetype')."
189+
echowarn "Try it with \`--no-mime-check' option."
190+
echoerr "Exiting $scriptName..."
191+
exit 1
192+
}
193+
183194
assertISOMimeType() {
184195
typeset mimetype=$(file --mime-type -b -- "$selectedIsoFile")
196+
typeset -i isOctetStream
185197
if [ "$disableMimeCheck" == 'true' ]; then
186-
echowarn "Mime check has been disabled. Skipping."
198+
echowarn "Mime check has been disabled with \`--no-mime-check'. Skipping."
187199
return 0
188200
fi
189-
if [ ! "$mimetype" == "application/x-iso9660-image" ]; then
190-
failAndExit "Provided file \`$selectedIsoFile' doesn't seem to be an ISO file (wrong mime type: \`$mimetype').\\nTry it with \`--no-mime-check' option."
201+
[ "$mimetype" == "application/octet-stream" ]
202+
isOctetStream=$?
203+
if [ "$strictMimeCheck" == 'true' ] && ((isOctetStream == 0)); then
204+
failISOCheck
205+
fi
206+
if ((isOctetStream != 0)) && [ ! "$mimetype" == "application/x-iso9660-image" ]; then
207+
failISOCheck
208+
fi
209+
if ((isOctetStream == 0)); then
210+
echowarn "Provided file \`$selectedIsoFile' seems to have a loose mime-type \`application/octet-stream'."
211+
echowarn "It's possible that it is corrupted and you should control its integrity with a checksum tool."
212+
else
213+
echogood "The selected ISO file has the right \`application/x-iso9660-image' mime type."
191214
fi
192-
echogood "The selected ISO file has the right mime type."
193215
# Label is set to uppercase because FAT32 labels should be
194216
isoLabel=$(blkid -o value -s LABEL -- "$selectedIsoFile" | awk '{print toupper($0)}')
195217
}
@@ -274,6 +296,22 @@ parseOptions() {
274296
autoselect=true
275297
shift
276298
;;
299+
-h|--help|help)
300+
display_help
301+
exit 0
302+
;;
303+
-l|--list-usb-drives)
304+
listDevicesTable
305+
exit 0
306+
;;
307+
-v|--version)
308+
echo "$version"
309+
exit 0
310+
;;
311+
-s|--strict-mime-check)
312+
strictMimeCheck=true
313+
shift
314+
;;
277315
--dd)
278316
useDD=true
279317
shouldMakeFAT32Partition=false
@@ -287,36 +325,32 @@ parseOptions() {
287325
disableUSBCheck=true
288326
shift
289327
;;
290-
-h|--help|help)
291-
display_help
292-
exit 0
293-
;;
294-
-l|--list-usb-drives)
295-
listDevicesTable
296-
exit 0
297-
;;
298-
-v|--version)
299-
echo "$version"
300-
exit 0
301-
;;
302328
--)
303329
isEndOfOptions=true
304330
shift
305331
;;
306332
-*)
307333
if [ ! -f "$key" ]; then
308-
if [[ "$key" =~ ^-[A-Za-z0-9]{2,}$ ]]; then
334+
if [[ "$key" =~ ^-["$shortOptions"]{2,}$ ]]; then
309335
shift
310336
typeset options=${key#*-}
311337
typeset -a extractedOptions
312338
mapfile -t extractedOptions < <(echo "$options" | grep -o . | xargs -d '\n' -n1 printf '-%s\n')
313339
set -- "${extractedOptions[@]}" "$@"
314340
else
315-
echoerr "Unknown option \`$key'."
341+
printf '\e[0;31m%s\e[m' "Unknown option: "
342+
printf '%s' "$key" | GREP_COLORS='mt=00;32:sl=00;31' grep --color=always -P "[$shortOptions]"
343+
if [[ "$key" =~ ^-[a-zA-Z0-9]+$ ]]; then
344+
typeset wrongOptions=$(printf '%s' "${key#*-}" | grep -Po "[^$shortOptions]" | tr -d '\n')
345+
echowarn "Unknown stacked flag(s): \\033[0;31m\`$wrongOptions'\\033[0m."
346+
fi
347+
echoerr "Exiting $scriptName..."
316348
exit 2
317349
fi
350+
else
351+
selectedIsoFile=$1
352+
shift
318353
fi
319-
selectedIsoFile=$1
320354
;;
321355
*)
322356
selectedIsoFile=$1
@@ -414,7 +448,10 @@ selectDevice() {
414448
if listDevicesTable; then
415449
handleDeviceSelection
416450
else
417-
failAndExit "There is no USB drive connected to your system.\\nUse --no-usb-check to bypass this detection at your own risk, or replug an plugged device which is likely ejected."
451+
echoerr "There is no USB drive connected to your system."
452+
echowarn "Use \`--no-usb-check' to bypass this detection at your own risk, or replug an plugged device which is likely ejected."
453+
echoerr "Exiting $scriptName..."
454+
exit 1
418455
fi
419456
fi
420457
selectedPartition="${selectedDevice}1"
@@ -440,7 +477,10 @@ assertDeviceIsUSB() {
440477
fi
441478
deviceType=$(getDeviceType "$selectedDevice")
442479
if [ "$deviceType" != "usb" ] ; then
443-
failAndExit "The device you selected is not connected through USB (found BUS: \`$deviceType').\\nUse \`--no-usb-check' option to bypass this limitation at your own risks."
480+
echoerr "The device you selected is not connected through USB (found BUS: \`$deviceType')."
481+
echowarn "Use \`--no-usb-check' option to bypass this limitation at your own risks."
482+
echoerr "Exiting $scriptName..."
483+
exit 1
444484
fi
445485
echogood "The selected device \`$selectedDevice' is connected through USB."
446486
}

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v2.5.0
2+
3+
- allow loose `application/octet-stream` mime type by default in ISO files
4+
- add `-s`, `--strict-mime-check` option to disallow loose `application/octet-stream` mime type in ISO files
5+
- fix bug #3: Provided file argument starting with -- cause bootiso to hang
6+
- better handling of erroneous stacked short options
7+
18
# v2.4.2
29

310
- better feedback when mime type check fails

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
2-
[![v2.4.2](https://img.shields.io/badge/version-v2.4.2-green.svg)](#)
2+
[![v2.5.0](https://img.shields.io/badge/version-v2.5.0-green.svg)](#)
33
[![GitHub issues open](https://img.shields.io/github/issues/jsamr/bootiso.svg?maxAge=2592000)](https://github.com/jsamr/bootiso/issues)
44
[![Build Status](https://travis-ci.org/jsamr/bootiso.svg?branch=master)](https://travis-ci.org/jsamr/bootiso)
55

0 commit comments

Comments
 (0)