home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / 3b2 / selectdevice < prev    next >
Text File  |  1985-07-02  |  2KB  |  104 lines

  1. #    @(#)selectdevice    1.2    /sccs/src/cmd/sadmin/shell/s.selectdevice
  2. #    Select one of the simple administration names for a block or character
  3. #    device.
  4.  
  5. #!    chmod +x ${file}
  6.  
  7. pid=${2:?}
  8. case "$1" in
  9. -b )    #    block device
  10.     type=-b
  11.     typename=block
  12.     r=
  13.     ;;
  14. -c )    #    character (aka raw) device
  15.     type=-c
  16.     typename=character
  17.     r=r
  18.     ;;
  19. * )
  20.     echo >&2 "Usage:  $0 -[b|c] pid [dir [names ...]]"
  21.     exit 1
  22. esac
  23.  
  24. if [ $# -lt 3 ]
  25. then
  26.     #default directory to /dev/${r}SA
  27.     set -- $1 $2 /dev/${r}SA
  28. fi
  29. DIR=$3
  30.  
  31. if [ ! -d $DIR ]
  32. then
  33.     admerr $0 $DIR nonexistent directory
  34.     exit 1
  35. fi
  36.  
  37. rm -f /usr/tmp/$$.list
  38. cd $DIR
  39. shift 3
  40. if [ $# -eq 0 ]
  41. then
  42.     # default to everything in directory
  43.     ls >/usr/tmp/$$.list
  44. else
  45.     for DEVTYPES in $*
  46.     do
  47.         ls | grep "${DEVTYPES}[0-9][0-9]*" >>/usr/tmp/$$.list
  48.     done
  49. fi
  50. if [ ! -s /usr/tmp/$$.list ]
  51. then
  52.     admerr $0 Problems in $DIR, no valid ${typename} devices.
  53.     rm -f /usr/tmp/$$.list
  54.     exit 1
  55. fi
  56.  
  57. set -- `cat /usr/tmp/$$.list`
  58.  
  59. if [ $# = 1 ]
  60. then    
  61.     if [ ! ${type} "$1" ]
  62.     then
  63.         admerr $0 $1 is not of type ${typename}
  64.         rm -f /usr/tmp/$$.list
  65.         exit 1
  66.     fi
  67.  
  68.     echo $DIR/$1
  69.     rm -f /usr/tmp/$$.list
  70.     exit 0
  71. elif [ $# -gt 1 ]
  72. then
  73.     list=`pr -tn /usr/tmp/$$.list`
  74.     select=`checklist -k "${pid}" -fep -H "
  75. The menu items indicate possible devices for use by this subcommand.
  76. Your selection will determine the particular device to be used." "
  77. Select which device to use:
  78.  
  79. ${list}
  80.  
  81. Enter a number, a name, the initial part of a name, or
  82. ? for HELP, q to QUIT:" ${list} q`
  83.     case ${select} in
  84.     q )
  85.         rm -f /usr/tmp/$$.list
  86.         exit 0 ;;
  87.     [1-9] | [1-9][0-9]* )
  88.         shift `expr $select - 1`
  89.         DEV=$DIR/$1
  90.         ;;
  91.     * )
  92.         DEV=$DIR/${select}
  93.     esac
  94.     if [ ! ${type} $DEV ]
  95.     then
  96.         admerr $0 $DEV is not of type ${typename}
  97.         rm -f /usr/tmp/$$.list
  98.         exit 1
  99.     fi
  100.     echo $DEV
  101.     rm -f /usr/tmp/$$.list
  102.     exit 0
  103. fi
  104.