1
0
Эх сурвалжийг харах

fix: Avoid pipe to head on find (#1197)

Kroese 3 сар өмнө
parent
commit
67cd5db5bc
2 өөрчлөгдсөн 21 нэмэгдсэн , 21 устгасан
  1. 8 8
      src/define.sh
  2. 13 13
      src/install.sh

+ 8 - 8
src/define.sh

@@ -1215,7 +1215,7 @@ addFolder() {
   cp -Lr "$folder/." "$dest" || return 1
   cp -Lr "$folder/." "$dest" || return 1
 
 
   local file
   local file
-  file=$(find "$dest" -maxdepth 1 -type f -iname install.bat | head -n 1)
+  file=$(find "$dest" -maxdepth 1 -type f -iname install.bat  -print -quit)
   [ -f "$file" ] && unix2dos -q "$file"
   [ -f "$file" ] && unix2dos -q "$file"
 
 
   return 0
   return 0
@@ -1310,7 +1310,7 @@ prepareInstall() {
   fi
   fi
 
 
   local pid file setup
   local pid file setup
-  setup=$(find "$target" -maxdepth 1 -type f -iname setupp.ini | head -n 1)
+  setup=$(find "$target" -maxdepth 1 -type f -iname setupp.ini -print -quit)
 
 
   if [ -n "$setup" ]; then
   if [ -n "$setup" ]; then
 
 
@@ -1606,20 +1606,20 @@ detectLegacy() {
   local dir="$1"
   local dir="$1"
   local find find2
   local find find2
 
 
-  find=$(find "$dir" -maxdepth 1 -type d -iname win95 | head -n 1)
+  find=$(find "$dir" -maxdepth 1 -type d -iname win95 -print -quit)
   [ -n "$find" ] && DETECTED="win95" && return 0
   [ -n "$find" ] && DETECTED="win95" && return 0
 
 
-  find=$(find "$dir" -maxdepth 1 -type d -iname win98 | head -n 1)
+  find=$(find "$dir" -maxdepth 1 -type d -iname win98 -print -quit)
   [ -n "$find" ] && DETECTED="win98" && return 0
   [ -n "$find" ] && DETECTED="win98" && return 0
 
 
-  find=$(find "$dir" -maxdepth 1 -type d -iname win9x | head -n 1)
+  find=$(find "$dir" -maxdepth 1 -type d -iname win9x -print -quit)
   [ -n "$find" ] && DETECTED="win9x" && return 0
   [ -n "$find" ] && DETECTED="win9x" && return 0
 
 
-  find=$(find "$dir" -maxdepth 1 -type f -iname cdrom_nt.5 | head -n 1)
+  find=$(find "$dir" -maxdepth 1 -type f -iname cdrom_nt.5 -print -quit)
   [ -n "$find" ] && DETECTED="win2k" && return 0
   [ -n "$find" ] && DETECTED="win2k" && return 0
 
 
-  find=$(find "$dir" -maxdepth 1 -type d -iname win51 | head -n 1)
-  find2=$(find "$dir" -maxdepth 1 -type f -iname setupxp.htm | head -n 1)
+  find=$(find "$dir" -maxdepth 1 -type d -iname win51 -print -quit)
+  find2=$(find "$dir" -maxdepth 1 -type f -iname setupxp.htm -print -quit)
 
 
   if [ -n "$find" ] || [ -n "$find2" ] || [ -f "$dir/WIN51AP" ] || [ -f "$dir/WIN51IC" ]; then
   if [ -n "$find" ] || [ -n "$find2" ] || [ -f "$dir/WIN51AP" ] || [ -f "$dir/WIN51IC" ]; then
     [ -d "$dir/AMD64" ] && DETECTED="winxpx64" && return 0
     [ -d "$dir/AMD64" ] && DETECTED="winxpx64" && return 0

+ 13 - 13
src/install.sh

@@ -201,7 +201,7 @@ abortInstall() {
   [[ "${iso,,}" == *".esd" ]] && exit 60
   [[ "${iso,,}" == *".esd" ]] && exit 60
   [[ "${UNPACK:-}" == [Yy1]* ]] && exit 60
   [[ "${UNPACK:-}" == [Yy1]* ]] && exit 60
 
 
-  efi=$(find "$dir" -maxdepth 1 -type d -iname efi | head -n 1)
+  efi=$(find "$dir" -maxdepth 1 -type d -iname efi -print -quit)
 
 
   if [ -z "$efi" ]; then
   if [ -z "$efi" ]; then
     [[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
     [[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
@@ -230,8 +230,8 @@ detectCustom() {
 
 
   CUSTOM=""
   CUSTOM=""
 
 
-  dir=$(find / -maxdepth 1 -type d -iname "$fname" | head -n 1)
-  [ ! -d "$dir" ] && dir=$(find "$STORAGE" -maxdepth 1 -type d -iname "$fname" | head -n 1)
+  dir=$(find / -maxdepth 1 -type d -iname "$fname" -print -quit)
+  [ ! -d "$dir" ] && dir=$(find "$STORAGE" -maxdepth 1 -type d -iname "$fname" -print -quit)
 
 
   if [ -d "$dir" ]; then
   if [ -d "$dir" ]; then
     if ! hasDisk || [ ! -f "$boot" ]; then
     if ! hasDisk || [ ! -f "$boot" ]; then
@@ -239,8 +239,8 @@ detectCustom() {
     fi
     fi
   fi
   fi
 
 
-  file=$(find / -maxdepth 1 -type f -iname "$fname" | head -n 1)
-  [ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$fname" | head -n 1)
+  file=$(find / -maxdepth 1 -type f -iname "$fname" -print -quit)
+  [ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$fname" -print -quit)
 
 
   if [ ! -s "$file" ] && [[ "${VERSION,,}" != "http"* ]]; then
   if [ ! -s "$file" ] && [[ "${VERSION,,}" != "http"* ]]; then
     base=$(basename "$VERSION")
     base=$(basename "$VERSION")
@@ -396,7 +396,7 @@ extractImage() {
 
 
   else
   else
 
 
-    file=$(find "$dir" -maxdepth 1 -type f -iname "*.iso" | head -n 1)
+    file=$(find "$dir" -maxdepth 1 -type f -iname "*.iso" -print -quit)
 
 
     if [ -z "$file" ]; then
     if [ -z "$file" ]; then
       error "Failed to find any .iso file in archive!" && return 1
       error "Failed to find any .iso file in archive!" && return 1
@@ -591,14 +591,14 @@ detectImage() {
   fi
   fi
 
 
   local src wim info
   local src wim info
-  src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
+  src=$(find "$dir" -maxdepth 1 -type d -iname sources -print -quit)
 
 
   if [ ! -d "$src" ]; then
   if [ ! -d "$src" ]; then
     warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
     warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
   fi
   fi
 
 
-  wim=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1)
-  [ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)
+  wim=$(find "$src" -maxdepth 1 -type f -iname install.wim -print -quit)
+  [ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname install.esd -print -quit)
 
 
   if [ ! -f "$wim" ]; then
   if [ ! -f "$wim" ]; then
     warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1
     warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1
@@ -892,14 +892,14 @@ updateImage() {
   rm -rf "$tmp"
   rm -rf "$tmp"
   mkdir -p "$tmp"
   mkdir -p "$tmp"
 
 
-  src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
+  src=$(find "$dir" -maxdepth 1 -type d -iname sources -print -quit)
 
 
   if [ ! -d "$src" ]; then
   if [ ! -d "$src" ]; then
     error "failed to locate 'sources' folder in ISO image, $FB" && return 1
     error "failed to locate 'sources' folder in ISO image, $FB" && return 1
   fi
   fi
 
 
-  wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1)
-  [ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)
+  wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim -print -quit)
+  [ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname boot.esd -print -quit)
 
 
   if [ ! -f "$wim" ]; then
   if [ ! -f "$wim" ]; then
     error "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1
     error "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1
@@ -962,7 +962,7 @@ updateImage() {
 
 
   local find="$file"
   local find="$file"
   [[ "$MANUAL" == [Yy1]* ]] && find="$org"
   [[ "$MANUAL" == [Yy1]* ]] && find="$org"
-  path=$(find "$dir" -maxdepth 1 -type f -iname "$find" | head -n 1)
+  path=$(find "$dir" -maxdepth 1 -type f -iname "$find" -print -quit)
 
 
   if [ -f "$path" ]; then
   if [ -f "$path" ]; then
     if [[ "$MANUAL" != [Yy1]* ]]; then
     if [[ "$MANUAL" != [Yy1]* ]]; then