From nobody@FreeBSD.org  Mon Jan  2 11:05:26 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 343241065672
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  2 Jan 2012 11:05:26 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 21D568FC1B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  2 Jan 2012 11:05:26 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q02B5PZu064754
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 2 Jan 2012 11:05:25 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q02B5P2i064753;
	Mon, 2 Jan 2012 11:05:25 GMT
	(envelope-from nobody)
Message-Id: <201201021105.q02B5P2i064753@red.freebsd.org>
Date: Mon, 2 Jan 2012 11:05:25 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] pc-sysinstall/backend.sh - convert iscompressed function from egrep to case expression
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         163773
>Category:       bin
>Synopsis:       [patch] pc-sysinstall(8): pc-sysinstall/backend.sh - convert iscompressed function from egrep to case expression
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 02 11:10:08 UTC 2012
>Closed-Date:    Sun Mar 04 04:23:40 UTC 2012
>Last-Modified:  Sun Feb 03 22:30:00 UTC 2013
>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     gcooper@bayonetta.local:/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:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sun Jan 22 05:42:24 UTC 2012 
Responsible-Changed-Why:  
n1 

http://www.freebsd.org/cgi/query-pr.cgi?pr=163773 
State-Changed-From-To: open->closed 
State-Changed-By: eadler 
State-Changed-When: Sun Mar 4 04:23:39 UTC 2012 
State-Changed-Why:  
the grep code looks cleaner and it is more obvious what is going on on 
(we are 'looking'/'grepping' for some text). The lack of a quality test 
suite for grep is a different issue 

http://www.freebsd.org/cgi/query-pr.cgi?pr=163773 
>Unformatted:
