#! /bin/sh
#----------------------------------------------------------------------
# create-devices
#
# Creation:     2007-10-09 hbfl
# Last Update:  $Id$
#
# Copyright (c) 2007 the eisfair team, team(at)eisfair(dot)org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#---------------------------------------------------------------------
#exec 2>create-devices-trace$$.log
#set -x
FOLDER=/dev/

# create hd devices
rm -f /dev/hd[efgh]{17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}

HD_DEVICES="a:3:0:16
            b:3:64:16
            c:22:0:16
            d:22:64:16
            e:33:0:16
            f:33:64:16
            g:34:0:16
            h:34:64:16
            i:56:0:16
            j:56:64:16
            k:57:0:16
            l:57:64:16
            m:88:0:16
            n:88:64:16
            o:89:0:16
            p:89:64:16
            q:90:0:16
            r:90:64:16
            s:91:0:16
            t:91:64:16"

for hd in ${HD_DEVICES}
do
        _OLD_IFS=${IFS}
        IFS=:
        set -- ${hd}

        if [ ! -b "${FOLDER}hd${1}" ]
        then
                mknod ${FOLDER}hd${1} b ${2} ${3}
        fi

        idx=1
        idy=`/usr/bin/expr ${3} + 1`
        while [ ${idx} -le ${4} ]
        do
                if [ ! -b "${FOLDER}hd${1}${idx}" ]
                then
                        mknod ${FOLDER}hd${1}${idx} b ${2} ${idy}
                fi
                idx=`/usr/bin/expr ${idx} + 1`
                idy=`/usr/bin/expr ${idy} + 1`
        done
        IFS=${_OLD_IFS}
done
chown root.root ${FOLDER}hd{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t}*
chmod 0660 ${FOLDER}hd{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t}*

idx=0
while [ ${idx} -le 3 ]
do
        if [ ! -c "${FOLDER}parport${idx}" ]
        then
                mknod ${FOLDER}parport${idx} c 99 ${idx}
                chmod 0660 ${FOLDER}parport${idx}
                chown root:root ${FOLDER}parport${idx}
        fi
        idx=`/usr/bin/expr ${idx} + 1`
done

PTY_DEVICES="a:176
             b:192
             c:208
             d:224
             e:240
             p:0
             q:16
             r:32
             s:48
             t:64
             u:80
             v:96
             w:112
             x:128
             y:144
             z:160"

PTY_SUB_DEVICES="0 1 2 3 4 5 6 7 8 9 a b c d e f"

for pty in ${PTY_DEVICES}
do
        _OLD_IFS=${IFS}
        IFS=:
        set -- ${pty}

        IFS=${_OLD_IFS}

        idx=${2}
        for pty_sub in ${PTY_SUB_DEVICES}
        do
                if [ ! -c "${FOLDER}pty${1}${pty_sub}" ]
                then
                        mknod ${FOLDER}pty${1}${pty_sub} c 2 ${idx}
                fi
                idx=`/usr/bin/expr ${idx} + 1`
        done
done
chown root.tty ${FOLDER}pty*
chmod 0666 ${FOLDER}pty*