~ubuntu-branches/ubuntu/breezy/joystick/breezy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl

sub err {
   print STDERR $_[0];
   exit 1;
}

sub fix {
   # remove old nodes, create new, restore permisions
   unlink $_[0];
   system("mknod ".$_[0]." c ".$_[1]." ".$_[2]);
   chmod $_[3], $_[0];
   chown $_[4], $_[5], $_[0];
}

# new kernel detection
open(fh,"</proc/version");
if(<fh> =~ /Linux version \d\.(\d)\.\d/) {
   $newvers = $1 if($1 > 3);
}
else {
   err("/proc not mounted, aborting.");
}

@nodes = </dev/js*>;
err("Oops, please create some joystick device nodes with MAKEDEV first!") if($#nodes < 0);

# read modes and resolve links when needed
for(@nodes) {
   @mode = lstat;
   if(!defined($newvers) && ($mode[6] < 3500) ) { # old kernel, new device
      $rec = 1;
      fix($_, 15, ($mode[6] % 256), $mode[2], $mode[4], $mode[5]);
      print "Recreating $_\n";
   }
   if(defined($newvers) && ($mode[6] > 3500) ) { # new kernel, old device
      $rec = 1;
      fix($_, 13, ($mode[6] % 256), $mode[2], $mode[4], $mode[5]);
      print "Recreating $_\n";
   }
}
if(!defined($rec)) { print "device files are okay!\n" }