>Number:         163773
>Category:       bin
>Synopsis:       [patch] pc-sysinstall/backend.sh - convert iscompressed 
>function from egrep to case expression
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 02 11:10:08 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Garrett Cooper
>Release:        9.0-PRERELEASE
>Organization:
n/a
>Environment:
FreeBSD bayonetta.local 9.0-PRERELEASE FreeBSD 9.0-PRERELEASE #0 r229187M: Sun 
Jan  1 14:39:27 PST 2012     
[email protected]:/usr/obj/store/freebsd/stable/9/sys/BAYONETTA  amd64
>Description:
We ran into an issue at iXsystems using pc-sysinstall where 9.0-BETA and RC1 
images weren't properly determining compressed file formats. After some poking 
around and testing, I determined that the issue was with how egrep formulated 
the regular expression; I didn't go any further than that.

In order to work around the issue, I rewrote the function to use a simpler 
shell-based case statement.

The grep bug appears to have been isolated and fixed, but I thought this would 
still be a worthwhile change as it doesn't require grep to run, and FreeBSD's 
/bin/sh has a more extensive test suite than *grep does.
>How-To-Repeat:
$ cat test-is_compressed.sh <<EOF
#!/bin/sh

iscompressed_case()
{
  local FILE
  local RES

  FILE="$1"

  case "${FILE}" in
  *.Z|*.lzo|*.lzw|*.lzma|*.gz|*.bz2|*.xz|*.zip)
    RES=0
    ;;
  *)
    RES=1
    ;;
  esac

  return ${RES}
}

iscompressed_bsdgrep()
{
  local FILE
  local RES

  FILE="$1"
  RES=1

  if echo "${FILE}" | \
    grep -qiE '\.(Z|lzo|lzw|lzma|gz|bz2|xz|zip)$' 2>&1
  then
    RES=0
  fi

  return ${RES}
}

iscompressed_grep()
{
  local FILE
  local RES

  FILE="$1"
  RES=1

  if echo "${FILE}" | \
    grep -qiE '\.(Z|lzo|lzw|lzma|gz|bz2|xz|zip)$' 2>&1
  then
    RES=0
  fi

  return ${RES}
}

for i in foo.Z foo.lzo foo.lzw foo.lzma foo.gz foo.bz2 foo.xz foo.zip foo.xzzip 
foo.bargz foo.tar.xz FreeNAS-embedded-amd64.xz 
FreeNAS-8.0.3-RC3-x86.GUI_Upgrade.xz FreeNAS-8.0.3-BETA1-amd64.Full_Install.xz 
FreeNAS-8.2-ALPHA-r9369-x86.GUI_Upgrade.xz 
FreeNAS-8.2-r9200-x64.Full_Install.xz FreeNAS-8.2-r8527-amd64.full.xz; do
    if iscompressed_case $i; then
        echo "case $i (matched)"
    else
        echo "case $i (no-match)"
    fi
    if iscompressed_bsdgrep $i; then
        echo "bsdgrep $i (matched)"
    else
        echo "bsdgrep $i (no-match)"
    fi
    if iscompressed_grep $i; then
        echo "grep $i (matched)"
    else
        echo "grep $i (no-match)"
    fi
done
EOF
$ sh test-is_compressed.sh
case foo.Z (matched)
bsdgrep foo.Z (matched)
grep foo.Z (matched)
case foo.lzo (matched)
bsdgrep foo.lzo (matched)
grep foo.lzo (matched)
case foo.lzw (matched)
bsdgrep foo.lzw (matched)
grep foo.lzw (matched)
case foo.lzma (matched)
bsdgrep foo.lzma (matched)
grep foo.lzma (matched)
case foo.gz (matched)
bsdgrep foo.gz (matched)
grep foo.gz (matched)
case foo.bz2 (matched)
bsdgrep foo.bz2 (matched)
grep foo.bz2 (matched)
case foo.xz (matched)
bsdgrep foo.xz (matched)
grep foo.xz (matched)
case foo.zip (matched)
bsdgrep foo.zip (matched)
grep foo.zip (matched)
case foo.xzzip (no-match)
bsdgrep foo.xzzip (no-match)
grep foo.xzzip (no-match)
case foo.bargz (no-match)
bsdgrep foo.bargz (no-match)
grep foo.bargz (no-match)
case foo.tar.xz (matched)
bsdgrep foo.tar.xz (matched)
grep foo.tar.xz (matched)
case FreeNAS-embedded-amd64.xz (matched)
bsdgrep FreeNAS-embedded-amd64.xz (matched)
grep FreeNAS-embedded-amd64.xz (matched)
case FreeNAS-8.0.3-RC3-x86.GUI_Upgrade.xz (matched)
bsdgrep FreeNAS-8.0.3-RC3-x86.GUI_Upgrade.xz (matched)
grep FreeNAS-8.0.3-RC3-x86.GUI_Upgrade.xz (matched)
case FreeNAS-8.0.3-BETA1-amd64.Full_Install.xz (matched)
bsdgrep FreeNAS-8.0.3-BETA1-amd64.Full_Install.xz (matched)
grep FreeNAS-8.0.3-BETA1-amd64.Full_Install.xz (matched)
case FreeNAS-8.2-ALPHA-r9369-x86.GUI_Upgrade.xz (matched)
bsdgrep FreeNAS-8.2-ALPHA-r9369-x86.GUI_Upgrade.xz (matched)
grep FreeNAS-8.2-ALPHA-r9369-x86.GUI_Upgrade.xz (matched)
case FreeNAS-8.2-r9200-x64.Full_Install.xz (matched)
bsdgrep FreeNAS-8.2-r9200-x64.Full_Install.xz (matched)
grep FreeNAS-8.2-r9200-x64.Full_Install.xz (matched)
case FreeNAS-8.2-r8527-amd64.full.xz (matched)
bsdgrep FreeNAS-8.2-r8527-amd64.full.xz (matched)
grep FreeNAS-8.2-r8527-amd64.full.xz (matched)
>Fix:


Patch attached with submission follows:

Index: usr.sbin/pc-sysinstall/backend/functions.sh
===================================================================
--- usr.sbin/pc-sysinstall/backend/functions.sh (revision 229264)
+++ usr.sbin/pc-sysinstall/backend/functions.sh (working copy)
@@ -290,13 +290,15 @@
   local RES
 
   FILE="$1"
-  RES=1
 
-  if echo "${FILE}" | \
-    grep -qiE '\.(Z|lzo|lzw|lzma|gz|bz2|xz|zip)$' 2>&1
-  then
+  case "${FILE}" in
+  *.Z|*.lzo|*.lzw|*.lzma|*.gz|*.bz2|*.xz|*.zip)
     RES=0
-  fi
+    ;;
+  *)
+    RES=1
+    ;;
+  esac
 
   return ${RES}
 }


>Release-Note:
>Audit-Trail:
>Unformatted:
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to