@@ -32,7 +32,7 @@ set -euf -o pipefail
32
32
SUDO=' '
33
33
if [[ $( id -u) -ne 0 ]]; then
34
34
# verify that 'sudo' is present before assuming we can use it
35
- if [[ ! -x $( which sudo 2> /dev/null) ]] ; then
35
+ if ! hash sudo 2> /dev/null; then
36
36
echo " [-] Dependencies unmet. Please verify that 'sudo' is installed, executable, and in the PATH." >&2
37
37
echo " Alternatively, you may also re-run this script as root." >&2
38
38
exit 1
@@ -256,7 +256,7 @@ while getopts ":b:fp:w:vh" opt; do
256
256
exit 1
257
257
fi
258
258
if [[ " $WIPE_METHOD " = " scrub" ]]; then
259
- if [[ ! -x $( which scrub 2> /dev/null) ]] ; then
259
+ if ! hash scrub 2> /dev/null; then
260
260
echo " [-] Dependencies unmet. Please verify that the following are installed, executable, and in the PATH: scrub" >&2
261
261
exit 1
262
262
fi
@@ -348,7 +348,7 @@ if [[ "$PARENT_DEVICE" != "$DEVICE" ]]; then
348
348
echo " You are attempting to format a single partition (as opposed to entire device)."
349
349
echo " For maximal compatibility, the recommendation is to format the entire device."
350
350
echo " If you continue, the resultant UDF partition will not be recognized on macOS."
351
-
351
+
352
352
if [[ -z $FORCE ]]; then
353
353
read -rp " Type 'yes' if you would like to continue anyway: " YES_CASE
354
354
YES=$( echo " $YES_CASE " | tr ' [:upper:]' ' [:lower:]' )
364
364
# ##############################################################################
365
365
366
366
echo " [+] Testing dependencies..."
367
- if [[ ! -x $( which cat 2> /dev/null) ]] ||
368
- [[ ! -x $( which grep 2> /dev/null) ]] ||
369
- [[ ! -x $( which mount 2> /dev/null) ]] ||
370
- [[ ! -x $( which test 2> /dev/null) ]] ||
371
- [[ ! -x $( which true 2> /dev/null) ]] ||
372
- [[ ! -x $( which false 2> /dev/null) ]] ||
373
- [[ ! -x $( which awk 2> /dev/null) ]] ||
374
- [[ ! -x $( which printf 2> /dev/null) ]] ||
375
- [[ ! -x $( which sed 2> /dev/null) ]] ||
376
- [[ ! -x $( which tr 2> /dev/null) ]] ||
377
- [[ ! -x $( which dd 2> /dev/null) ]] ||
378
- [[ ! -x $( which xxd 2> /dev/null) ]] ; then
367
+ if ! hash cat 2> /dev/null ||
368
+ ! hash grep 2> /dev/null ||
369
+ ! hash mount 2> /dev/null ||
370
+ ! hash test 2> /dev/null ||
371
+ ! hash true 2> /dev/null ||
372
+ ! hash false 2> /dev/null ||
373
+ ! hash awk 2> /dev/null ||
374
+ ! hash printf 2> /dev/null ||
375
+ ! hash sed 2> /dev/null ||
376
+ ! hash tr 2> /dev/null ||
377
+ ! hash dd 2> /dev/null ||
378
+ ! hash xxd 2> /dev/null; then
379
379
echo " [-] Dependencies unmet. Please verify that the following are installed, executable, and in the PATH: cat, grep, mount, test, true, false, awk, printf, sed, tr, dd, xxd" >&2
380
380
exit 1
381
381
fi
384
384
# ensure have required drive info tool
385
385
echo -n " [+] Looking for drive info tool..."
386
386
# `true` is so that a failure here doesn't cause entire script to exit prematurely
387
- TOOL_BLOCKDEV=$( $SUDO which blockdev 2> /dev/null) || true
387
+ TOOL_BLOCKDEV=$( command -v blockdev 2> /dev/null) || true
388
388
# `true` is so that a failure here doesn't cause entire script to exit prematurely
389
- TOOL_IOREG=$( which ioreg 2> /dev/null) || true
389
+ TOOL_IOREG=$( command -v ioreg 2> /dev/null) || true
390
390
if [[ -x " $TOOL_BLOCKDEV " ]]; then
391
391
TOOL_DRIVE_INFO=$TOOL_BLOCKDEV
392
392
elif [[ -x " $TOOL_IOREG " ]]; then
@@ -402,9 +402,9 @@ echo " using $TOOL_DRIVE_INFO"
402
402
# ensure have required drive listing tool
403
403
echo -n " [+] Looking for drive listing tool..."
404
404
# `true` is so that a failure here doesn't cause entire script to exit prematurely
405
- TOOL_BLOCKDEV=$( $SUDO which blockdev 2> /dev/null) || true
405
+ TOOL_BLOCKDEV=$( command -v blockdev 2> /dev/null) || true
406
406
# `true` is so that a failure here doesn't cause entire script to exit prematurely
407
- TOOL_DISKUTIL=$( which diskutil 2> /dev/null) || true
407
+ TOOL_DISKUTIL=$( command -v diskutil 2> /dev/null) || true
408
408
if [[ -x " $TOOL_BLOCKDEV " ]]; then
409
409
TOOL_DRIVE_LISTING=$TOOL_BLOCKDEV
410
410
elif [[ -x " $TOOL_DISKUTIL " ]]; then
@@ -420,7 +420,7 @@ echo " using $TOOL_DRIVE_LISTING"
420
420
# ensure have required drive summary tool
421
421
echo -n " [+] Looking for drive summary tool..."
422
422
# `true` is so that a failure here doesn't cause entire script to exit prematurely
423
- TOOL_BLKID=$( $SUDO which blkid 2> /dev/null) || true
423
+ TOOL_BLKID=$( command -v blkid 2> /dev/null) || true
424
424
if [[ -x " $TOOL_BLKID " ]]; then
425
425
TOOL_DRIVE_SUMMARY=$TOOL_BLKID
426
426
echo " using $TOOL_DRIVE_SUMMARY "
433
433
# ensure have required unmount tool
434
434
echo -n " [+] Looking for unmount tool..."
435
435
# `true` is so that a failure here doesn't cause entire script to exit prematurely
436
- TOOL_UMOUNT=$( $SUDO which umount 2> /dev/null) || true
436
+ TOOL_UMOUNT=$( command -v umount 2> /dev/null) || true
437
437
# `true` is so that a failure here doesn't cause entire script to exit prematurely
438
- TOOL_DISKUTIL=$( $SUDO which diskutil 2> /dev/null) || true
438
+ TOOL_DISKUTIL=$( command -v diskutil 2> /dev/null) || true
439
439
# prefer 'diskutil' if available, as it's required on macOS (even if 'umount' is present)
440
440
if [[ -x " $TOOL_DISKUTIL " ]]; then
441
441
TOOL_UNMOUNT=$TOOL_DISKUTIL
@@ -452,9 +452,9 @@ echo " using $TOOL_UNMOUNT"
452
452
# ensure have required UDF tool
453
453
echo -n " [+] Looking for UDF tool..."
454
454
# `true` is so that a failure here doesn't cause entire script to exit prematurely
455
- TOOL_MKUDFFS=$( $SUDO which mkudffs 2> /dev/null) || true
455
+ TOOL_MKUDFFS=$( command -v mkudffs 2> /dev/null) || true
456
456
# `true` is so that a failure here doesn't cause entire script to exit prematurely
457
- TOOL_NEWFS_UDF=$( $SUDO which newfs_udf 2> /dev/null) || true
457
+ TOOL_NEWFS_UDF=$( command -v newfs_udf 2> /dev/null) || true
458
458
if [[ -x " $TOOL_MKUDFFS " ]]; then
459
459
TOOL_UDF=$TOOL_MKUDFFS
460
460
elif [[ -x " $TOOL_NEWFS_UDF " ]]; then
@@ -525,14 +525,14 @@ if [[ -n $PHYSICAL_BLOCK_SIZE ]]; then
525
525
echo " of $LOGICAL_BLOCK_SIZE bytes and physical block size of $PHYSICAL_BLOCK_SIZE bytes."
526
526
if [[ $LOGICAL_BLOCK_SIZE -eq 512 ]] && [[ $PHYSICAL_BLOCK_SIZE -eq 4096 ]]; then
527
527
echo " This device is an '512 emulation' (512e) drive."
528
- elif [[ $LOGICAL_BLOCK_SIZE -eq 4096 ]] && [[ $PHYSICAL_BLOCK_SIZE -eq 4096 ]]; then
528
+ elif [[ $LOGICAL_BLOCK_SIZE -eq 4096 ]] && [[ $PHYSICAL_BLOCK_SIZE -eq 4096 ]]; then
529
529
echo " This device is an '4K native' (4Kn) drive."
530
530
fi
531
531
echo " As such, this drive will not be as compatible across operating systems as a standard"
532
532
echo " drive having a logical block size of 512 bytes and a physical block size of 512 bytes."
533
533
echo " For example, this drive will not be usable for read or write on Windows XP."
534
534
echo " Please see the format-udf README for more information/limitations."
535
-
535
+
536
536
if [[ -z $FORCE ]]; then
537
537
read -rp " Type 'yes' if you would like to continue anyway: " YES_CASE
538
538
YES=$( echo " $YES_CASE " | tr ' [:upper:]' ' [:lower:]' )
@@ -593,7 +593,7 @@ if [[ $((TOTAL_SIZE/LOGICAL_BLOCK_SIZE)) -ge $(((2**32)-1)) ]]; then
593
593
echo " and the remainder of the drive will not be used."
594
594
echo " The maximum UDF file system capacity on this device is $(( LOGICAL_BLOCK_SIZE/ 256 )) TiB."
595
595
echo " Please see the format-udf README for more information."
596
-
596
+
597
597
if [[ -z $FORCE ]]; then
598
598
read -rp " Type 'yes' if you would like to continue anyway: " YES_CASE
599
599
YES=$( echo " $YES_CASE " | tr ' [:upper:]' ' [:lower:]' )
622
622
623
623
if [[ -z $FORCE ]]; then
624
624
echo " The above-listed device (and partitions, if any) will be completely erased."
625
-
625
+
626
626
read -rp " Type 'yes' if this is what you intend: " YES_CASE
627
627
YES=$( echo " $YES_CASE " | tr ' [:upper:]' ' [:lower:]' )
628
628
if [[ $YES != " yes" ]]; then
0 commit comments