Skip to content

Commit

Permalink
v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Apr 9, 2018
1 parent e599e3f commit 021acca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
60 changes: 35 additions & 25 deletions bootiso
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Author: jules randolph <[email protected]> https://github.com/jsamr
# License: MIT
# Version 2.2.3
# Version 2.3.0
#
# Usage: [<options>...] <file.iso>
#
Expand All @@ -21,6 +21,7 @@
# Autoselect will automatically select a USB drive device if there is exactly one connected to the system.
# Enabled by default when neither -d nor --no-usb-check options are given.
# -J, --no-eject Do not eject device after unmounting.
# -l, --list-usb-drives List available USB drives and exit.
# --dd Use dd utility and create an iso9660 fs instead of mounting + rsync.
# Does not allow bootloader installation with syslinux.
# --no-mime-check bootiso won't assert that selected ISO file has the right mime-type.
Expand Down Expand Up @@ -62,6 +63,7 @@ typeset isoMountPoint
typeset usbMountPoint
typeset startTime
typeset endTime
typeset -a devicesList

# options

Expand All @@ -74,7 +76,7 @@ typeset shouldMakeFAT32Partition=true
typeset ejectDevice=true
typeset autoselect=false

typeset version="2.2.3"
typeset version="2.3.0"
typeset help_message="\
Usage: $scriptName [<options>...] <file.iso>
Expand All @@ -99,6 +101,7 @@ Options
Autoselect will automatically select a USB drive device if there is exactly one connected to the system.
Enabled by default when neither -d nor --no-usb-check options are given.
-J, --no-eject Do not eject device after unmounting.
-l, --list-usb-drives List available USB drives.
--dd Use \`dd' utility instead of mounting + \`rsync'.
Does not allow bootloader installation with syslinux.
--no-mime-check \`$scriptName' won't assert that selected ISO file has the right mime-type.
Expand Down Expand Up @@ -204,6 +207,30 @@ checkpkg() {
fi
}

joinBy() { local IFS="$1"; shift; echo "$*"; }

initDevicesList() {
typeset -a devices
mapfile -t devices < <(lsblk -o NAME,TYPE | grep --color=never -oP '^\K\w+(?=\s+disk$)')
for device in "${devices[@]}" ; do
if [ "$(getDeviceType "/dev/$device")" == "usb" ] || [ "$disableUSBCheck" == 'true' ]; then
devicesList+=("$device")
fi
done
}

listDevicesTable() {
typeset lsblkCmd='lsblk -o NAME,HOTPLUG,SIZE,STATE,TYPE'
initDevicesList
if [ "$disableUSBCheck" == 'false' ]; then
echo "Listing USB drives available in your system:"
else
echo "Listing devices available in your system:"
fi
$lsblkCmd | sed -n 1p
$lsblkCmd | grep --color=never -P "^($(joinBy '|' "${devicesList[@]}"))"
}

parseOptions() {
typeset key
while [[ $# -gt 0 ]]; do
Expand Down Expand Up @@ -248,6 +275,11 @@ parseOptions() {
display_help
exit 0
;;
-l|--list-usb-drives)
listDevicesTable
exit 0
shift
;;
-v|--version)
echo "$version"
exit 0
Expand Down Expand Up @@ -311,28 +343,6 @@ deviceIsDisk() {

selectDevice() {
typeset _selectedDevice
typeset -a devicesList
joinBy() { local IFS="$1"; shift; echo "$*"; }
initDevicesList() {
typeset -a devices
mapfile -t devices < <(lsblk -o NAME,TYPE | grep --color=never -oP '^\K\w+(?=\s+disk$)')
for device in "${devices[@]}" ; do
if [ "$(getDeviceType "/dev/$device")" == "usb" ] || [ "$disableUSBCheck" == 'true' ]; then
devicesList+=("$device")
fi
done
}
listDevicesTable() {
typeset lsblkCmd='lsblk -o NAME,HOTPLUG,SIZE,STATE,TYPE'
initDevicesList
if [ "$disableUSBCheck" == 'false' ]; then
echo "Listing available USB drives in your system:"
else
echo "Listing available devices in your system:"
fi
$lsblkCmd | sed -n 1p
$lsblkCmd | grep --color=never -P "^($(joinBy '|' "${devicesList[@]}"))"
}
containsElement () {
local e match="$1"
shift
Expand All @@ -358,7 +368,7 @@ selectDevice() {
# autoselect
if [ "$disableConfirmation" == 'false' ] || ([ "$disableConfirmation" == 'true' ] && [ "$autoselect" == 'true' ]); then
typeset selected="${devicesList[0]}"
echogood "Autoselecting $selected (only USB device candidate)"
echogood "Autoselecting \`$selected' (only USB device candidate)"
selectedDevice="/dev/$selected"
else
chooseDevice
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v2.3.0

- add `-l`, `--list-usb-drives` option

# v2.2.3

- when prompting user to select device, list drives which are of type disk according to `lsblk` instead of using name matching to discard partition and loop devices
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![v2.2.2](https://img.shields.io/badge/version-v2.2.3-green.svg)](#)
[![v2.3.0](https://img.shields.io/badge/version-v2.3.0-green.svg)](#)
[![GitHub issues open](https://img.shields.io/github/issues/jsamr/bootiso.svg?maxAge=2592000)](https://github.com/jsamr/bootiso/issues)
[![Build Status](https://travis-ci.org/jsamr/bootiso.svg?branch=master)](https://travis-ci.org/jsamr/bootiso)

Expand Down Expand Up @@ -62,6 +62,7 @@ Where `bin-path` is any folder in the `$PATH` environment such as `$HOME/bin`.
| `-y` | `--assume-yes` | bootiso won't prompt the user for confirmation before erasing and partitioning USB device. Use at your own risks. |
| `-a` | `--autoselect` | Enable autoselecting USB devices in conjunction with `-y` option. Autoselect will automatically select a USB drive device if there is exactly one connected to the system. Enabled by default when neither `-d` nor `--no-usb-check` options are given. |
| `-J` | `--no-eject` | Do not eject device after unmounting. |
| `-l` | `--list-usb-drives` | List available USB drives. |
| | `--dd` | Use dd utility instead of mounting + rsync. Does not allow bootloader installation with syslinux. |
| | `--no-mime-check` | bootiso won't assert that selected ISO file has the right mime-type. |
| | `--no-usb-check` | bootiso won't assert that selected device is a USB (connected through USB bus). Use at your own risks. |
Expand Down

0 comments on commit 021acca

Please sign in to comment.