#!/bin/sh
#
# Copyright (C) 2001-2006  PEAK System-Technik GmbH
#
# linux@peak-system.com
# www.peak-system.com
#
# This is a small script to generate device node entries at /dev for
# PCAN devices. The script uses the entries from /proc/devices.
# This means the driver have to be installed before using the script.
#
# Maintainer: Klaus Hitschler (klaus.hitschler@gmx.de)
#
# $Id: pcan_make_devices 388 2006-05-07 14:54:10Z khitschler $
#
group="root"
mode="666"

if test $UID -ne 0; then
  echo "ERROR: you must be root to use pcan_make_devices!"
  echo ""
  exit 1
fi

# check command line arguments
if test $# -le 0; then
  echo "ERROR: please provide the number of devices per interface type!"
  echo "usage: pcan_make_devices n"
  echo ""
  exit 1
fi

# get major number from /proc/devices
major=`cat /proc/devices | awk "\\$2==\"pcan\" {print \\$1}"`

# make device nodes
if test "$major"; then
  j=0;
  while test $j -le 44; do
    k=$[$j + ($1 - 1)];
    i=$j;
    while test $i -le $k; do
      rm -f /dev/pcan$i;
      mknod /dev/pcan$i c $major $i;
      chgrp $group /dev/pcan$i;
      chmod $mode  /dev/pcan$i;
      i=$[$i + 1];
    done;
  j=$[$j + 8];
  done;
else
  echo "Please do first a \"insmod pcan.o or insmod pcan.ko ... (depends on kernel version)\"";
fi

# end of script

