home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / rescue / etc / sysconfig / hardware / scripts / chandev-to-hwcfg.sh next >
Linux/UNIX/POSIX Shell Script  |  2006-11-29  |  6KB  |  277 lines

  1. #!/bin/bash
  2. #
  3. # Converts lines from /etc/chandev.conf to hwcfg-files.
  4. #
  5. # This is for debugging.
  6. # DEBUG=1
  7.  
  8. if [ -z "$DEBUG" ]; then
  9.     HWCFG_DIR=/etc/sysconfig/hardware
  10.     CHANDEV=/etc/chandev.conf
  11. else
  12.     CHANDEV=$1
  13.     HWCFG_DIR="."
  14. fi
  15.  
  16. if [ ! -f "$CHANDEV" ]; then
  17.     # Nothing to be done
  18.     exit 0
  19. fi
  20.  
  21. # What a bastard
  22. retval=0
  23. saved_IFS="$IFS"
  24. IFS=","
  25. while read; do
  26.     _line="$REPLY"
  27.     set -- $REPLY
  28.     if [ -n "$1" ]; then
  29.     _devname=${1%%[1234567890]*}
  30.     echo -n "Converting parameter $1: "
  31.     shift
  32.     case "$_devname" in
  33.         qeth*)
  34.         _read_chan=$(($1))
  35.         _write_chan=$(($2))
  36.         _data_chan=$(($3))
  37.         if [ "$_write_chan" -ne $(expr $_read_chan + 1) -o \
  38.             "$_data_chan" -ne $(expr $_read_chan + 2) ]; then
  39.             echo "Channel IDs not consecutive, cannot convert."
  40.             echo "Entry was:"
  41.             echo "$_line"
  42.             retval=1
  43.             break;
  44.         fi
  45.         shift; shift; shift;
  46.         if [ $# -gt 0 ]; then
  47.             if [ $1 -ne 0 ] ; then
  48.             _memsize=$1
  49.             fi
  50.             shift;
  51.         fi
  52.         if [ $# -gt 0 ] ; then
  53.             if [ $1 -ne -1 -a $1 -ne 0 ] ; then
  54.             _portno=$1
  55.             fi
  56.         fi
  57.         if [ "$_read_chan" -lt "$_write_chan" ]; then
  58.             CFG_ID="$_read_chan"
  59.         else
  60.             CFG_ID="$_write_chan"
  61.         fi
  62.         if [ "$CFG_ID" -gt "$_data_chan" ]; then
  63.             CFG_ID="$_data_chan"
  64.         fi
  65.         _begin_id=$(printf "%04x" $CFG_ID)
  66.         eval CFGNAME[$CFG_ID]="hwcfg-qeth-bus-ccw-0.0.$_begin_id"
  67.         eval MODULE[$CFG_ID]="qeth_mod"
  68.         eval STARTMODE[$CFG_ID]="auto"
  69.         eval CCW_CHAN_NAME[$CFG_ID]="qeth"
  70.         eval CCW_CHAN_NUM[$CFG_ID]=3
  71.         eval CCW_CHAN_IDS[$CFG_ID]="\"0.0.$(printf "%04x" $_read_chan) 0.0.$(printf "%04x" $_write_chan) 0.0.$(printf "%04x" $_data_chan)\""
  72.         eval SCRIPT_up[$CFG_ID]="hwup-ccw"
  73.         eval SCRIPT_ccw[$CFG_ID]="hwup-ccw"
  74.         eval SCRIPT_ccwgroup[$CFG_ID]="hwup-qeth"
  75.         eval SCRIPT_down[$CFG_ID]="hwdown-ccw"
  76.         CFG_LIST="${CFG_LIST:+$CFG_LIST }$CFG_ID"
  77.         _entry="$_line"
  78.         echo "ok."
  79.         ;;
  80.         ctc*|escon*|lcs*)
  81.         _read_chan=$(($1))
  82.         _write_chan=$(($2))
  83.         if [ "$_write_chan" -ne $(expr $_read_chan + 1) ]; then
  84.             echo "Channel IDs not consecutive, cannot convert."
  85.             echo "Entry was:"
  86.             echo "$_line"
  87.             retval=1
  88.             break;
  89.         fi
  90.         shift; shift;
  91.         if [ $# -gt 0 ]; then
  92.             if  [ $1 -ne 0 ]; then
  93.             _memsize=$1
  94.             fi
  95.             shift
  96.         fi
  97.         if [ $# -gt 0 ]; then
  98.             if [ $1 -ne 0 ]; then
  99.             _port=$1
  100.             fi
  101.             shift
  102.         fi
  103.         if [ $# -gt 0 ]; then
  104.             if [ $1 -ne 0 ]; then
  105.             _checksum=$1
  106.             fi
  107.             shift
  108.         fi
  109.         if [ $# -gt 0 ] && [ $1 -ne 0 ]; then
  110.             _use_stats=$1
  111.         fi
  112.         if [ "$_read_chan" -lt "$_write_chan" ]; then
  113.             CFG_ID="$_read_chan"
  114.         else
  115.             CFG_ID="$_write_chan"
  116.         fi
  117.         _begin_id=$(printf "%04x" $CFG_ID)
  118.         eval CFGNAME[$CFG_ID]="hwcfg-$_devname-bus-ccw-0.0.$_begin_id"
  119.         eval MODULE[$CFG_ID]="ctc"
  120.         eval STARTMODE[$CFG_ID]="auto"
  121.         eval CCW_CHAN_NAME[$CFG_ID]=cu3088
  122.         eval CCW_CHAN_NUM[$CFG_ID]=2
  123.         eval CCW_CHAN_IDS[$CFG_ID]="\"0.0.$(printf "%04x" $_read_chan) 0.0.$(printf "%04x" $_write_chan)\""
  124.         eval CCW_CHAN_MODE[$CFG_ID]="$_port"
  125.         eval SCRIPT_up[$CFG_ID]="hwup-ccw"
  126.         eval SCRIPT_ccw[$CFG_ID]="hwup-ccw"
  127.         eval SCRIPT_ccwgroup[$CFG_ID]="hwup-ctc"
  128.         eval SCRIPT_down[$CFG_ID]="hwdown-ccw"
  129.         CFG_LIST="${CFG_LIST:+$CFG_LIST }$CFG_ID"
  130.         _entry="$_line"
  131.         echo "ok."
  132.         ;;
  133.         add_parm*)
  134.         _chan_type=$1
  135.         if [ $(($_chan_type)) -ne $((0x10)) ]; then
  136.             echo "Unhandled device type $_chan_type in add_parms!"
  137.             retval=1
  138.             continue
  139.         fi
  140.  
  141.         case $2 in
  142.             0x*)
  143.             shift
  144.             _begin_id=$1
  145.             shift
  146.             _end_id=$1
  147.             ;;
  148.             *)
  149.             _begin_id=0
  150.             _end_id=$((0xFFFF))
  151.             ;;
  152.         esac
  153.  
  154.         while shift; do
  155.             case $1 in
  156.             portname*)
  157.                 _port=${1#portname:}
  158.                 for _id in $CFG_LIST; do
  159.                 if [ $(($_id > $_begin_id)) ] && [ $((_id < $_end_id)) ] ; then
  160.                     eval CCW_CHAN_MODE[$_id]="$_port"
  161.  
  162.                 fi
  163.                 done
  164.                 echo -n "(portname: $_port) "
  165.                 ;;
  166.             *)
  167.                 if [ "$1" ]; then
  168.                 echo -n "($1: ignored) "
  169.                 fi
  170.                 ;;
  171.             esac
  172.         done
  173.         echo "ok."
  174.         _entry="$_entry;$_line"
  175.         ;;
  176.         noauto*)
  177.         echo "ignored."
  178.         ;;
  179.         use_devno_names*)
  180.         echo "ignored."
  181.         ;;
  182.         *)
  183.         echo "not supported, please edit manually."
  184.         retval=1
  185.         ;;
  186.     esac
  187.     fi
  188. done < <(cat $CHANDEV | sed '/^#/d;/^ /d' | tr ";" "\n")
  189. IFS="$saved_IFS"
  190.  
  191. for _cfg in $CFG_LIST; do
  192.     _hwcfg_file=${HWCFG_DIR}/${CFGNAME[$_cfg]}
  193.     cat > $_hwcfg_file <<EOF
  194. #!/bin/sh
  195. #
  196. # ${CFGNAME[$_cfg]}
  197. #
  198. # Automatically converted from chandev entry
  199. # $_entry
  200. #
  201. # Please check whether the specified adapter is 
  202. # correctly configured
  203. #
  204.  
  205. STARTMODE="${STARTMODE[$_cfg]}"
  206. MODULE="${MODULE[$_cfg]}"
  207. MODULE_OPTIONS=""
  208. MODULE_UNLOAD="no"
  209.  
  210. # Scripts to be called for the various events.
  211. # If called manually SCRIPTUP is selected.
  212. EOF
  213.  
  214.     if [ $SCRIPT_up[$_cfg] ]; then
  215.     echo "SCRIPTUP=\"${SCRIPT_up[$_cfg]}\"" >> $_hwcfg_file
  216.     fi
  217.     if [ $SCRIPT_ccw[$_cfg] ]; then
  218.     echo "SCRIPTUP_ccw=\"${SCRIPT_ccw[_cfg]}\"" >> $_hwcfg_file
  219.     fi
  220.     if [ $SCRIPT_ccw[$_cfg] ]; then
  221.     echo "SCRIPTUP_ccwgroup=\"${SCRIPT_ccwgroup[_cfg]}\"" >> $_hwcfg_file
  222.     fi
  223.     if [ ${SCRIPT_down[$_cfg]} ]; then
  224.     echo "SCRIPTDOWN=\"${SCRIPT_down[$_cfg]}\"" >> $_hwcfg_file
  225.     fi
  226.  
  227.     cat >> $_hwcfg_file <<EOF
  228.  
  229. # CCW_CHAN_IDS sets the channel IDs for this device
  230. # The first ID will be used as the group ID
  231. CCW_CHAN_IDS="${CCW_CHAN_IDS[$_cfg]}"
  232.  
  233. # CCW_CHAN_NUM set the number of channels for this device
  234. CCW_CHAN_NUM="${CCW_CHAN_NUM[$_cfg]}"
  235.  
  236. EOF
  237.     if [ "$_devname" = "ctc" -o "$_devname" = "escon" ]; then
  238.     cat >> $_hwcfg_file <<EOF
  239. # CCW_CHAN_MODE sets the protocol for CTC / ESCON
  240. # 0 for compability mode (default)
  241. # 1 for extended mode
  242. # 2 for CTC-based tty
  243. # 3 for compability mode with OS/390 and z/OS
  244. EOF
  245.     if [ ${CCW_CHAN_MODE[$_cfg]} ]; then
  246.         echo "CCW_CHAN_MODE=\"${CCW_CHAN_MODE[$_cfg]}\"" >> $_hwcfg_file
  247.     else
  248.         echo "# CCW_CHAN_MODE=0" >> $_hwcfg_file
  249.     fi
  250.     echo >> $_hwcfg_file
  251.     elif [ "$_devname" = "lcs" ]; then
  252.     cat >> $_hwcfg_file <<EOF
  253. # CCW_CHAN_MODE sets the port number for LCS
  254. # Port number 0 is the default
  255. EOF
  256.     if [ ${CCW_CHAN_MODE[$_cfg]} ]; then
  257.         echo "CCW_CHAN_MODE=\"${CCW_CHAN_MODE[$_cfg]}\"" >> $_hwcfg_file
  258.     else
  259.         echo "# CCW_CHAN_MODE=0" >> $_hwcfg_file
  260.     fi
  261.     echo >> $_hwcfg_file
  262.     else
  263.     cat >> $_hwcfg_file <<EOF
  264. # CCW_CHAN_MODE sets the portname for OSA-Express / Hipersockets
  265. EOF
  266.     if [ ${CCW_CHAN_MODE[$_cfg]} ]; then
  267.         echo "CCW_CHAN_MODE=\"${CCW_CHAN_MODE[$_cfg]}\"" >> $_hwcfg_file
  268.     else
  269.         echo "# CCW_CHAN_MODE=\"\"" >> $_hwcfg_file
  270.     fi
  271.     echo >> $_hwcfg_file
  272.     fi
  273.     echo Wrote ${CFGNAME[$_cfg]}
  274. done
  275.  
  276. exit $retval
  277.