home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / rescue / sbin / smart_agetty < prev    next >
Text File  |  2006-11-29  |  2KB  |  108 lines

  1. #!/bin/bash
  2. # emulate: /sbin/agetty -L $speed console for console != vga/framebuffer console
  3.  
  4. #echo "$0: called with '$*'" > /dev/kmsg
  5.  
  6. function stop_me () {
  7.     kill -STOP $$
  8.     exit 1
  9. }
  10.  
  11. kernel_console=
  12. getty_options=
  13. getty_device=
  14. getty_speed=
  15. getty_TERM=
  16.  
  17. until [ "$#" = "0" ] ; do
  18.     case "$1" in
  19.         -i|-h|-L|-m|-n|-w)
  20.             getty_options="$getty_options $1"
  21.             shift
  22.         ;;
  23.         -*)
  24.             getty_options="$getty_options $1 $2"
  25.             shift 2
  26.         ;;
  27.         *)
  28.             case "$1" in
  29.                 [0-9]*)
  30.                 getty_speed=$1
  31.                 getty_device=$2
  32.                 ;;
  33.                 *)
  34.                 getty_speed=$2
  35.                 getty_device=$1
  36.                 ;;
  37.             esac
  38.             getty_TERM=$3
  39.             break
  40.         ;;
  41.     esac
  42. done
  43.  
  44. getty_speed=`stty speed < /dev/$getty_device`
  45.  
  46. if test -z "$getty_speed"
  47. then
  48.     echo "${0}: can not determine '$getty_device' speed" > /dev/kmsg
  49.     stop_me
  50.     exit 1
  51. fi
  52.  
  53. guess_powerpc_autoconsole() {
  54.     local prop
  55.     if test -f /proc/device-tree/chosen/linux,stdout-path
  56.     then
  57.         prop=`cat /proc/device-tree/chosen/linux,stdout-path`
  58.         prop="${prop##*/}"
  59.         case "$prop" in
  60.             display@*) echo tty1 ;;
  61.             serial@3f8) echo ttyS0 ;; # maple
  62.             serial@i3f8) echo ttyS0 ;;
  63.             serial@i2f8) echo ttyS1 ;;
  64.             serial@i898) echo ttyS2 ;;
  65.             serial@i890) echo ttyS3 ;;
  66.             vty@0) echo hvc0 ;;
  67.             vty@30000000) echo hvsi0 ;;
  68.             vty@30000001) echo hvsi1 ;;
  69.             # some Exar and Jasmine PCI cards have serial@[0123]
  70.             # but since its pci, the ttyS# number cant be guessed
  71.             serial@0) echo ttyS0 ;;
  72.             *) echo "$0: unhandled stdout '$prop'" > /dev/kmsg ;;
  73.         esac
  74.     fi
  75. }
  76.  
  77. if test "$getty_device" = "console"
  78. then
  79.     read kernel_cmdline < /proc/cmdline
  80.     for i in $kernel_cmdline ''
  81.     do
  82.         case "$i" in
  83.             console=*)
  84.             kernel_console="${i#*=}"
  85.             kernel_console="${kernel_console%%,*}"
  86.             ;;
  87.         esac
  88.     done
  89.     if test -z "$kernel_console"
  90.     then
  91.         # check SuSE TIOCGDEV, remove /dev/
  92.         kernel_console="`showconsole < /dev/console`"
  93.         kernel_console="${kernel_console##*/}"
  94.     fi
  95.     if test -z "$kernel_console"
  96.     then
  97.         kernel_console="`guess_powerpc_autoconsole`"
  98.     fi
  99.     case "$kernel_console" in
  100.         tty[0-9]*)
  101.         stop_me
  102.         exit 1
  103.         ;;
  104.     esac
  105. fi
  106.  
  107. exec /sbin/agetty $getty_options $getty_speed $getty_device $getty_TERM
  108.