Print this page
XXX Remove nawk(1)


   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23 # Use is subject to license terms.
  24 #
  25 # ident "%Z%%M% %I%     %E% SMI"
  26 #
  27 
  28 #
  29 # Get the make/model/nickname as well as the repository/label from ppdfilename
  30 #
  31 
  32 # Input
  33 #       ppdfilename
  34 #       /var/lp/ppd/user/HP/foo.ppd.gz
  35 # Output
  36 #       make
  37 #       model
  38 #       label(repository letter): driver
  39 #
  40 #       Lexmark
  41 #       IBM Page Printer 3112
  42 #       foomatic(L): Foomatic/hpijs
  43 #
  44 
  45 if [[ $# -lt 1 ]]; then
  46         exit 1
  47 fi
  48 
  49 cachefile=/var/lp/ppd/ppdcache
  50 [[ -f $cachefile ]] || exit 1
  51 
  52 cacheentry=$(/bin/grep "$1" $cachefile)
  53 [[ -n "$cacheentry" ]] || exit 1
  54 
  55 #
  56 # Retrieve the manufacturer (make)
  57 # Use only the first word in manufacturer entry
  58 #
  59 manuf=$(echo "$cacheentry" | 
  60 nawk '{FS=":"; print $1}' |
  61 nawk '{print $1}')
  62 
  63 # Retrieve the model
  64 model=$(echo "$cacheentry" | nawk '{FS=":"; print $2}')
  65 
  66 # Retrieve the driver
  67 driver=$(echo "$cacheentry" | nawk '{FS=":"; print $3}')
  68 
  69 #
  70 # Retrieve the PPD path.  Parse the PPD path to get the
  71 # label path and to figure out the repository letter
  72 # associated with the label path.  Note:
  73 # the PPD file name is the 6th colon separated entry
  74 # in the cache entry.  This is may need to be modified if the
  75 # format changes.
  76 #
  77 ppdpath=$(echo "$cacheentry" | /bin/nawk '{FS=":"; print $6}' )
  78 manupath=$(/bin/dirname "$ppdpath")
  79 labelpath=$(/bin/dirname "$manupath")
  80 
  81 case "$labelpath" in
  82 /usr/share/ppd/*)
  83         repltr=S
  84                 ;;
  85 /opt/share/ppd/*)
  86         repltr=V
  87         ;;
  88 /usr/local/share/ppd/*)
  89         repltr=A
  90         ;;
  91 /var/lp/ppd/*)
  92         repltr=U
  93         ;;
  94 esac
  95 
  96 [[ -n "${repltr}" ]] || exit 1
  97 echo "${manuf}\n${model}"


   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23 # Use is subject to license terms.
  24 #


  25 
  26 #
  27 # Get the make/model/nickname as well as the repository/label from ppdfilename
  28 #
  29 
  30 # Input
  31 #       ppdfilename
  32 #       /var/lp/ppd/user/HP/foo.ppd.gz
  33 # Output
  34 #       make
  35 #       model
  36 #       label(repository letter): driver
  37 #
  38 #       Lexmark
  39 #       IBM Page Printer 3112
  40 #       foomatic(L): Foomatic/hpijs
  41 #
  42 
  43 if [[ $# -lt 1 ]]; then
  44         exit 1
  45 fi
  46 
  47 cachefile=/var/lp/ppd/ppdcache
  48 [[ -f $cachefile ]] || exit 1
  49 
  50 cacheentry=$(/bin/grep "$1" $cachefile)
  51 [[ -n "$cacheentry" ]] || exit 1
  52 
  53 #
  54 # Retrieve the manufacturer (make)
  55 # Use only the first word in manufacturer entry
  56 #
  57 manuf=$(echo "$cacheentry" | 
  58 /usr/xpg4/bin/awk '{FS=":"; print $1}' |
  59 /usr/xpg4/bin/awk '{print $1}')
  60 
  61 # Retrieve the model
  62 model=$(echo "$cacheentry" | /usr/xpg4/bin/awk '{FS=":"; print $2}')
  63 
  64 # Retrieve the driver
  65 driver=$(echo "$cacheentry" | /usr/xpg4/bin/awk '{FS=":"; print $3}')
  66 
  67 #
  68 # Retrieve the PPD path.  Parse the PPD path to get the
  69 # label path and to figure out the repository letter
  70 # associated with the label path.  Note:
  71 # the PPD file name is the 6th colon separated entry
  72 # in the cache entry.  This is may need to be modified if the
  73 # format changes.
  74 #
  75 ppdpath=$(echo "$cacheentry" | /usr/xpg4/bin/awk '{FS=":"; print $6}' )
  76 manupath=$(/bin/dirname "$ppdpath")
  77 labelpath=$(/bin/dirname "$manupath")
  78 
  79 case "$labelpath" in
  80 /usr/share/ppd/*)
  81         repltr=S
  82                 ;;
  83 /opt/share/ppd/*)
  84         repltr=V
  85         ;;
  86 /usr/local/share/ppd/*)
  87         repltr=A
  88         ;;
  89 /var/lp/ppd/*)
  90         repltr=U
  91         ;;
  92 esac
  93 
  94 [[ -n "${repltr}" ]] || exit 1
  95 echo "${manuf}\n${model}"