Speed up recovery script finding matching images

Make all the calls to grep go away, and instead use a case statement
like we do earlier in the file to count the number of matching images.
Runtime is now just a few seconds.

BUG=chromium:263207
TEST=run ./recovery.sh; press enter; LOTS of models printed
     run ./recovery.sh; type LINK; just link models printed

Change-Id: I957d37f9ef9f24d00c63b9bfab509e04f4add78c
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/62921
Reviewed-by: Daniel Erat <derat@chromium.org>
diff --git a/linux/recovery.sh b/linux/recovery.sh
index 2068b65..ca1b893 100755
--- a/linux/recovery.sh
+++ b/linux/recovery.sh
@@ -457,6 +457,9 @@
       read hwidprefix
 
       echo
+      echo "This may take a few minutes to print the full list..."
+
+      echo
       if [ "$num_images" -gt 1 ]; then
         echo "There are $num_images recovery images to choose from:"
       else
@@ -466,20 +469,38 @@
       count=0
       echo "0 - <quit>"
       # NOTE: making assumptions about the order of lines in each stanza!
+
+
       while read line; do
-        if echo "$line" | grep -q '^name='; then
-          echo
-          count=$(( count + 1 ))
-          echo "$line" | sed "s/name=/$count - /"
-        elif echo "$line" | grep -q '^channel='; then
-          echo "$line" | sed 's/channel=/      channel:  /'
-        elif echo "$line" | grep -q '^hwid='; then
-          if [ -z "$hwidprefix" ] || \
-              echo "$line" | grep -qi "hwid=$hwidprefix"; then
-              echo "$line" | sed 's/hwid=/      model:    /'
+          # Got something...
+          if [ -n "$line" ]; then
+              key=${line%=*}
+              val=${line#*=}
+              if [ -z "$key" ] || [ -z "$val" ] || \
+                  [ "$key=$val" != "$line" ]; then
+                  DEBUG "ignoring $line"
+                  continue
+              fi
+
+              case $key in
+                  name)
+                      count=$(( count + 1 ))
+                      echo "$count - $val"
+                      ;;
+                  channel)
+                      echo "      channel:  $val"
+                      ;;
+                  hwid)
+                      if [ -z "$hwidprefix" ]; then
+                          echo "      model:    $val"
+                      elif [ "${val#$hwidprefix}" != "$val" ]; then
+                          echo "      model:    $val"
+                      fi
+                      ;;
+              esac
           fi
-        fi
       done < "$config"
+
       echo
       show=
     fi