Hi Frederic,
Attached is the diff for libgphoto2 2.1.6-4.1 which adds udev support
to libgphoto2-2.
I left the README.Debian update up to you, as you'll probably want to
rewrite it.
Please send print-udev-rules.c upstream.
JB.
--
Julien BLACHE <[EMAIL PROTECTED]> | Debian, because code matters more
Debian & GNU/Linux Developer | <http://www.debian.org>
Public key available on <http://www.jblache.org> - KeyID: F5D6 5169
GPG Fingerprint : 935A 79F1 C8B3 3521 FD62 7CC7 CD61 4FD7 F5D6 5169
diff -u libgphoto2-2.1.6/debian/changelog libgphoto2-2.1.6/debian/changelog
--- libgphoto2-2.1.6/debian/changelog
+++ libgphoto2-2.1.6/debian/changelog
@@ -1,3 +1,15 @@
+libgphoto2 (2.1.6-4.1) unstable; urgency=low
+
+ * Non-Maintainer Upload.
+ * Derived print-udev-rules from print-usb-usermap to generate the udev
+ rules file.
+ * debian/libgphoto2-2.postinst: call print-udev-rules, create the symlink
+ in /etc/udev/rules.d if needed (closes: #332936).
+ * debian/hotplug: use chown user:group instead of chown user.group.
+ * debian/control: libgphoto2-2 Recommends: udev | hotplug
+
+ -- Julien BLACHE <[EMAIL PROTECTED]> Mon, 10 Oct 2005 20:40:53 +0200
+
libgphoto2 (2.1.6-4) unstable; urgency=low
* camlibs/ptp2/library.c: ported (kludgy) patch to work with HP
diff -u libgphoto2-2.1.6/debian/hotplug libgphoto2-2.1.6/debian/hotplug
--- libgphoto2-2.1.6/debian/hotplug
+++ libgphoto2-2.1.6/debian/hotplug
@@ -7,7 +7,7 @@
# check if $GROUP really exists
if getent group $GROUP > /dev/null; then
chmod 660 "$DEVICE"
- chown root.$GROUP "$DEVICE"
+ chown root:$GROUP "$DEVICE"
fi
fi
diff -u libgphoto2-2.1.6/debian/libgphoto2-2.postinst libgphoto2-2.1.6/debian/libgphoto2-2.postinst
--- libgphoto2-2.1.6/debian/libgphoto2-2.postinst
+++ libgphoto2-2.1.6/debian/libgphoto2-2.postinst
@@ -15,6 +15,16 @@
# create USB usermap
test -e /usr/lib/$PACKAGE/print-usb-usermap && \
/usr/lib/$PACKAGE/print-usb-usermap $PACKAGE > /etc/hotplug/usb/$PACKAGE.usermap
+ # create udev rules file
+ if [ -e /usr/lib/$PACKAGE/print-udev-rules ]; then
+ /usr/lib/$PACKAGE/print-udev-rules /etc/hotplug/usb/$PACKAGE > /etc/udev/$PACKAGE.rules
+ # install the udev file only once:
+ # - the first time the package is installed
+ # OR - the first time the package is upgraded from a version earlier than 2.1.6-4.1
+ if [ -z "$2" ] || dpkg --compare-versions "$2" lt 2.1.6-4.1 ; then
+ ln -sf ../$PACKAGE.rules /etc/udev/rules.d/025_$PACKAGE.rules
+ fi
+ fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
diff -u libgphoto2-2.1.6/debian/control libgphoto2-2.1.6/debian/control
--- libgphoto2-2.1.6/debian/control
+++ libgphoto2-2.1.6/debian/control
@@ -38,6 +38,7 @@
Architecture: any
Conflicts: gphoto2 (<= 2.1.1)
Depends: ${shlibs:Depends}, adduser
+Recommends: ${udev-hotplug}
Suggests: gphoto2 (>= 2.1.1), gtkam
Description: gphoto2 digital camera library
The gphoto2 library can be used by applications to access various
diff -u libgphoto2-2.1.6/debian/rules libgphoto2-2.1.6/debian/rules
--- libgphoto2-2.1.6/debian/rules
+++ libgphoto2-2.1.6/debian/rules
@@ -5,6 +5,14 @@
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
+DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
+ifeq ($(DEB_HOST_ARCH_OS),)
+ DEB_HOST_ARCH_OS := $(subst -gnu,,$(shell dpkg-architecture -qDEB_HOST_GNU_SYSTEM))
+ ifeq ($(DEB_HOST_ARCH_OS),gnu)
+ DEB_HOST_ARCH_OS := hurd
+ endif
+endif
+
major=2
CFLAGS = -g
@@ -97,7 +105,11 @@
dh_shlibdeps -ldebian/libgphoto2-$(major)/usr/lib/:debian/libgphoto2-port0/usr/lib/
dh_gencontrol -plibgphoto2-$(major)-dev
dh_gencontrol -plibgphoto2-port0
+ifeq (linux,$(DEB_HOST_ARCH_OS))
+ dh_gencontrol -plibgphoto2-$(major) -- -Vudev-hotplug="udev | hotplug"
+else
dh_gencontrol -plibgphoto2-$(major)
+endif
dh_md5sums
dh_builddeb
diff -u libgphoto2-2.1.6/debian/control.in libgphoto2-2.1.6/debian/control.in
--- libgphoto2-2.1.6/debian/control.in
+++ libgphoto2-2.1.6/debian/control.in
@@ -38,6 +38,7 @@
Architecture: any
Conflicts: gphoto2 (<= 2.1.1)
Depends: ${shlibs:Depends}, adduser
+Recommends: ${udev-hotplug}
Suggests: gphoto2 (>= 2.1.1), gtkam
Description: gphoto2 digital camera library
The gphoto2 library can be used by applications to access various
diff -u libgphoto2-2.1.6/debian/libgphoto2-2.files.in libgphoto2-2.1.6/debian/libgphoto2-2.files.in
--- libgphoto2-2.1.6/debian/libgphoto2-2.files.in
+++ libgphoto2-2.1.6/debian/libgphoto2-2.files.in
@@ -6,0 +7 @@
[EMAIL PROTECTED]@ usr/lib/libgphoto2/print-udev-rules
only in patch2:
unchanged:
--- libgphoto2-2.1.6.orig/packaging/linux-hotplug/print-udev-rules.c
+++ libgphoto2-2.1.6/packaging/linux-hotplug/print-udev-rules.c
@@ -0,0 +1,240 @@
+/* $Id$
+ *
+ * Copyright © 2002 Hans Ulrich Niedermann <[EMAIL PROTECTED]>
+ * Portions Copyright © 2002 Lutz Müller <[EMAIL PROTECTED]>
+ * Portions Copyright © 2002 FIXME
+ * Portions Copyright © 2005 Julien BLACHE <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#define GP_USB_HOTPLUG_SCRIPT "/etc/hotplug/usb/usbcam"
+
+#define HELP_TEXT \
+"print-udev-rules - print rules file for udev\n" \
+"\n" \
+"Syntax:\n" \
+" print-udev-rules [ --verbose ] [ --debug ] [ <scriptname> ]\n" \
+"\n" \
+" --verbose also print comments with camera model names\n" \
+" --debug print all debug output\n" \
+"\n" \
+"print-udev-rules prints the lines for the rules file on stdout.\n" \
+"All other messages are printed on stderr. In case of any error, the \n" \
+"program aborts regardless of data printed on stdout and returns a non-zero\n" \
+"status code.\n" \
+"If no <scriptname> is given, print-udev-rules uses the script name\n" \
+"\"" GP_USB_HOTPLUG_SCRIPT "\"."
+
+#include <stdio.h>
+#include <sys/time.h>
+#include <time.h>
+#include <string.h>
+
+#include <gphoto2-camera.h>
+#include <gphoto2-port-log.h>
+
+#ifndef TRUE
+#define TRUE (0==0)
+#endif
+#ifndef FALSE
+#define FALSE (0!=0)
+#endif
+
+#define GP_USB_HOTPLUG_MATCH_VENDOR_ID 0x0001
+#define GP_USB_HOTPLUG_MATCH_PRODUCT_ID 0x0002
+
+#define GP_USB_HOTPLUG_MATCH_DEV_CLASS 0x0080
+#define GP_USB_HOTPLUG_MATCH_DEV_SUBCLASS 0x0100
+#define GP_USB_HOTPLUG_MATCH_DEV_PROTOCOL 0x0200
+
+#ifdef __GNUC__
+#define CR(result) \
+ do { \
+ int r = (result); \
+ if (r < 0) { \
+ fprintf(stderr, "print-usb-usermap: " \
+ "Fatal error running `%s'.\n" \
+ "Aborting.\n", #result ); \
+ return (r); \
+ } \
+ } while (0)
+#else /* !__GNUC__ */
+#define CR(result) \
+ do { \
+ int r = (result); \
+ if (r < 0) { \
+ fprintf(stderr, "print-usb-usermap: " \
+ "Fatal error detected, aborting.\n"); \
+ return (r); \
+ } \
+ } while (0)
+#endif /* __GNUC__ */
+
+/* print-udev-rules
+ *
+ * Print out lines that can be included into an udev rules file
+ * - for all cams supported by our instance of libgphoto2.
+ *
+ * written after list_cameras & print_usb_usermap
+ */
+
+static int print_udev_rules (const char *hotplug_script, const int add_comments)
+{
+ int x, n;
+ CameraAbilitiesList *al;
+ CameraAbilities a;
+
+ CR (gp_abilities_list_new (&al));
+ CR (gp_abilities_list_load (al, NULL)); /* use NULL context */
+ CR (n = gp_abilities_list_count (al));
+
+ printf ("# udev rules file for libgphoto2\n#\n");
+ printf ("BUS!=\"usb\", ACTION!=\"add\", GOTO=\"libgphoto2_rules_end\"\n\n");
+
+ for (x = 0; x < n; x++) {
+ int flags = 0;
+ int class = 0, subclass = 0, proto = 0;
+ int usb_vendor = 0, usb_product = 0;
+
+ CR (gp_abilities_list_get_abilities (al, x, &a));
+
+ if (!(a.port & GP_PORT_USB))
+ continue;
+
+ if (a.usb_vendor) { /* usb product id may be 0! */
+ class = 0;
+ subclass = 0;
+ proto = 0;
+ flags = GP_USB_HOTPLUG_MATCH_VENDOR_ID | GP_USB_HOTPLUG_MATCH_PRODUCT_ID;
+ usb_vendor = a.usb_vendor;
+ usb_product = a.usb_product;
+ } else if (a.usb_class) {
+ class = a.usb_class;
+ subclass = a.usb_subclass;
+ proto = a.usb_protocol;
+ flags = GP_USB_HOTPLUG_MATCH_DEV_CLASS;
+ if (subclass != -1)
+ flags |= GP_USB_HOTPLUG_MATCH_DEV_SUBCLASS;
+ else
+ subclass = 0;
+ if (proto != -1)
+ flags |= GP_USB_HOTPLUG_MATCH_DEV_PROTOCOL;
+ else
+ proto = 0;
+ usb_vendor = 0;
+ usb_product = 0;
+ } else {
+ flags = 0;
+ }
+
+ if (flags != 0) {
+ printf ("# %s\n",
+ a.model);
+
+ if (flags & GP_USB_HOTPLUG_MATCH_DEV_CLASS) {
+ printf("SYSFS{bDeviceClass}==\"%02x\", ", class);
+ if (flags & GP_USB_HOTPLUG_MATCH_DEV_SUBCLASS) {
+ printf("SYSFS{bDeviceSubClass}==\"%02x\", ", subclass);
+ }
+ if (flags & GP_USB_HOTPLUG_MATCH_DEV_PROTOCOL) {
+ printf("SYSFS{bDeviceProtocol}==\"%02x\", ", proto);
+ }
+ } else {
+ printf ("SYSFS{idVendor}==\"%04x\", SYSFS{idProduct}==\"%04x\", ",
+ a.usb_vendor, a.usb_product);
+ }
+ printf("RUN+=\"%s\"\n", hotplug_script);
+ } else {
+ fputs ("Error: Neither vendor/product nor class/subclass matched\n", stderr);
+ return 2;
+ }
+ }
+ printf ("\nLABEL=\"libgphoto2_rules_end\"\n");
+
+ CR (gp_abilities_list_free (al));
+
+ return (0);
+}
+
+/* time zero for debug log time stamps */
+struct timeval glob_tv_zero = { 0, 0 };
+
+static void
+debug_func (GPLogLevel level, const char *domain, const char *format,
+ va_list args, void *data)
+{
+ struct timeval tv;
+ gettimeofday (&tv,NULL);
+ fprintf (stderr, "%li.%06li %s(%i): ",
+ tv.tv_sec - glob_tv_zero.tv_sec,
+ (1000000 + tv.tv_usec - glob_tv_zero.tv_usec) % 1000000,
+ domain, level);
+ vfprintf (stderr, format, args);
+ fprintf (stderr, "\n");
+}
+
+int main(int argc, char *argv[])
+{
+ char *hotplug_script = NULL; /* script name to use */
+ int add_comments = FALSE; /* whether to add cam model as a comment */
+ int debug_mode = FALSE; /* whether we should output debug messages */
+
+ int i;
+
+ /* check command line arguments */
+ for (i=1; i<argc; i++) {
+ if (0 == strcmp(argv[i], "--verbose")) {
+ if (add_comments) {
+ fprintf(stderr, "Error: duplicate parameter: option \"%s\"\n", argv[i]);
+ return 1;
+ }
+ add_comments = TRUE;
+ } else if (0 == strcmp(argv[i], "--debug")) {
+ if (debug_mode) {
+ fprintf(stderr, "Error: duplicate parameter: option \"%s\"\n", argv[i]);
+ return 1;
+ }
+ debug_mode = TRUE;
+ /* now is time zero for debug log time stamps */
+ gettimeofday (&glob_tv_zero, NULL);
+ gp_log_add_func (GP_LOG_ALL, debug_func, NULL);
+ } else if (0 == strcmp(argv[i], "--help")) {
+ puts(HELP_TEXT);
+ return 0;
+ } else {
+ if (hotplug_script != NULL) {
+ fprintf(stderr, "Error: duplicate script parameter: \"%s\"\n", argv[i]);
+ return 1;
+ }
+ /* assume script name */
+ hotplug_script = argv[i];
+ }
+ }
+
+ if (NULL == hotplug_script) {
+ hotplug_script = GP_USB_HOTPLUG_SCRIPT;
+ }
+
+ return print_udev_rules(hotplug_script, add_comments);
+}
+
+/*
+ * Local Variables:
+ * c-file-style:"linux"
+ * indent-tabs-mode:t
+ * End:
+ */
only in patch2:
unchanged:
--- libgphoto2-2.1.6.orig/packaging/linux-hotplug/Makefile.am
+++ libgphoto2-2.1.6/packaging/linux-hotplug/Makefile.am
@@ -13,10 +13,14 @@
# FIXME: utilsdir be modifiable by a ./configure option to adapt to local
# policies
utilsdir = $(libdir)/$(PACKAGE)
-utils_PROGRAMS = print-usb-usermap
+utils_PROGRAMS = print-usb-usermap print-udev-rules
print_usb_usermap_SOURCE = print-usb-usermap.c
print_usb_usermap_LDADD = $(top_builddir)/libgphoto2/libgphoto2.la \
$(top_builddir)/libgphoto2_port/libgphoto2_port/libgphoto2_port.la
+print_udev_rules_SOURCE = print-udev-rules.c
+print_udev_rules_LDADD = $(top_builddir)/libgphoto2/libgphoto2.la \
+ $(top_builddir)/libgphoto2_port/libgphoto2_port/libgphoto2_port.la
+
endif
only in patch2:
unchanged:
--- libgphoto2-2.1.6.orig/packaging/linux-hotplug/Makefile.in
+++ libgphoto2-2.1.6/packaging/linux-hotplug/Makefile.in
@@ -146,14 +146,16 @@
# FIXME: utilsdir be modifiable by a ./configure option to adapt to local
# policies
@[EMAIL PROTECTED] = $(libdir)/$(PACKAGE)
[EMAIL PROTECTED]@utils_PROGRAMS = print-usb-usermap
[EMAIL PROTECTED]@utils_PROGRAMS = print-usb-usermap print-udev-rules
@[EMAIL PROTECTED] = print-usb-usermap.c
@[EMAIL PROTECTED] = $(top_builddir)/libgphoto2/libgphoto2.la $(top_builddir)/libgphoto2_port/libgphoto2_port/libgphoto2_port.la
[EMAIL PROTECTED]@print_udev_rules_SOURCE = print-udev-rules.c
[EMAIL PROTECTED]@print_udev_rules_LDADD = $(top_builddir)/libgphoto2/libgphoto2.la $(top_builddir)/libgphoto2_port/libgphoto2_port/libgphoto2_port.la
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../../config.h
CONFIG_CLEAN_FILES =
[EMAIL PROTECTED]@utils_PROGRAMS = print-usb-usermap$(EXEEXT)
[EMAIL PROTECTED]@utils_PROGRAMS = print-usb-usermap$(EXEEXT) print-udev-rules$(EXEEXT)
PROGRAMS = $(utils_PROGRAMS)
@@ -167,6 +169,12 @@
@[EMAIL PROTECTED](top_builddir)/libgphoto2/libgphoto2.la \
@[EMAIL PROTECTED](top_builddir)/libgphoto2_port/libgphoto2_port/libgphoto2_port.la
print_usb_usermap_LDFLAGS =
+print_udev_rules_SOURCES = print-udev-rules.c
+print_udev_rules_OBJECTS = print-udev-rules.$(OBJEXT)
[EMAIL PROTECTED]@print_udev_rules_DEPENDENCIES = \
[EMAIL PROTECTED]@$(top_builddir)/libgphoto2/libgphoto2.la \
[EMAIL PROTECTED]@$(top_builddir)/libgphoto2_port/libgphoto2_port/libgphoto2_port.la
+print_udev_rules_LDFLAGS =
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -181,8 +189,8 @@
TAR = tar
GZIP_ENV = --best
-SOURCES = print-usb-usermap.c
-OBJECTS = print-usb-usermap.$(OBJEXT)
+SOURCES = print-usb-usermap.c print-udev-rules.c
+OBJECTS = print-usb-usermap.$(OBJEXT) print-udev-rules.$(OBJEXT)
all: all-redirect
.SUFFIXES:
@@ -268,6 +276,10 @@
@rm -f print-usb-usermap$(EXEEXT)
$(LINK) $(print_usb_usermap_LDFLAGS) $(print_usb_usermap_OBJECTS) $(print_usb_usermap_LDADD) $(LIBS)
+print-udev-rules$(EXEEXT): $(print_udev_rules_OBJECTS) $(print_udev_rules_DEPENDENCIES)
+ @rm -f print-udev-rules$(EXEEXT)
+ $(LINK) $(print_udev_rules_LDFLAGS) $(print_udev_rules_OBJECTS) $(print_udev_rules_LDADD) $(LIBS)
+
install-hotplugdocDATA: $(hotplugdoc_DATA)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(hotplugdocdir)