Magellan Linux

Contents of /trunk/udev/config-udev-103-r3/seq_node.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 89 - (show annotations) (download) (as text)
Tue Dec 26 12:34:36 2006 UTC (17 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 1631 byte(s)
import

1 #!/bin/bash
2 # Copyright 1999-2006 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # Author: Martin Schlemmer <azarah@gentoo.org>
5 # $Header: /root/magellan-cvs/src/udev/config-udev-103-r3/seq_node.sh,v 1.1 2006-12-26 12:34:36 niro Exp $
6
7 # Stupid little script to emulate the depriciated '%e' directive of udev.
8 # I am not sure why its supposidly broken, so this might need fixing if it
9 # have the same issue as '%e'.
10 #
11 # Usage: seq_node.sh <root> <kernel name> <wanted node>
12 #
13 # root - root of udev (usuall /dev)
14 # kernel name - kernel name for device
15 # wanted node - needed free node
16 #
17 # Example: seq_node.sh %r %k cdrom
18 #
19 # If called as above, it should return 'cdrom' if free, else 'cdrom1',
20 # 'cdrom2', etc. It also checks if an existing node was already created for
21 # the specific 'kernel name'.
22 #
23
24 root=$1
25 kname=$2
26 node=$3
27
28 count=0
29 new_node=${node}
30
31 if [[ -z ${root} || -z ${kname} || -z ${node} ]] ; then
32 exit 1
33 fi
34
35 get_filename() {
36 local symlink=$1
37 local filename=
38
39 if [[ ! -L ${root}/${symlink} ]] ; then
40 echo "${symlink}"
41 return 0
42 fi
43
44 if type -p readlink &>/dev/null ; then
45 filename=$(readlink "${root}/${symlink}")
46 else
47 filename=$(perl -e "print readlink(\"${root}/${symlink}\")" 2>/dev/null)
48 fi
49
50 echo "${filename}"
51 }
52
53 while [[ -e "${root}/${new_node}" || -L "${root}/${new_node}" ]] ; do
54 # Check if existing node is the same as the kname we are looking
55 # for a new node, and return that instead
56 if [[ $(get_filename "${new_node}") == "${kname}" ]] ; then
57 break
58 fi
59
60 let "count += 1"
61 new_node="${node}${count}"
62 done
63
64 echo "${new_node}"
65
66 exit 0
67