[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#504668: firmware-nonfree: Add License handler in gencontrol.py



Package: firmware-nonfree
Severity: normal
Tags: patch

The two patches attaches allow gencontrol.py to handle licenses
in a way that complies with ipw2100 and ipw2200 firmware license.

The patch links.diff implements a "links" entry in the firmware's
define file. That entry is a list of source:target that is used
by gencontrol.py to generate ./debian/firmware-foobar.links

The patch license.diff implements license=[required|no-preseed]
and license_name entry in the firmware's define file.
When used, those fields are used to generate a preinst script 
that present the license to the user.
If license=no-preseed, then the license acceptation can't be
accepted by using Debconf preseeding (!).

Franklin

-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (990, 'testing'), (200, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-1-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff --git a/debian/bin/gencontrol.py b/debian/bin/gencontrol.py
index 92f0017..f5d5cc9 100755
--- a/debian/bin/gencontrol.py
+++ b/debian/bin/gencontrol.py
@@ -134,6 +134,11 @@ class GenControl(object):
             postinst = self.templates['postinst.initramfs-tools']
             file("debian/firmware-%s.postinst" % package, 'w').write(self.substitute(postinst, vars))
 
+	if 'links' in config_entry:
+            for l in config_entry['links']:
+                src,trg = l.split(':')
+                file("debian/firmware-%s.links" % package, 'w').write("%s %s\n" % (src, trg))
+
         packages.extend(packages_binary)
 
         makefile.add('binary-indep', cmds = ["$(MAKE) -f debian/rules.real binary-indep %s" % makeflags])
@@ -209,6 +214,7 @@ class Config(dict):
     schemas = {
         'base': {
             'files': SchemaItemList(),
+            'links': SchemaItemList(),
             'packages': SchemaItemList(),
             'support': SchemaItemList(),
         }
diff --git a/debian/changelog b/debian/changelog
index bbbe478..e871f01 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+firmware-nonfree (0.14) unstable; urgency=low
+
+  * gencontrol can generate links file.
+
+ -- Frank Lin PIAT <fpiat@klabs.be>  Mon, 27 Oct 2008 00:05:03 +0100
+
 firmware-nonfree (0.13) unstable; urgency=low
 
   * Make firmware-bnx2 trigger update-initramfs (closes: #494936)
diff --git a/debian/rules b/debian/rules
index 648d517..9a6f3fb 100755
--- a/debian/rules
+++ b/debian/rules
@@ -12,4 +12,5 @@ maintainerclean:
 	-rm debian/control debian/control.md5sum debian/rules.gen
 	-rm debian/*.copyright
 	-rm debian/*.hook.*
+	-rm debian/*.links
 	-rm debian/*.postinst
diff --git a/debian/rules.real b/debian/rules.real
index 7626ef5..83646f4 100644
--- a/debian/rules.real
+++ b/debian/rules.real
@@ -30,6 +30,7 @@ install:
 	fi
 	dh_installchangelogs
 	dh_installdocs
+	dh_link
 	dh_compress
 	dh_fixperms
 	dh_installdeb
diff --git a/debian/bin/gencontrol.py b/debian/bin/gencontrol.py
index f5d5cc9..b23cd51 100755
--- a/debian/bin/gencontrol.py
+++ b/debian/bin/gencontrol.py
@@ -83,6 +83,8 @@ class GenControl(object):
         config_entry = self.config['base', package]
         vars.update(config_entry)
         vars['package'] = package
+        vars['debconfpkg'] = "firmware-%s" % package
+        vars['license_name'] = package
 
         makeflags['PACKAGE'] = package
 
@@ -91,6 +93,11 @@ class GenControl(object):
 
         vars['license'] = file("%s/LICENSE" % package).read()
 
+        regex=re.compile('^\s*$', re.MULTILINE)
+        vars['license_indented'] = re.sub(regex, '.', vars['license'])
+        regex=re.compile('^', re.MULTILINE)
+        vars['license_indented'] = re.sub(regex, ' ', vars['license_indented'])
+
         file("debian/firmware-%s.copyright" % package, 'w').write(self.substitute(copyright, vars))
 
         files_orig = config_entry['files']
@@ -139,6 +146,15 @@ class GenControl(object):
                 src,trg = l.split(':')
                 file("debian/firmware-%s.links" % package, 'w').write("%s %s\n" % (src, trg))
 
+        if 'license_accept' in config_entry:
+            preinst = self.templates['preinst.license']
+            preinst_filename = "debian/firmware-%s.preinst" % package
+            file(preinst_filename, 'w').write(self.substitute(preinst, vars))
+
+            templates = self.templates['license.templates']
+            templates_filename = "debian/firmware-%s.templates" % package
+            file(templates_filename, 'w').write(self.substitute(templates, vars))
+
         packages.extend(packages_binary)
 
         makefile.add('binary-indep', cmds = ["$(MAKE) -f debian/rules.real binary-indep %s" % makeflags])
diff --git a/debian/changelog b/debian/changelog
index e871f01..756f9a8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
 firmware-nonfree (0.14) unstable; urgency=low
 
   * gencontrol can generate links file.
+  * gencontrol can generate license acceptation prompt, based on
+    sun-java5 preinst script and template.
 
  -- Frank Lin PIAT <fpiat@klabs.be>  Mon, 27 Oct 2008 00:05:03 +0100
 
diff --git a/debian/rules b/debian/rules
index 9a6f3fb..38f8b0f 100755
--- a/debian/rules
+++ b/debian/rules
@@ -12,5 +12,7 @@ maintainerclean:
 	-rm debian/control debian/control.md5sum debian/rules.gen
 	-rm debian/*.copyright
 	-rm debian/*.hook.*
 	-rm debian/*.links
+	-rm debian/*.templates
+	-rm debian/*.preinst
 	-rm debian/*.postinst
diff --git a/debian/rules.real b/debian/rules.real
index 83646f4..afcf1cc 100644
--- a/debian/rules.real
+++ b/debian/rules.real
@@ -30,6 +30,7 @@ install:
 	fi
 	dh_installchangelogs
 	dh_installdocs
+	dh_installdebconf
 	dh_link
 	dh_compress
 	dh_fixperms
diff --git a/debian/templates/license.templates.in b/debian/templates/license.templates.in
new file mode 100644
index 0000000..629547b
--- /dev/null
+++ b/debian/templates/license.templates.in
@@ -0,0 +1,21 @@
+Template: @debconfpkg@/present-@license_name@
+Type: note
+Description: @license_title@
+@license_indented@
+
+Template: @debconfpkg@/accepted-@license_name@
+Type: boolean
+Default: false
+Description: Do you agree with the @license_title@ license terms?
+ In order to install this package, you must agree to its license terms, the
+ "@license_title@".
+ Not accepting will cancel the installation.
+
+Template: @debconfpkg@/error-@license_name@
+Type: error
+Description: Declined @license_title@
+ If you do not agree to the "@license_title@" 
+ license terms you cannot install this software.
+ .
+ The installation of this package will be canceled.
+
diff --git a/debian/templates/preinst.license.in b/debian/templates/preinst.license.in
new file mode 100644
index 0000000..ec750e9
--- /dev/null
+++ b/debian/templates/preinst.license.in
@@ -0,0 +1,77 @@
+#!/bin/sh -e
+
+. /usr/share/debconf/confmodule
+db_version 2.0
+db_capb backup
+
+#Valid values are "required" and "no-preseed"
+license_accept=@license_accept@
+
+errmsg()
+{
+    echo >&2 ''
+    echo >&2 "$@"
+    echo >&2 "try 'dpkg-reconfigure debconf' to select a frontend other than noninteractive"
+    echo >&2 ''
+}
+
+db_get @debconfpkg@/accepted-@license_name@
+if [ "$RET" = "true" ]; then
+    echo "@license_name@ license has already been accepted" >&2
+    exit 0
+fi
+
+# facilitate backup capability per debconf-devel(7)
+STATE=1
+while true; do
+    case "$STATE" in
+    0)  # ensure going back from license presentment is harmless
+        STATE=1 
+        continue
+        ;;   
+    1)  # present license
+        db_get @debconfpkg@/accepted-@license_name@
+       	if [ "$RET" != true -o "${license_accept}" = "no-preseed" ]; then
+		db_fset @debconfpkg@/present-@license_name@ seen false
+        	if ! db_input critical @debconfpkg@/present-@license_name@ ; then
+        	    errmsg "@license_name@ license could not be presented"
+		    exit 2
+        	fi
+
+        	db_fset @debconfpkg@/accepted-@license_name@ seen false
+        	if ! db_input critical @debconfpkg@/accepted-@license_name@ ; then
+        	    errmsg "@license_name@ agree question could not be asked"
+		    exit 2
+        	fi
+	fi
+        ;;      
+    2)  # determine users' choice
+        db_get @debconfpkg@/accepted-@license_name@
+        if [ "$RET" = "true" ]; then
+	    # license accepted
+            exit 0
+        fi
+        # error on decline license (give user chance to back up)
+        db_input critical @debconfpkg@/error-@license_name@
+        ;;      
+    3)  # user has confirmed declining license
+        echo "user did not accept the @license_name@ license" >&2
+        exit 1
+        ;;   
+    *)  # unknown state
+        echo "@license_name@ license state unknown: $STATE" >&2
+        exit 2
+        ;;   
+    esac
+    if db_go; then
+        STATE=$(($STATE + 1))
+    else
+        STATE=$(($STATE - 1))
+    fi
+done
+ 
+#DEBHELPER#
+
+# proper exit (0 or 1) above
+errmsg "@license_name@ license could not be presented / was not accepted"
+exit 2

Reply to: