Package: irda-utils
Version: 0.9.18-10
Severity: normal
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu lucid ubuntu-patch

Hello,

Here is an updated version of the patch, taken from the current Ubuntu
package; it applies cleanly to irda-utils 0.9.18-10, and includes a couple
of fixes (e.g., not using bashisms in an init script that runs with
/bin/sh).

It could probably use a bit more cleanup (fix the irda-start script to also
run with dash; and should this just be a udev rule instead of an init
script?; if you are interested in applying the patch, let me know and I can
try to take care of this cleanup.

-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slanga...@ubuntu.com                                     vor...@debian.org
=== modified file 'debian/config'
--- debian/config       2004-09-16 15:30:07 +0000
+++ debian/config       2009-12-23 02:15:31 +0000
@@ -15,19 +15,22 @@
 # preinst has to retrieve the old values first.
 if [ ! -e "$CONFIG_OLD" ]; then
     STATE=1
-    LASTSTATE=4
+    LASTSTATE=5
     while [ $STATE -gt 0 -a $STATE -le $LASTSTATE ]; do
         case $STATE in
         1)
             db_input medium $PACKAGE/enable || true
         ;;
         2)
+            db_input medium $PACKAGE/automatic || true
+        ;;
+        3)
             db_input medium $PACKAGE/discovery || true
         ;;
-        3)
+        4)
             db_input medium $PACKAGE/selectdevice || true
         ;;
-        4)
+        5)
             db_get $PACKAGE/selectdevice
             if [ "$RET" = "serial" ]; then
                 db_input medium $PACKAGE/ttydev || true

=== modified file 'debian/irda-utils.init'
--- debian/irda-utils.init      2009-12-04 13:27:26 +0000
+++ debian/irda-utils.init      2009-12-23 05:09:20 +0000
@@ -55,6 +55,11 @@
 if [ -f /etc/default/$PACKAGE ]; then
     . /etc/default/$PACKAGE
 fi
+if [ "$AUTOMATIC" = "true" ] && [ -f /var/run/irdadev ]; then
+# We discovered a device on boot. Attempt to bind to it.
+    ENABLE="true"
+    read DEVICE JUNK </var/run/irdadev
+fi
 if [ "$ENABLE" = "false" ]; then
     log_action_begin_msg "Skipping $DESC:" "$NAME (not enabled)"
     log_action_end_msg 0

=== added file 'debian/irda-utils.irda-setup.init'
--- debian/irda-utils.irda-setup.init   1970-01-01 00:00:00 +0000
+++ debian/irda-utils.irda-setup.init   2009-12-23 02:15:35 +0000
@@ -0,0 +1,118 @@
+#!/bin/bash
+
+. /etc/default/irda-utils
+
+test "$AUTOMATIC" = "true" || exit 0
+
+test -d /sys/bus/pnp/devices || exit 0
+
+cd /sys/bus/pnp/devices
+
+IRDA=0;
+STATEFILE=/var/run/irdadev;
+
+case $1 in
+    start|restart|reload|force-reload)
+    for x in *; do
+       FIR="false";
+       SIR="false";
+       FALLBACK=true;
+       OPTIONS=""
+       for y in `cat $x/id`; do
+           case "$y" in
+               PNP0510|PNP0511)
+               SIR="true";
+               ;;
+               NSC*)
+               FIR="nsc-ircc";
+               ;;
+               IBM0071)
+               FIR="nsc-ircc";
+               OPTIONS="dongle_id=0x09";
+               ;;
+               SMC*)
+               FIR="smsc-ircc2";
+               ;;          
+               ALI5123)
+               FIR="ali-ircc";
+               ;;
+               VIA3076)
+               FIR="via-ircc"
+           esac
+       done
+
+       if [ $FIR = "false" -a $SIR = "false" ]; then
+               continue;
+       fi
+       
+    # Work out resource ranges, so we know which serial port to work with
+       PORTS=`grep io $x/resources | sed -e 's/io \(.*\)-.*/\1/'`
+       for PORT in $PORTS; do
+               case $PORT in
+               0x3f8)
+               PORT="/dev/ttyS0"
+               break;
+               ;;
+               0x2f8)
+               PORT="/dev/ttyS1"
+               break;
+               ;;
+               0x3e8)
+               PORT="/dev/ttyS2"
+               break;
+               ;;
+               0x2e8)
+               PORT="/dev/ttyS3"
+               break;
+               ;;
+               default)
+               PORT="UNKNOWN"
+               ;;
+               esac;
+       done
+
+       if [ "$FIR" != "false" ]; then
+           # The BIOS doesn't always activate the device. Prod it
+           echo disable >$x/resources;
+           echo activate >$x/resources;
+
+           UART="unknown";
+           if [ "$PORT" != "UNKNOWN" ]; then
+           # We should attempt to disable the UART. However, we need to store
+           # it - there's a chance that things could still go horribly wrong
+               UART=`setserial $PORT | sed 's/.*UART: \(.*\), Port.*/\1/'`
+               setserial $PORT uart none
+           fi
+           modprobe $FIR $OPTIONS;
+           if [ "$?" = "0" ]; then
+               echo "irda$IRDA fir" >$STATEFILE;
+               let "IRDA=$IRDA+1";
+               continue;
+           else
+           # Try to recover
+               if [ "$UART" != "undefined" ]; then
+                       setserial $PORT uart $UART;
+               fi
+           fi
+       fi
+       
+       if [ "$SIR" = "true" -o "$FIR" != "false" ]; then
+           # We'll only have got here if the FIR module has failed
+
+           if [ "$PORT" != "UNKNOWN" ]; then
+           # The BIOS doesn't always activate the device. Prod it
+               echo disable >$x/resources;
+               echo activate >$x/resources;
+
+           # The IRQ is not always set correctly, so try to deal with that
+               IRQ=`grep irq $x/resources | sed -e 's/irq \(.*\)/\1/'`
+               setserial $PORT irq $IRQ;
+               echo "$PORT sir" >$STATEFILE;
+           fi
+       fi
+    done
+    ;;
+    stop)
+    exit 0
+    ;;
+esac

=== modified file 'debian/postinst'
--- debian/postinst     2009-12-04 13:27:26 +0000
+++ debian/postinst     2009-12-23 02:17:54 +0000
@@ -64,6 +64,10 @@
 # to 'true'.
 ENABLE=
 
+# Set this to 'false' if you do not want automatic discovery of irda devices.
+# If 'true', it will automatically start irattach if devices are found.
+AUTOMATIC=
+
 # Set discovery mode which usually is a good idea for finding other devices.
 # If set 'true' or 'false' irattach and sysctl are used to enable and disable
 # discovery mode. By default discover mode is disabled.
@@ -98,6 +102,8 @@
     # read config
     db_get $PACKAGE/enable
     ENABLE="$RET"
+    db_get $PACKAGE/automatic
+    AUTOMATIC="$RET"
     db_get $PACKAGE/discovery
     DISCOVERY="$RET"
     if [ "$DEVICE" = "serial" ]; then
@@ -116,6 +122,7 @@
 
     # re-insert values deleted in $CONFIG but existant in debconf
     test -z "$ENABLE" || grep -Eq '^ *ENABLE=' $CONFIG || echo "ENABLE=" >> 
$CONFIG
+    test -z "$AUTOMATIC" || grep -Eq '^ *AUTOMATIC=' $CONFIG || echo 
"AUTOMATIC=" >> $CONFIG
     test -z "$DISCOVERY" || grep -Eq '^ *DISCOVERY=' $CONFIG || echo 
"DISCOVERY=" >> $CONFIG
     test -z "$DEVICE" || grep -Eq '^ *DEVICE=' $CONFIG || echo "DEVICE=" >> 
$CONFIG
     test -z "$DONGLE" || grep -Eq '^ *DONGLE=' $CONFIG || echo "DONGLE=" >> 
$CONFIG
@@ -125,6 +132,7 @@
     # all comments and other variables defined by the admin
     sed -e "
         s#^ *ENABLE=.*#ENABLE=\"$ENABLE\"#
+        s#^ *AUTOMATIC=.*#AUTOMATIC=\"$AUTOMATIC\"#
         s#^ *DISCOVERY=.*#DISCOVERY=\"$DISCOVERY\"#
         s#^ *DEVICE=.*#DEVICE=\"$DEVICE\"#
         s#^ *DONGLE=.*#DONGLE=\"$DONGLE\"#
=== modified file 'debian/preinst'
--- debian/preinst      2009-06-01 17:50:24 +0000
+++ debian/preinst      2009-12-23 02:15:39 +0000
@@ -107,6 +107,8 @@
     # store values from current config
     db_set $PACKAGE/enable $ENABLE
 
+    db_set $PACKAGE/automatic $AUTOMATIC
+
     case "$DEVICE" in
         /dev/ttyS*)
             db_set $PACKAGE/selectdevice serial

=== modified file 'debian/rules'
--- debian/rules        2009-06-01 17:50:24 +0000
+++ debian/rules        2009-12-23 02:15:40 +0000
@@ -117,8 +117,7 @@
 #      dh_installmenu
 #      dh_installemacsen
        dh_installinit
+       dh_installinit -r --no-start --name=irda-setup -- start 47 S .
 #      dh_installcron
        dh_installdebconf
        if [ "$(DEB_BUILD_GNU_TYPE)" = "i486-linux-gnu" -o 
"$(DEB_BUILD_GNU_TYPE)" = "x86_64-linux-gnu" ]; then \

=== modified file 'debian/templates'
--- debian/templates    2008-05-04 14:24:21 +0000
+++ debian/templates    2009-12-23 02:15:41 +0000
@@ -58,3 +58,10 @@
  Confirm if you want IrDA to be enabled when your system is booting. This is
  necessary for devices that need "irattach" to be run. Most devices need it,
  except for some rare FIR devices.
+
+Template: irda-utils/automatic
+Type: boolean
+Default: true
+_Description: Attempt to probe for IrDA on system bootup?
+ Confirm if you want to attempt to autoconfigure IrDA on system startup. If 
+ a device is found, irattach will automatically be started up.

Reply via email to