Skip to content

Commit 5b1108d

Browse files
authored
fix: Avoid pipe to head on find (#313)
1 parent a74690d commit 5b1108d

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/define.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ addFolder() {
768768
cp -Lr "$folder/." "$dest" || return 1
769769

770770
local file
771-
file=$(find "$dest" -maxdepth 1 -type f -iname install.bat | head -n 1)
771+
file=$(find "$dest" -maxdepth 1 -type f -iname install.bat -print -quit)
772772
[ -f "$file" ] && unix2dos -q "$file"
773773

774774
return 0

src/install.sh

+14-15
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ abortInstall() {
201201
[[ "${iso,,}" == *".esd" ]] && exit 60
202202
[[ "${UNPACK:-}" == [Yy1]* ]] && exit 60
203203

204-
efi=$(find "$dir" -maxdepth 1 -type d -iname efi | head -n 1)
204+
efi=$(find "$dir" -maxdepth 1 -type d -iname efi -print -quit)
205205

206206
if [ -z "$efi" ]; then
207207
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
@@ -230,17 +230,17 @@ detectCustom() {
230230

231231
CUSTOM=""
232232

233-
dir=$(find / -maxdepth 1 -type d -iname "$fname" | head -n 1)
234-
[ ! -d "$dir" ] && dir=$(find "$STORAGE" -maxdepth 1 -type d -iname "$fname" | head -n 1)
233+
dir=$(find / -maxdepth 1 -type d -iname "$fname" -print -quit)
234+
[ ! -d "$dir" ] && dir=$(find "$STORAGE" -maxdepth 1 -type d -iname "$fname" -print -quit)
235235

236236
if [ -d "$dir" ]; then
237237
if ! hasDisk || [ ! -f "$boot" ]; then
238238
error "The bind $dir maps to a file that does not exist!" && return 1
239239
fi
240240
fi
241241

242-
file=$(find / -maxdepth 1 -type f -iname "$fname" | head -n 1)
243-
[ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$fname" | head -n 1)
242+
file=$(find / -maxdepth 1 -type f -iname "$fname" -print -quit)
243+
[ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$fname" -print -quit)
244244

245245
if [ ! -s "$file" ] && [[ "${VERSION,,}" != "http"* ]]; then
246246
base=$(basename "$VERSION")
@@ -396,7 +396,7 @@ extractImage() {
396396

397397
else
398398

399-
file=$(find "$dir" -maxdepth 1 -type f -iname "*.iso" | head -n 1)
399+
file=$(find "$dir" -maxdepth 1 -type f -iname "*.iso" -print -quit)
400400

401401
if [ -z "$file" ]; then
402402
error "Failed to find any .iso file in archive!" && return 1
@@ -591,14 +591,14 @@ detectImage() {
591591
fi
592592

593593
local src wim info
594-
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
594+
src=$(find "$dir" -maxdepth 1 -type d -iname sources -print -quit)
595595

596596
if [ ! -d "$src" ]; then
597597
warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
598598
fi
599599

600-
wim=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1)
601-
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)
600+
wim=$(find "$src" -maxdepth 1 -type f -iname install.wim -print -quit)
601+
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname install.esd -print -quit)
602602

603603
if [ ! -f "$wim" ]; then
604604
warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1
@@ -723,8 +723,7 @@ updateXML() {
723723
sed -i "s/<Username>Docker<\/Username>/<Username>$user<\/Username>/g" "$asset"
724724
fi
725725

726-
[ -n "$PASSWORD" ] && pass="$PASSWORD" || pass=""
727-
[ -z "$pass" ] && pass="admin"
726+
[ -n "$PASSWORD" ] && pass="$PASSWORD" || pass="admin"
728727

729728
pw=$(printf '%s' "${pass}Password" | iconv -f utf-8 -t utf-16le | base64 -w 0)
730729
admin=$(printf '%s' "${pass}AdministratorPassword" | iconv -f utf-8 -t utf-16le | base64 -w 0)
@@ -893,14 +892,14 @@ updateImage() {
893892
rm -rf "$tmp"
894893
mkdir -p "$tmp"
895894

896-
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
895+
src=$(find "$dir" -maxdepth 1 -type d -iname sources -print -quit)
897896

898897
if [ ! -d "$src" ]; then
899898
error "failed to locate 'sources' folder in ISO image, $FB" && return 1
900899
fi
901900

902-
wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1)
903-
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)
901+
wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim -print -quit)
902+
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname boot.esd -print -quit)
904903

905904
if [ ! -f "$wim" ]; then
906905
error "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1
@@ -963,7 +962,7 @@ updateImage() {
963962

964963
local find="$file"
965964
[[ "$MANUAL" == [Yy1]* ]] && find="$org"
966-
path=$(find "$dir" -maxdepth 1 -type f -iname "$find" | head -n 1)
965+
path=$(find "$dir" -maxdepth 1 -type f -iname "$find" -print -quit)
967966

968967
if [ -f "$path" ]; then
969968
if [[ "$MANUAL" != [Yy1]* ]]; then

0 commit comments

Comments
 (0)