home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Complet / emovix / eMovix-0.9.0pre1_Setup.exe / {app} / src / movix / rc.lirc < prev    next >
Encoding:
Text File  |  2003-11-30  |  2.5 KB  |  104 lines

  1. #!/usr/bin/perl
  2.  
  3. ### This is needed because for some strange bug only the first two user boot args
  4. ### are actually exported as env variables
  5. readRCFile();
  6. loadBootParm();
  7.  
  8. $LOG="/tmp/modprobe.log";
  9. $ERR="/tmp/modprobe.err";
  10.  
  11. #exit if ! defined $ENV{'REMOTE'};
  12. ### it's much better to have a default :-)
  13. $REMOTE = ! defined $ENV{'REMOTE'} ? "hauppauge" : $ENV{'REMOTE'};
  14.  
  15. readRemotesData();
  16.  
  17. die "I do not know the remote \"$REMOTE\", your remote won't be started :-(\n"
  18.   unless exists $REMOTE_DEV{$REMOTE};
  19. install("lircd.conf","/etc",$REMOTE);
  20. install("lircrc","/root",$REMOTE);
  21. `ln -s /root/lircrc /root/.lircrc`;
  22.  
  23. `modprobe -s af_packet >> $LOG 2>> $ERR`;
  24. `modprobe -s unix      >> $LOG 2>> $ERR`;
  25.  
  26.  
  27. if (@{$REMOTE_MOD{$REMOTE}}[0] eq lirc_serl){
  28. #    print "loading Serial LIRC support\n";
  29. #    `depmod`;
  30.     `mknod /dev/lirc c 61 0`;
  31.     `mknod /dev/lircd c 61 0`;
  32.     `modprobe serial`;
  33.     `setserial /dev/ttyS0 uart none`;
  34.     `modprobe lirc_serial`;
  35. } else {
  36.     foreach (@{$REMOTE_MOD{$REMOTE}}){
  37.       `modprobe -s $_ >> $LOG 2>> $ERR`
  38.     }
  39. }
  40. if( -e "$REMOTE_DEV{$REMOTE}" ){
  41.   `lircd -d $REMOTE_DEV{$REMOTE} -H $REMOTE_DRV{$REMOTE}`;
  42. } else {
  43.   foreach (@{$REMOTE_MOD{$REMOTE}}){
  44.     `rmmod $_ >> $LOG 2>> $ERR`
  45.   }
  46. }
  47.  
  48. ######################################################
  49.  
  50. sub readRemotesData {
  51.   my @data = split "\n", `find / -name remotes.data`;
  52.   my $confFile=@data[0];
  53.  
  54.   @data = split "\n", `cat "$confFile"`;
  55.   foreach (@data){
  56.     /^(\w+)\s+(\w+)\s+([^\s]+)\s+([^\s]+)\s*$/ or
  57.       die "remotes data file is broken, can't understand line \"$_\"\n";
  58.     $REMOTE_DRV{$1} = $2;
  59.     $REMOTE_DEV{$1} = $3;
  60.     my @tmp = split ",", $4;
  61.     $REMOTE_MOD{$1} = \@tmp;
  62.   }
  63. }
  64.  
  65. sub install {
  66.   my $file  = shift;
  67.   my $dir   = shift; 
  68.   my $model = shift;
  69.   `rm -f $dir/$file`;
  70.   
  71.   my @data = split "\n",  `find / -name $file.$model`;
  72.   my $confFile=@data[0];
  73.  
  74.   print "$confFile\n";
  75.   if( -e "$confFile" ){
  76.     `cp $confFile $dir/$file`;
  77.   } elsif( $file =~ /^lircrc/ ){
  78.     ### use the hauppauge file if no specific lircrc is available
  79.     $confFile=`find / -name $file.hauppauge`;
  80.     `cp $confFile $dir/$file`;
  81.   } else {
  82.     die "can't find $confFile for: $file.$model :-(\n";
  83.   }
  84. }
  85.  
  86. sub loadBootParm {
  87.   foreach (split " ", `cat /proc/cmdline`) {
  88.     next unless /^([^\=]+)\=(.+)$/;
  89.     $ENV{$1} = $2;
  90.   }
  91. }
  92.  
  93. sub readRCFile {
  94.   my $bootrc = "/root/.bootrc";
  95.   return unless -e "$bootrc";
  96.   open RC, "$bootrc";
  97.   while(<RC>){
  98.     next if /^\#/ or /^\s*$/;
  99.     next unless /^([^=]+)=(.+)$/;
  100.     $ENV{$1}=$2;
  101.   }
  102.   close RC;
  103. }
  104.