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

Commit

Permalink
v3.1.2, fix #21
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Jul 26, 2018
1 parent ef0929c commit f288817
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
50 changes: 38 additions & 12 deletions bootiso
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#
# Author: jules randolph <jules.sam.randolph@gmail.com> https://github.com/jsamr
# License: MIT
# Version 3.1.1
# Version 3.1.2

set -o pipefail
set -E

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

Expand All @@ -17,7 +18,7 @@ if [ -z "$BASH_VERSION" ] || [ "$bashVersion" -lt 4 ]; then
fi

# program constrains definitions
typeset -ar commandDependencies=('lsblk' 'sfdisk' 'mkfs' 'blkid' 'wipefs' 'grep' 'file' 'awk' 'mlabel' 'partprobe')
typeset -ar commandDependencies=('lsblk' 'sfdisk' 'mkfs' 'blkid' 'wipefs' 'grep' 'file' 'awk' 'mlabel' 'partprobe' 'tar')
typeset -Ar commandPackages=(
['lsblk']='util-linux'
['sfdisk']='util-linux'
Expand All @@ -32,6 +33,7 @@ typeset -Ar commandPackages=(
['rsync']='rsync'
['partprobe']='parted'
['curl']='curl'
['tar']='tar'
)
typeset shortOptions='bydJahlMftLp'
typeset -ar supportedFS=('vfat' 'exfat' 'ntfs' 'ext2' 'ext3' 'ext4' 'f2fs')
Expand All @@ -52,7 +54,6 @@ typeset -Ar userFlagsCompatibilityMatrix=(
)

# internal variables
typeset version="3.1.1"
typeset ticketsurl="https://github.com/jsamr/bootiso/issues"
typeset mountRoot=/mnt
typeset tempRoot=/var/tmp/bootiso
Expand All @@ -67,6 +68,8 @@ typeset syslinuxVersion
typeset -a devicesList
typeset operationSuccess
typeset expectingISOFile
typeset foundSyslinuxMbrBinary
typeset foundSyslinuxBiosFolder
typeset -A syslinuxInstall
typeset -a temporaryAssets=()
typeset -A isoInspection=(
Expand Down Expand Up @@ -381,7 +384,7 @@ assertISOIsOK() {
}

firstMatchInFolder() {
find "$1" -type f -iname "$2" | head -n1 | awk '{print $1;}'
find "$1" -type f -iname "$2" -print -quit
}

matchFirstExpression() {
Expand Down Expand Up @@ -411,7 +414,7 @@ findFileFromPatterns() {
done
if [ -z "$found" ]; then
for loc in "$@"; do
typeset candidate=$(find "$root" -type f -wholename "*/$loc")
typeset candidate=$(find "$root" -type f -path "*/$loc" -print -quit)
if [ ! -z "$candidate" ]; then
found="$candidate"
break
Expand Down Expand Up @@ -466,7 +469,13 @@ checkpkg() {
echo
case $answer in
y | Y)
$pkgmgr "${commandPackages["$1"]}"
if ! $pkgmgr "${commandPackages["$1"]}"; then
failAndExit "Installation of dependency \`$1' failed.\\nPerhaps this dependency has a slightly different name in your distribution.\\nFind it and install manually."
else
if ! hasPackage "$1"; then
failAndExit "Program \`$1' is not accessible in the \$PATH environment even though the package ${commandPackages["$1"]} has just been installed."
fi
fi
;;
*)
failAndExit "Missing dependency \`$1'."
Expand Down Expand Up @@ -508,7 +517,7 @@ initDevicesList() {
}

listDevicesTable() {
typeset lsblkCmd='lsblk -o NAME,MODEL,VENDOR,SIZE,TRAN,HOTPLUG'
typeset lsblkCmd='lsblk -o NAME,MODEL,VENDOR,SIZE,TRAN,HOTPLUG,SERIAL'
initDevicesList
if [ "$disableUSBCheck" == 'false' ]; then
echoinfo "Listing drives available in your system:"
Expand Down Expand Up @@ -1081,6 +1090,7 @@ installSyslinuxVersion() {
fi
syslinuxInstall['mbrBin']="$mbrBin"
syslinuxInstall['extBin']="$extlinuxBin"
ls -l "$extlinuxBin" # TODO DELETE
return 0
}
checkpkg 'curl'
Expand Down Expand Up @@ -1161,17 +1171,18 @@ installBootloader() {
syslinuxFolder=$(dirname "$syslinuxConfig")
}
installWtLocalExtlinux() {
syslinuxInstall=(['mbrBin']=/usr/lib/syslinux/bios/mbr.bin ['extBin']='extlinux')
syslinuxInstall=(['mbrBin']="$foundSyslinuxMbrBinary" ['extBin']='extlinux')
syslinuxVersion="$localSyslinuxVersion"
echoinfo "Installing SYSLINUX bootloader in \`$syslinuxFolder' with local version \`$syslinuxVersion'..."
rsync --no-links --no-perms --no-owner --no-group -I /usr/lib/syslinux/bios/*.c32 "$syslinuxFolder" |& indentAll || echowarn "SYSLINUX could not install C32 BIOS modules."
rsync --no-links --no-perms --no-owner --no-group -I "$foundSyslinuxBiosFolder"/*.c32 "$syslinuxFolder" |& indentAll || echowarn "SYSLINUX could not install C32 BIOS modules."
sync
echogood "C32 BIOS modules successfully installed."
${syslinuxInstall['extBin']} --stupid --install "$syslinuxFolder" |& indentAll || failAndExit "SYSLINUX bootloader could not be installed."
sync
}
installWtKernelOrgExtlinux() {
echoinfo "Installing SYSLINUX bootloader in \`$syslinuxFolder' with kernel.org version \`$syslinuxVersion'..."
ls -l "${syslinuxInstall['extBin']}" # TODO DELETE
if ! ${syslinuxInstall['extBin']} --stupid --install "$syslinuxFolder" |& indentAll; then
echowarn "kernel.org version \`$syslinuxVersion' could not be run.\\nAttempting with local SYSLINUX install..."
installWtLocalExtlinux >/dev/null
Expand Down Expand Up @@ -1418,8 +1429,8 @@ inspectISO() {
fi
}
inspectEFICapabilities() {
typeset hasEfiRoot=$(find "$isoMountPoint" -type d -iname 'efi')
typeset hasEfiFile=$(find "$isoMountPoint" -type f -ipath '*/efi/*.efi' -prune)
typeset hasEfiRoot=$(find "$isoMountPoint" -type d -iname 'efi' -print -quit)
typeset hasEfiFile=$(find "$isoMountPoint" -type f -ipath '*/efi/*.efi' -prune -print -quit)
supportsEFIBoot=false
if [ ! -z "$hasEfiFile" ] && [ ! -z "$hasEfiRoot" ]; then
supportsEFIBoot=true
Expand Down Expand Up @@ -1466,6 +1477,21 @@ inspectISOBootCapabilities() {
fi
}

checkSyslinuxInstall() {
checkpkg 'syslinux'
if ! command -v extlinux > /dev/null; then
failAndExit "Your distribution doesn't ship \`extlinux' binary with \`syslinux' package.\\nPlease install \`extlinux' and try again."
fi
foundSyslinuxBiosFolder=$(find /usr/lib/syslinux/ -type d -path '*/bios' -print -quit)
foundSyslinuxMbrBinary=$(findFileFromPatterns /usr/lib/syslinux 'bios/mbr.bin' 'mbr.bin')
if [ -z "$foundSyslinuxBiosFolder" ]; then
failAndExit "Could not find a SYSLINUX bios folder containing c32 bios module files on this system."
fi
if [ -z "$foundSyslinuxMbrBinary" ]; then
failAndExit "Could not find a SYSLINUX MBR binary file on this system."
fi
}

printISOBootCapabilities() {
typeset uefiCompatible=${isoInspection['supportsEFIBoot']}
typeset syslinuxCompatible=false
Expand Down Expand Up @@ -1514,14 +1540,14 @@ execProbe() {

execWithRsync() {
shouldMakePartition=true
checkSyslinuxInstall
inspectISOBootCapabilities
runSecurityAssessments
mountISOFile
partitionUSB false
mountUSB
copyWithRsync
if [ "$addSyslinuxBootloader" == 'true' ]; then
checkpkg 'syslinux'
installBootloader
fi
}
Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v3.1.2

- improved robustness of `checkpkg` function
- fix issue with SYSLINUX and EXTLINUX on Ubuntu and debian-based distros #21
- replaced `find` arguments `-wholename` with `-path` which is more portable
- systematic usage the `-print -quit` pattern with `find` command when possible
- add explicit dependency to `tar`

# v3.1.1

- add compatibility code for `sfdisk` versions older then 2.28 which don't support `-W` option
Expand Down

0 comments on commit f288817

Please sign in to comment.