]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
UBUNTU: [debian] Initial debian and ubuntu directories
authorLeann Ogasawara <leann.ogasawara@canonical.com>
Sat, 13 Mar 2010 01:13:25 +0000 (17:13 -0800)
committerSeth Forshee <seth.forshee@canonical.com>
Mon, 29 Jan 2018 13:44:47 +0000 (07:44 -0600)
Ignore: yes
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
80 files changed:
.gitignore
Makefile
arch/arm/Kconfig
arch/arm64/Kconfig
arch/powerpc/Kconfig
arch/x86/Kconfig
debian/cloud-tools/hv_get_dhcp_info [new file with mode: 0755]
debian/cloud-tools/hv_get_dns_info [new file with mode: 0755]
debian/cloud-tools/hv_set_ifconfig [new file with mode: 0755]
debian/commit-templates/bumpabi [new file with mode: 0644]
debian/commit-templates/config-updates [new file with mode: 0644]
debian/commit-templates/external-driver [new file with mode: 0644]
debian/commit-templates/missing-modules [new file with mode: 0644]
debian/commit-templates/newrelease [new file with mode: 0644]
debian/commit-templates/sauce-patch [new file with mode: 0644]
debian/commit-templates/upstream-patch [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control-scripts/extra-post [new file with mode: 0644]
debian/control-scripts/headers-postinst [new file with mode: 0644]
debian/control-scripts/postinst [new file with mode: 0644]
debian/control-scripts/postrm [new file with mode: 0644]
debian/control-scripts/preinst [new file with mode: 0644]
debian/control-scripts/prerm [new file with mode: 0644]
debian/debian.env [new file with mode: 0644]
debian/docs/README.inclusion-list [new file with mode: 0644]
debian/gbp.conf [new file with mode: 0644]
debian/linux-cloud-tools-common.hv-fcopy-daemon.service [new file with mode: 0644]
debian/linux-cloud-tools-common.hv-fcopy-daemon.upstart [new file with mode: 0644]
debian/linux-cloud-tools-common.hv-kvp-daemon.service [new file with mode: 0644]
debian/linux-cloud-tools-common.hv-kvp-daemon.upstart [new file with mode: 0644]
debian/linux-cloud-tools-common.hv-vss-daemon.service [new file with mode: 0644]
debian/linux-cloud-tools-common.hv-vss-daemon.upstart [new file with mode: 0644]
debian/rules [new file with mode: 0755]
debian/rules.d/0-common-vars.mk [new file with mode: 0644]
debian/rules.d/1-maintainer.mk [new file with mode: 0644]
debian/rules.d/2-binary-arch.mk [new file with mode: 0644]
debian/rules.d/3-binary-indep.mk [new file with mode: 0644]
debian/rules.d/4-checks.mk [new file with mode: 0644]
debian/rules.d/5-udebs.mk [new file with mode: 0644]
debian/scripts/abi-check [new file with mode: 0755]
debian/scripts/config-check [new file with mode: 0755]
debian/scripts/control-create [new file with mode: 0755]
debian/scripts/link-headers [new file with mode: 0755]
debian/scripts/misc/find-obsolete-firmware [new file with mode: 0755]
debian/scripts/misc/fw-to-ihex.sh [new file with mode: 0755]
debian/scripts/misc/gen-auto-reconstruct [new file with mode: 0755]
debian/scripts/misc/get-firmware [new file with mode: 0755]
debian/scripts/misc/getabis [new file with mode: 0755]
debian/scripts/misc/git-ubuntu-log [new file with mode: 0755]
debian/scripts/misc/insert-changes.pl [new file with mode: 0755]
debian/scripts/misc/insert-mainline-changes [new file with mode: 0755]
debian/scripts/misc/insert-ubuntu-changes [new file with mode: 0755]
debian/scripts/misc/kernel-wedge-arch.pl [new file with mode: 0755]
debian/scripts/misc/kernelconfig [new file with mode: 0755]
debian/scripts/misc/retag [new file with mode: 0755]
debian/scripts/misc/splitconfig.pl [new file with mode: 0755]
debian/scripts/misc/tristate.sh [new file with mode: 0755]
debian/scripts/misc/update-aufs.sh [new file with mode: 0755]
debian/scripts/misc/update-zfs.sh [new file with mode: 0755]
debian/scripts/module-check [new file with mode: 0755]
debian/scripts/module-inclusion [new file with mode: 0755]
debian/scripts/sub-flavour [new file with mode: 0644]
debian/snapcraft.mk [new file with mode: 0644]
debian/source/format [new file with mode: 0644]
debian/source/options [new file with mode: 0644]
debian/stamps/keep-dir [new file with mode: 0644]
debian/tests-build/README [new file with mode: 0644]
debian/tests-build/check-aliases [new file with mode: 0755]
debian/tests/control [new file with mode: 0644]
debian/tests/rebuild [new file with mode: 0644]
debian/tests/ubuntu-regression-suite [new file with mode: 0755]
debian/tools/generic [new file with mode: 0644]
debian/zfs-modules.ignore [new file with mode: 0644]
drivers/staging/signature-inclusion [new file with mode: 0644]
dropped.txt [new file with mode: 0644]
scripts/Makefile.modinst
ubuntu/Kconfig [new file with mode: 0644]
ubuntu/Makefile [new file with mode: 0644]
ubuntu/include/Kbuild [new file with mode: 0644]
ubuntu/include/README [new file with mode: 0644]

index f6050b88e95b5b59e2c08dbef865d92049956e58..cfb46d17f355ab67478f20e03b96303e8fe1303f 100644 (file)
@@ -63,7 +63,7 @@ modules.builtin
 #
 # Debian directory (make deb-pkg)
 #
-/debian/
+#/debian/
 
 #
 # tar directory (make tar*-pkg)
index c8b8e902d5a4fdd8114bf55283f35535e2556df1..b2096779460d48d010d386d7dc4a6530f1915905 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -395,6 +395,13 @@ CFLAGS_KERNEL      =
 AFLAGS_KERNEL  =
 LDFLAGS_vmlinux =
 
+# Prefer linux-backports-modules
+ifneq ($(KBUILD_SRC),)
+ifneq ($(shell if test -e $(KBUILD_OUTPUT)/ubuntu-build; then echo yes; fi),yes)
+UBUNTUINCLUDE := -I/usr/src/linux-headers-lbm-$(KERNELRELEASE)
+endif
+endif
+
 # Use USERINCLUDE when you must reference the UAPI directories only.
 USERINCLUDE    := \
                -I$(srctree)/arch/$(SRCARCH)/include/uapi \
@@ -406,12 +413,16 @@ USERINCLUDE    := \
 # Use LINUXINCLUDE when you must reference the include/ directory.
 # Needed to be compatible with the O= option
 LINUXINCLUDE    := \
+               $(UBUNTUINCLUDE) \
                -I$(srctree)/arch/$(SRCARCH)/include \
                -I$(objtree)/arch/$(SRCARCH)/include/generated \
                $(if $(KBUILD_SRC), -I$(srctree)/include) \
                -I$(objtree)/include \
                $(USERINCLUDE)
 
+# UBUNTU: Include our third party driver stuff too
+LINUXINCLUDE   += -Iubuntu/include $(if $(KBUILD_SRC),-I$(srctree)/ubuntu/include)
+
 KBUILD_AFLAGS   := -D__ASSEMBLY__
 KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                   -fno-strict-aliasing -fno-common -fshort-wchar \
@@ -557,7 +568,7 @@ scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \
 
 # Objects we will link into vmlinux / subdirs we need to visit
 init-y         := init/
-drivers-y      := drivers/ sound/ firmware/
+drivers-y      := drivers/ sound/ firmware/ ubuntu/
 net-y          := net/
 libs-y         := lib/
 core-y         := usr/
index 51c8df5610777459c727e30cc65ef6fe7aa41b66..86458c57c4b0f2aa297529c3675833c521a380ca 100644 (file)
@@ -2204,6 +2204,7 @@ source "net/Kconfig"
 source "drivers/Kconfig"
 
 source "drivers/firmware/Kconfig"
+source "ubuntu/Kconfig"
 
 source "fs/Kconfig"
 
index c9a7e9e1414f344c9dfd515600e3e4378bf61d81..e8641c70520651bb33701c8c790b391a45c9a942 100644 (file)
@@ -1208,6 +1208,8 @@ source "net/Kconfig"
 
 source "drivers/Kconfig"
 
+source "ubuntu/Kconfig"
+
 source "drivers/firmware/Kconfig"
 
 source "drivers/acpi/Kconfig"
index 2ed525a44734cfaa62ba7125fab11225c1778a7a..86474d8b2ede378faff88e1f22ce4783acfdedc3 100644 (file)
@@ -1215,6 +1215,8 @@ source "net/Kconfig"
 
 source "drivers/Kconfig"
 
+source "ubuntu/Kconfig"
+
 source "fs/Kconfig"
 
 source "lib/Kconfig"
index 20da391b5f329885e26b30e0351d73d571d28fc1..05dcc344243eb9cff1688fae2be79e788131a302 100644 (file)
@@ -2898,6 +2898,8 @@ source "net/Kconfig"
 
 source "drivers/Kconfig"
 
+source "ubuntu/Kconfig"
+
 source "drivers/firmware/Kconfig"
 
 source "fs/Kconfig"
diff --git a/debian/cloud-tools/hv_get_dhcp_info b/debian/cloud-tools/hv_get_dhcp_info
new file mode 100755 (executable)
index 0000000..09fabd2
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# This example script retrieves the DHCP state of a given interface.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to gather
+# DHCP setting for the specific interface.
+#
+# Input: Name of the interface
+#
+# Output: The script prints the string "Enabled" to stdout to indicate
+#      that DHCP is enabled on the interface. If DHCP is not enabled,
+#      the script prints the string "Disabled" to stdout.
+#
+# Each Distro is expected to implement this script in a distro specific
+# fashion. 
+
+#set -x
+
+IF_FILE="/etc/network/interfaces"
+NMCMD="nmcli"
+
+function checknetworkmanager {
+       #Assumes if $NMCMD exists, inteface exists and interface is not
+       #  in $IF_FILE then dhcp is being used by NM
+        if  hash $NMCMD >/dev/null 2>&1  ; then
+                if  $NMCMD  dev status |grep -q $1  ; then
+                        echo "Enabled"
+                else
+                        echo "Disabled"
+                fi
+        else
+                #Give up
+                echo "Disabled"
+        fi
+}
+
+if [ -z $1 ]  ; then echo "Disabled"; exit; fi
+
+if [ -e $IF_FILE ]; then
+       if grep -v -e "^#" $IF_FILE|grep -q $1 ; then
+               #interface exists so
+               if grep -q -e $1\.\*dhcp $IF_FILE; then 
+                       echo "Enabled"; exit;
+               else
+                       echo "Disabled"; exit;
+               fi
+       else
+               checknetworkmanager $1
+               exit
+       fi
+else
+       checknetworkmanager $1
+       exit
+fi
+
diff --git a/debian/cloud-tools/hv_get_dns_info b/debian/cloud-tools/hv_get_dns_info
new file mode 100755 (executable)
index 0000000..058c17b
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# This example script parses /etc/resolv.conf to retrive DNS information.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to gather
+# DNS information.
+# This script is expected to print the nameserver values to stdout.
+# Each Distro is expected to implement this script in a distro specific
+# fashion. For instance on Distros that ship with Network Manager enabled,
+# this script can be based on the Network Manager APIs for retrieving DNS
+# entries.
+
+cat /etc/resolv.conf 2>/dev/null | awk '/^nameserver/ { print $2 }'
diff --git a/debian/cloud-tools/hv_set_ifconfig b/debian/cloud-tools/hv_set_ifconfig
new file mode 100755 (executable)
index 0000000..d8b0487
--- /dev/null
@@ -0,0 +1,288 @@
+#!/usr/bin/python3
+#
+# hv_set_ifconfig <config> -- take the hv_kvp_daemon generated configuration
+#                             file and apply it to the Ubuntu configuration.
+#
+
+# CONFIG example:
+# HWADDR=11:22:33:44:55:66
+# DEVICE=foo1
+# DHCP=yes
+
+# CONFIG example:
+# HWADDR=11:22:33:44:55:66
+# DEVICE=foo1
+# IPADDR=192.168.99.10
+# GATEWAY=192.168.99.1
+# DNS1=192.168.88.250
+# IPADDR2=192.168.99.11
+# IPV6ADDR=2001:DB8:99::10
+# IPV6NETMASK=64
+# IPV6_DEFAULTGW=2001:DB8:99::10
+
+# set interfaces in hv_kvp_daemon style
+import fileinput
+import sys
+import errno
+import os
+import shutil
+import tempfile
+import subprocess
+
+if_filename="/etc/network/interfaces"
+
+# Drop our output (XXX?)
+sys.stdout = open(os.devnull, 'w')
+sys.stderr = open(os.devnull, 'w')
+
+# Confirm we can open the network configuration.
+try:
+    if_file=open(if_filename,"r+")
+except IOError as e:
+    exit(e.errno)
+else:
+    if_file.close()
+
+# Usage: hv_set_ifconfig <config>
+if len(sys.argv) != 2 :
+    exit(errno.EINVAL)
+
+#
+# Here is the format of the ip configuration file:
+#
+# HWADDR=macaddr
+# DEVICE=interface name
+# BOOTPROTO=<protocol> (where <protocol> is "dhcp" if DHCP is configured
+#                       or "none" if no boot-time protocol should be used)
+#
+# IPADDR0=ipaddr1
+# IPADDR1=ipaddr2
+# IPADDRx=ipaddry (where y = x + 1)
+#
+# NETMASK0=netmask1
+# NETMASKx=netmasky (where y = x + 1)
+#
+# GATEWAY=ipaddr1
+# GATEWAYx=ipaddry (where y = x + 1)
+#
+# DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc)
+#
+# IPV6 addresses will be tagged as IPV6ADDR, IPV6 gateway will be
+# tagged as IPV6_DEFAULTGW and IPV6 NETMASK will be tagged as
+# IPV6NETMASK.
+#
+
+kvp=dict(line.strip().split("=") for line in fileinput.input())
+
+# Setting the hwaddress to something azure is not expecting is fatal
+# to networking.
+if not "HWADDR" in kvp :
+    exit(errno.EPROTO)
+
+# Confirm we have a device specified.
+if not "DEVICE" in kvp :
+    exit(1)
+
+autolist = []
+output=[]
+basename=kvp["DEVICE"]
+
+# DNS entries will go with the first interface and there can be a max
+# of three.  These will be emitted with the first interface.
+dns = []
+for count in (1, 2, 3):
+    key = "DNS" + str(count)
+    if key in kvp:
+        dns += [kvp[key]]
+dns_emitted = False
+
+# IPV4 may either be dhcp or static.
+if ("DHCP" in kvp and kvp["DHCP"] == "yes") or \
+   ("BOOTPROTO" in kvp and kvp["BOOTPROTO"] == "dhcp"):
+    autolist.append(basename)
+    output += ["iface " + basename  + " inet dhcp"]
+    output += [""]
+else:
+    # Matchup the interface specific lines
+
+    # No real max for the number of interface + aliases ...
+    # only required is the address (but mate everything up that comes in.
+
+    # IPv4 -- ensure we sort by numeric suffixes.
+    v4names = [ int(name[6:]) for name in kvp.keys() if name.startswith("IPADDR") ]
+    v4names.sort()
+
+    for if_count in v4names:
+        ifname = basename
+        which = str(if_count)
+
+        if if_count:
+            ifname += ":" + str(if_count)
+            which_gw = which
+        else:
+            which_gw = ""
+
+        if not ifname in autolist:
+            autolist += [ifname]
+
+        output += [ "iface " + ifname + " inet static" ]
+        output += [ "\t" + "address " + kvp["IPADDR" + which] ]
+        if "NETMASK" + which in kvp:
+            output += [ "\tnetmask " + kvp["NETMASK" + which] ]
+        if "GATEWAY" + which_gw in kvp:
+            output += ["\tgateway " + kvp["GATEWAY" + which_gw]]
+
+        if not dns_emitted:
+            dns_emitted = True
+            output += ["\tdns-nameservers " + ' '.join(dns)]
+        output += [""]
+
+# IPv6 requires a netmask
+# If an ipv6 exists, you'll want to turn off /proc/sys/net/ipv6/conf/all/autoconf with
+# echo 0 > /proc/sys/net/ipv6/conf/all/autoconf
+v6names = [ int(name[8:]) for name in kvp.keys() if name.startswith("IPV6ADDR") ]
+v6names.sort()
+
+for if6_count in v6names:
+    ifname = basename
+    which = str(if6_count)
+
+    if if6_count:
+        ifname += ":" + str(if6_count)
+        which_gw = which
+    else:
+        which_gw = ""
+
+    if not ifname in autolist:
+        autolist += [ifname]
+
+    if "IPV6NETMASK" + which in kvp:
+        output += [ "iface " + ifname + " inet6 static"]
+        output += [ "\taddress " + kvp["IPV6ADDR" + which]]
+        output += [ "\tnetmask " + kvp["IPV6NETMASK" + which]]
+        if "IPV6_DEFAULTGW" + which_gw in kvp:
+            output += [ "\tgateway " + kvp["IPV6_DEFAULTGW" + which_gw] ]
+        if not dns_emitted:
+            dns_emitted = True
+            output += ["\tdns-nameservers " + ' '.join(dns)]
+        output += [""]
+
+# Mark this new interface for automatic up.
+if len(autolist):
+    output = ["auto "+" ".join(autolist)] + output
+
+print("===================================")
+print(output)
+print("===================================")
+
+
+# Time to clean out the existing interface file
+
+# Markers.
+start_mark = "# The following stanza(s) added by hv_set_ifconfig"
+end_mark = "#End of hv_set_ifconfig stanzas"
+
+f=open(if_filename,"r")
+flines=f.readlines()
+f.close()
+newfile=[]
+pitchstanza=0
+inastanza=0
+stanza=[]
+prev_line=None
+for line in flines:
+    if line.startswith("auto"):
+        if inastanza:
+            if not pitchstanza:
+                newfile.extend(stanza)
+            stanza=[]
+        inastanza=0
+        newline=""
+        autoline=line.strip().split(" ")
+        for word in autoline:
+            if (not word == basename) and (not word.startswith(basename+":")):
+                newline+=word + " "
+        newline = newline.strip()
+        if not newline == "auto":
+            newfile += [newline.strip()]
+    elif line.startswith(("iface","mapping","source")):
+        '''Read a stanza'''
+        '''A Stanza can also start with allow- ie allow-hotplug'''
+        if inastanza:
+            if not pitchstanza:
+                newfile.extend(stanza)
+            stanza=[]
+        inastanza=1
+        pitchstanza=0
+        autoline=line.strip().split(" ")
+        for word in autoline:
+            if (word == basename) or (word.startswith(basename+":")):
+                pitchstanza=1
+        if not pitchstanza:
+            stanza+=[line.strip()]
+    elif line.strip() in (start_mark, end_mark):
+        if inastanza:
+            if not pitchstanza:
+                newfile.extend(stanza)
+            stanza=[]
+        inastanza = 0
+        pitchstanza = 0
+        # Deduplicate markers.
+        if line != prev_line:
+            newfile += [line.strip()]
+    else:
+        if inastanza:
+            if not pitchstanza:
+                stanza+=[line.strip()]
+        else:
+            if not pitchstanza:
+                newfile += [line.strip()]
+    prev_line=line
+
+# Include pending stanza if any.
+if inastanza and not pitchstanza:
+    newfile.extend(stanza)
+
+
+def emit(line):
+    print(line)
+    output = line + "\n"
+    os.write(fd, output.encode('utf-8'))
+
+# Insert the new output at the end and inside the existing markers if found.
+emitted = False
+fd, path = tempfile.mkstemp()
+for line in newfile:
+    if line == end_mark:
+        emit("\n".join(output))
+        emitted = True
+    emit(line)
+if not emitted:
+    emit(start_mark)
+    emit("\n".join(output))
+    emit(end_mark)
+os.close(fd)
+
+shutil.copy(path,if_filename)
+os.chmod(if_filename,0o644)
+
+#print("TMPFILE is at: " + path)
+#print("Copied file is at: " + if_filename)
+
+try:
+    retcode = subprocess.call("ifdown "+basename , shell=True)
+    if retcode < 0:
+        print("Child was terminated by signal", -retcode, file=sys.stderr)
+    else:
+        print("Child returned", retcode, file=sys.stderr)
+except OSError as e:
+    print("Execution failed:", e, file=sys.stderr)
+
+try:
+    retcode = subprocess.call("ifup "+basename , shell=True)
+    if retcode < 0:
+        print("Child was terminated by signal", -retcode, file=sys.stderr)
+    else:
+        print("Child returned", retcode, file=sys.stderr)
+except OSError as e:
+    print("Execution failed:", e, file=sys.stderr)
diff --git a/debian/commit-templates/bumpabi b/debian/commit-templates/bumpabi
new file mode 100644 (file)
index 0000000..6c373c9
--- /dev/null
@@ -0,0 +1,3 @@
+UBUNTU: Bump ABI
+
+Ignore: yes
diff --git a/debian/commit-templates/config-updates b/debian/commit-templates/config-updates
new file mode 100644 (file)
index 0000000..4b62c29
--- /dev/null
@@ -0,0 +1,15 @@
+#
+# This template is used for commit messages that don't need to
+# show up in debian/changelog. Administrative stuff like config
+# updates, ABI bumps, etc. Setting 'Ignore: yes' prevents
+# 'debian/rules insertchanges' from inserting this commit meesage
+# as a changelog entry.
+#
+# Please give a one-line description of the config change followed
+# by a detailed explanation if necessary
+
+UBUNTU: [Config] XXXX
+
+# BugLink: http://bugs.launchpad.net/bugs/<enter bug# here>
+# Ignore: yes
+# Other text below here.
diff --git a/debian/commit-templates/external-driver b/debian/commit-templates/external-driver
new file mode 100644 (file)
index 0000000..decdc89
--- /dev/null
@@ -0,0 +1,20 @@
+# Ubuntu external driver commit.
+#
+# NOTE: This gets reformatted for README.Ubuntu-External-Drivers and
+# debian/changelog.
+#
+# This is only needed when a driver is added, updated or removed. It is
+# not needed when patches or fixes are applied to the driver. If the
+# driver is being removed, add the line:
+#
+# Removing: yes
+#
+# to the commit, and you can remove all other tags (except UBUNTU:).
+#
+UBUNTU: 
+
+ExternalDriver: 
+Description:
+Url:
+Mask:
+Version:
diff --git a/debian/commit-templates/missing-modules b/debian/commit-templates/missing-modules
new file mode 100644 (file)
index 0000000..f4872e7
--- /dev/null
@@ -0,0 +1,3 @@
+UBUNTU: build/modules: Add modules that have intentionally gone missing
+
+Ignore: yes
diff --git a/debian/commit-templates/newrelease b/debian/commit-templates/newrelease
new file mode 100644 (file)
index 0000000..5f8931c
--- /dev/null
@@ -0,0 +1,3 @@
+UBUNTU: Start new release
+
+Ignore: yes
diff --git a/debian/commit-templates/sauce-patch b/debian/commit-templates/sauce-patch
new file mode 100644 (file)
index 0000000..08720a8
--- /dev/null
@@ -0,0 +1,40 @@
+# Ubuntu commit template.
+#
+# NOTE: This gets reformatted for debian/changelog
+#
+#
+# SAUCE refers to the fact that this patch might not go upstream, but we need to
+# carry it to successive releases. In most cases you DONOT want to use this
+# template. 
+#
+# An example of a SAUCE patch is the ACPI DSDT-in-initramfs patch which has been
+# refused upstream, but still provides useful functionality to users with broken
+# BIOSes.
+#
+#-------------------------------------------------------------------------
+#
+# The initial UBUNTU is a flag that this is an Ubuntu commit. It will be
+# referenced to the Author in the debian/changelog entry.
+#
+# The text following is the short message that will be placed in the
+# changelog. Extra text on the following lines will be ignored, but left
+# in the git commit. Lines with # will be ignored in the commit.
+#
+# OriginalAuthor allows for alternate attribution.
+#
+# OriginalLocation allows for a URL or description of where the patch came
+# from.
+#
+# BugLink is a URL to a Malone bug.
+#
+# Ignore: yes will keep this commit from showing up in the changelog.
+#
+UBUNTU: SAUCE: 
+
+<Why is this patch not going upstream?>
+
+# OriginalAuthor: 
+# OriginalLocation: 
+# BugLink: http://bugs.launchpad.net/bugs/<enter bug# here>
+# Ignore: yes
+# Other text below here.
diff --git a/debian/commit-templates/upstream-patch b/debian/commit-templates/upstream-patch
new file mode 100644 (file)
index 0000000..671ab6a
--- /dev/null
@@ -0,0 +1,27 @@
+# Ubuntu commit template.
+#
+# NOTE: This gets reformatted for debian/changelog
+#
+# The initial UBUNTU is a flag that this is an Ubuntu commit. It will be
+# referenced to the Author in the debian/changelog entry.
+#
+# The text following is the short message that will be placed in the
+# changelog. Extra text on the following lines will be ignored, but left
+# in the git commit. Lines with # will be ignored in the commit.
+#
+# OriginalAuthor allows for alternate attribution.
+#
+# OriginalLocation allows for a URL or description of where the patch came
+# from.
+#
+# BugLink is a URL to a Malone bug.
+#
+# Ignore: yes will keep this commit from showing up in the changelog.
+#
+UBUNTU: [Upstream]
+
+# OriginalAuthor: 
+# OriginalLocation: 
+# BugLink: http://bugs.launchpad.net/bugs/<enter bug# here>
+# Ignore: yes
+# Other text below here.
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control-scripts/extra-post b/debian/control-scripts/extra-post
new file mode 100644 (file)
index 0000000..0d3f3ad
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+set -e
+
+case "$0::$1" in
+*.postinst::configure|*.postrm::remove)
+       depmod -a -F /boot/System.map-=V =V || true
+       for dir in "/etc/kernel/postinst.d" "/etc/kernel/postinst.d/=V"
+       do
+               if [ -d "$dir" ]; then
+                       run-parts --verbose --exit-on-error --arg="=V" --arg="/boot/=K-=V" "$dir"
+               fi
+       done
+       ;;
+esac
diff --git a/debian/control-scripts/headers-postinst b/debian/control-scripts/headers-postinst
new file mode 100644 (file)
index 0000000..2fb2be8
--- /dev/null
@@ -0,0 +1,126 @@
+#!/usr/bin/perl
+#                              -*- Mode: Cperl -*- 
+# debian.postinst ---
+# Author           : Manoj Srivastava ( srivasta@pilgrim.umass.edu )
+# Created On       : Sat Apr 27 05:42:43 1996
+# Created On Node  : melkor.pilgrim.umass.edu
+# Last Modified By : Manoj Srivastava
+# Last Modified On : Sat Aug  5 13:20:22 2006
+# Last Machine Used: glaurung.internal.golden-gryphon.com
+# Update Count     : 45
+# Status           : Unknown, Use with caution!
+# HISTORY          :
+# Description      :
+#
+#
+#
+#  arch-tag: 1c716174-2f0a-476d-a626-a1322e62503a
+#
+
+
+$|=1;
+
+# Predefined values:
+my $version           = "=V";
+my $kimage            = "=K";
+my $package_name    = "linux-image-$version";
+
+
+# Ignore all invocations uxcept when called on to configure.
+exit 0 unless ($ARGV[0] && $ARGV[0] =~ /configure/);
+
+#known variables
+my $image_dest      = "/";
+my $realimageloc    = "/boot/";
+my $silent_modules  = '';
+my $modules_base    = '/lib/modules';
+my $CONF_LOC        = '/etc/kernel-img.conf';
+# remove multiple leading slashes; make sure there is at least one.
+$realimageloc  =~ s|^/*|/|o;
+$realimageloc  =~ s|/+|/|o;
+
+chdir '/usr/src' or die "Could not chdir to /usr/src:$!";
+
+if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
+  if (open(CONF, "$CONF_LOC")) {
+    while (<CONF>) {
+      chomp;
+      s/\#.*$//g;
+      next if /^\s*$/;
+
+      $header_postinst_hook   = "$1"  if /^\s*header_postinst_hook\s*=\s*(\S+)/ig;
+    }
+    close CONF;
+  }
+}
+
+sub exec_script {
+  my $type   = shift;
+  my $script = shift;
+  print STDERR "Running $type hook script $script.\n";
+  system ("$script $version $realimageloc$kimage-$version") &&
+    print STDERR "User $type hook script [$script] ";
+  if ($?) {
+    if ($? == -1) {
+      print STDERR "failed to execute: $!\n";
+    }
+    elsif ($? & 127) {
+      printf STDERR "died with signal %d, %s coredump\n",
+        ($? & 127),  ($? & 128) ? 'with' : 'without';
+    }
+    else {
+      printf STDERR "exited with value %d\n", $? >> 8;
+    }
+    exit $? >> 8;
+  }
+}
+sub run_hook {
+  my $type   = shift;
+  my $script = shift;
+  if ($script =~ m,^/,) {
+    # Full path provided for the hook script
+    if (-x "$script") {
+      &exec_script($type,$script);
+    }
+    else {
+      die "The provided $type hook script [$script] could not be run.\n";
+    }
+  }
+  else {
+    # Look for it in a safe path
+    for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
+      if (-x "$path/$script") {
+        &exec_script($type, "$path/$script");
+        return 0;
+      }
+    }
+    # No luck
+    print STDERR "Could not find $type hook script [$script].\n";
+    die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
+  }
+}
+
+## Run user hook script here, if any
+if (-x "$header_postinst_hook") {
+  &run_hook("postinst", $header_postinst_hook);
+}
+
+if (-d "/etc/kernel/header_postinst.d") {
+  print STDERR "Examining /etc/kernel/header_postinst.d.\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/header_postinst.d") &&
+            die "Failed to process /etc/kernel/header_postinst.d";
+}
+
+if (-d "/etc/kernel/header_postinst.d/$version") {
+  print STDERR "Examining /etc/kernel/header_postinst.d/$version.\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/header_postinst.d/$version") &&
+            die "Failed to process /etc/kernel/header_postinst.d/$version";
+}
+
+exit 0;
+
+__END__
diff --git a/debian/control-scripts/postinst b/debian/control-scripts/postinst
new file mode 100644 (file)
index 0000000..808575c
--- /dev/null
@@ -0,0 +1,1137 @@
+#! /usr/bin/perl
+# OriginalAuthor : Manoj Srivastava ( srivasta@pilgrim.umass.edu )
+#
+# Customized for Ubuntu by: Ben Collins <bcollins@ubuntu.com>
+
+#use strict; #for debugging
+use Cwd 'abs_path';
+
+$|=1;
+
+# Predefined values:
+my $version           = "=V";
+my $link_in_boot      = "";  # Should be empty, mostly
+my $no_symlink        = "";   # Should be empty, mostly
+my $reverse_symlink   = "";   # Should be empty, mostly
+my $do_symlink        = "Yes";  # target machine defined
+my $do_boot_enable    = "Yes";  # target machine defined
+my $do_bootfloppy     = "Yes";  # target machine defined
+my $do_bootloader     = "Yes";  # target machine defined
+my $move_image        = '';     # target machine defined
+my $kimage            = "=K";   # Should be empty, mostly
+my $loader            = "=L"; # lilo, silo, quik, palo, vmelilo, nettrom, arcboot or delo
+my $image_dir         = "/boot";        # where the image is located
+my $clobber_modules   = '';          # target machine defined
+my $relative_links    = "";          # target machine defined
+my $initrd            = "YES";        # initrd kernel
+my $do_initrd         = '';     # Normally we do not
+my $use_hard_links    = ''; # hardlinks do not work across fs boundaries
+my $postinst_hook     = '';          #Normally we do not
+my $postrm_hook       = '';          #Normally we do not
+my $preinst_hook      = '';          #Normally we do not
+my $prerm_hook        = '';          #Normally we do not
+my $minimal_swap      = '';          # Do not swap symlinks
+my $ignore_depmod_err = '';          # normally we do not
+my $kernel_arch       = "=B";
+my $ramdisk           = "/usr/sbin/update-initramfs";  # List of tools to create initial ram fs.
+my $notifier          = "/usr/share/update-notifier/notify-reboot-required";
+my $package_name      = "linux-image-$version";
+my $explicit_do_loader = 'Yes';
+
+my $Loader          = "NoLOADER"; #
+$Loader             = "LILO"     if $loader =~ /^lilo/io;
+$Loader             = "SILO"     if $loader =~ /^silo/io;
+$Loader             = "QUIK"     if $loader =~ /^quik/io;
+$Loader             = "yaboot"   if $loader =~ /^yaboot/io;
+$Loader             = "PALO"     if $loader =~ /^palo/io;
+$Loader             = "NETTROM"  if $loader =~ /^nettrom/io;
+$Loader             = "VMELILO"  if $loader =~ /^vmelilo/io;
+$Loader             = "ZIPL"     if $loader =~ /^zipl/io;
+$Loader             = "ELILO"    if $loader =~ /^elilo/io;
+$Loader             = "ARCBOOT"  if $loader =~ /^arcboot/io;
+$Loader             = "DELO"     if $loader =~ /^delo/io;
+
+# This should not point to /tmp, because of security risks.
+my $temp_file_name = "/var/log/$loader" . "_log.$$";
+
+#known variables
+my $image_dest      = "/";
+my $realimageloc    = "/$image_dir/";
+my $have_conffile   = "";
+my $silent_modules  = '';
+my $silent_loader   = '';
+my $warn_reboot     = 'Yes';     # Warn that we are installing a version of
+                                 # the kernel we are running
+
+my $modules_base    = '/lib/modules';
+my $CONF_LOC        = '/etc/kernel-img.conf';
+
+# Ignore all invocations except when called on to configure.
+exit 0 unless $ARGV[0] =~ /configure/;
+
+my $DEBUG = 0;
+
+# Do some preliminary sanity checks here to ensure we actually have an
+# valid image dir
+chdir('/')           or die "could not chdir to /:$!\n";
+die "Internal Error: ($image_dir) is not a directory!\n"
+  unless -d $image_dir;
+
+# remove multiple leading slashes; make sure there is at least one.
+$realimageloc  =~ s|^/*|/|o;
+$realimageloc  =~ s|/+|/|o;
+die "Internal Error: ($realimageloc) is not a directory!\n"
+  unless -d $realimageloc;
+
+if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
+  if (open(CONF, "$CONF_LOC")) {
+    while (<CONF>) {
+      chomp;
+      s/\#.*$//g;
+      next if /^\s*$/;
+
+      $do_symlink      = "" if /^\s*do_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $no_symlink      = "" if /^\s*no_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $reverse_symlink = "" if /^\s*reverse_symlink\s*=\s*(no|false|0)\s*$/ig;
+      $link_in_boot    = "" if /^\s*image_in_boot\s*=\s*(no|false|0)\s*$/ig;
+      $link_in_boot    = "" if /^\s*link_in_boot\s*=\s*(no|false|0)\s*$/ig;
+      $move_image      = "" if /^\s*move_image\s*=\s*(no|false|0)\s*$/ig;
+      $clobber_modules = '' if /^\s*clobber_modules\s*=\s*(no|false|0)\s*$/ig;
+      $do_boot_enable  = '' if /^\s*do_boot_enable\s*=\s*(no|false|0)\s*$/ig;
+      $do_bootfloppy   = '' if /^\s*do_bootfloppy\s*=\s*(no|false|0)\s*$/ig;
+      $relative_links  = '' if /^\s*relative_links \s*=\s*(no|false|0)\s*$/ig;
+      $do_bootloader   = '' if /^\s*do_bootloader\s*=\s*(no|false|0)\s*$/ig;
+      $explicit_do_loader = '' if /^\s*do_bootloader\s*=\s*(no|false|0)\s*$/ig;
+      $do_initrd       = '' if /^\s*do_initrd\s*=\s*(no|false|0)\s*$/ig;
+      $use_hard_links  = '' if /^\s*use_hard_links\s*=\s*(no|false|0)\s*$/ig;
+      $silent_modules  = '' if /^\s*silent_modules\s*=\s*(no|false|0)\s*$/ig;
+      $silent_loader   = '' if /^\s*silent_loader\s*=\s*(no|false|0)\s*$/ig;
+      $warn_reboot     = '' if /^\s*warn_reboot\s*=\s*(no|false|0)\s*$/ig;
+      $minimal_swap    = '' if /^\s*minimal_swap\s*=\s*(no|false|0)\s*$/ig;
+      $ignore_depmod_err = '' if /^\s*ignore_depmod_err\s*=\s*(no|false|0)\s*$/ig;
+
+      $do_symlink      = "Yes" if /^\s*do_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $no_symlink      = "Yes" if /^\s*no_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $reverse_symlink = "Yes" if /^\s*reverse_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $link_in_boot    = "Yes" if /^\s*image_in_boot\s*=\s*(yes|true|1)\s*$/ig;
+      $link_in_boot    = "Yes" if /^\s*link_in_boot\s*=\s*(yes|true|1)\s*$/ig;
+      $move_image      = "Yes" if /^\s*move_image\s*=\s*(yes|true|1)\s*$/ig;
+      $clobber_modules = "Yes" if /^\s*clobber_modules\s*=\s*(yes|true|1)\s*$/ig;
+      $do_boot_enable  = "Yes" if /^\s*do_boot_enable\s*=\s*(yes|true|1)\s*$/ig;
+      $do_bootfloppy   = "Yes" if /^\s*do_bootfloppy\s*=\s*(yes|true|1)\s*$/ig;
+      $do_bootloader   = "Yes" if /^\s*do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
+      $explicit_do_loader = "YES" if /^\s*do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
+      $relative_links  = "Yes" if /^\s*relative_links\s*=\s*(yes|true|1)\s*$/ig;
+      $do_initrd       = "Yes" if /^\s*do_initrd\s*=\s*(yes|true|1)\s*$/ig;
+      $use_hard_links  = "Yes" if /^\s*use_hard_links\s*=\s*(yes|true|1)\s*$/ig;
+      $silent_modules  = 'Yes' if /^\s*silent_modules\s*=\s*(yes|true|1)\s*$/ig;
+      $silent_loader   = 'Yes' if /^\s*silent_loader\s*=\s*(yes|true|1)\s*$/ig;
+      $warn_reboot     = 'Yes' if /^\s*warn_reboot\s*=\s*(yes|true|1)\s*$/ig;
+      $minimal_swap    = 'Yes' if /^\s*minimal_swap\s*=\s*(yes|true|1)\s*$/ig;
+      $ignore_depmod_err = 'Yes' if /^\s*ignore_depmod_err\s*=\s*(yes|true|1)\s*$/ig;
+
+      $image_dest      = "$1"  if /^\s*image_dest\s*=\s*(\S+)/ig;
+      $postinst_hook   = "$1"  if /^\s*postinst_hook\s*=\s*(\S+)/ig;
+      $postrm_hook     = "$1"  if /^\s*postrm_hook\s*=\s*(\S+)/ig;
+      $preinst_hook    = "$1"  if /^\s*preinst_hook\s*=\s*(\S+)/ig;
+      $prerm_hook      = "$1"  if /^\s*prerm_hook\s*=\s*(\S+)/ig;
+      $ramdisk         = "$1"  if /^\s*ramdisk\s*=\s*(.+)$/ig;
+    }
+    close CONF;
+    $have_conffile = "Yes";
+  }
+}
+
+
+
+# For some versions of kernel-package, we had this warning in the
+# postinst, but the rules did not really interpolate the value in.
+# Here is a sanity check.
+my $pattern = "=" . "I";
+$initrd=~ s/^$pattern$//;
+
+if ($link_in_boot) {
+  $image_dest = "/$image_dir/"; # same as realimageloc
+}
+
+# Tack on at least one trainling /
+$image_dest = "$image_dest/";
+$image_dest =~ s|^/*|/|o;
+$image_dest =~ s|/+$|/|o;
+
+if (! -d "$image_dest") {
+  die "Expected Image Destination dir ($image_dest) to be a valid directory!\n";
+}
+
+# sanity
+if (!($do_bootfloppy || $do_bootloader)) {
+  $do_boot_enable = '';
+}
+if ($do_symlink && $no_symlink) {
+  warn "Both do_symlinks and no_symlinks options enabled; disabling no_symlinks\n";
+  $no_symlink = 0;
+}
+
+# most of our work is done in $image_dest (nominally /)
+chdir("$image_dest") or die "could not chdir to $image_dest:$!\n";
+
+# Paranoid check to make sure that the correct value is put in there
+if    (! $kimage)                 { $kimage = "vmlinuz"; } # Hmm. empty
+elsif ($kimage =~ m/^b?uImage$/o) { $kimage = "vmlinuz"; } # these produce vmlinuz
+elsif ($kimage =~ m/^b?zImage$/o) { $kimage = "vmlinuz"; } # these produce vmlinuz
+elsif ($kimage =~ m/^[iI]mage$/o) { my $nop = $kimage;   }
+elsif ($kimage =~ m/^vmlinux$/o)  { my $nop = $kimage;   }
+else                              { $kimage = "vmlinuz"; } # Default
+
+$ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
+
+
+die "Internal Error: Could not find image (" . $realimageloc
+  . "$kimage-$version)\n" unless -e $realimageloc
+  . "$kimage-$version";
+
+# search for the boot loader in the path
+my $loader_exec;
+($loader_exec = $loader)  =~ s|.*/||;
+my ($loaderloc) = grep -x, map "$_/$loader_exec",
+  map { length($_) ? $_ : "." }  split /:/, $ENV{PATH};
+
+
+######################################################################
+######################################################################
+###########        Test whether a relative symlinkwould be OK #######
+######################################################################
+######################################################################
+sub test_relative {
+  my %params = @_;
+  my $cwd;
+
+  die "Internal Error: Missing Required paramater 'Old Dir' "
+    unless $params{'Old Dir'};
+  die "Internal Error: Missing Required paramater New Dir' "
+    unless $params{'New Dir'};
+
+
+  die "Internal Error: No such dir $params{'Old Dir'} "
+    unless -d $params{'Old Dir'};
+  die "Internal Error: No such dir $params{'New Dir'} "
+    unless -d $params{'New Dir'};
+
+  # If the caller specified a test file, and it does not exist try and find
+  # another file to use in its stead.  As we are installing kernels we can
+  # use any versioned file from this kernel which should be in the same place.
+  if (defined $params{'Test File'} and
+      ! -f $params{'Old Dir'} . '/' . $params{'Test File'}) {
+
+      my @possible = glob($params{'Old Dir'} . "/*$version*");
+      if ($#possible >= 0) {
+        $params{'Test File'} = `basename "$possible[0]"`;
+        chomp($params{'Test File'});
+        warn "Test relative: selected $params{'Test File'}"
+          if $DEBUG;
+      }
+  }
+
+  warn "Test relative: testing $params{'Old Dir'} -> $params{'New Dir'}"
+    if $DEBUG;
+  chomp($cwd = `pwd`);
+  chdir ($params{'New Dir'}) or die "Could not chdir to $params{'New Dir'}:$!";
+  my $ok = 0;
+  $params{'Old Dir'}  =~ s|^/*||o;
+  if (-d $params{'Old Dir'} ) {
+    if (defined $params{'Test File'}) {
+      if (-e $params{'Old Dir'} . $params{'Test File'}) {
+        $ok  = 1;
+      }
+    } else {
+      $ok = 1;                  # well, backward compatibility
+    }
+  }
+  chdir ($cwd) or die "Could not chdir to $params{'New Dir'}:$!";
+  return $ok;
+}
+
+######################################################################
+######################################################################
+############
+######################################################################
+######################################################################
+# sub CanonicalizePath {
+#   my $path = join '/', @_;
+#   my @work = split '/', $path;
+#   my @out;
+#   my $is_absolute;
+
+#   if (@work && $work[0] eq "") {
+#     $is_absolute = 1; shift @work;
+#   }
+
+#   while (@work) {
+#     my $seg = shift @work;
+#     if ($seg eq "." || $seg eq "") {
+#     } 
+#     elsif ($seg eq "..") {
+#       if (@out && $out[-1] ne "..") {
+#         pop @out;
+#       } 
+#       else {
+#         # Leading "..", or "../..", etc.
+#         push @out, $seg;
+#       }
+#     } 
+#     else {
+#       push @out, $seg;
+#     }
+#   }
+
+#   unshift @out, "" if $is_absolute;
+#   return join('/', @out);
+# }
+######################################################################
+######################################################################
+############
+######################################################################
+######################################################################
+
+sub spath {
+  my %params = @_;
+
+  die "Missing Required paramater 'Old'" unless $params{'Old'};
+  die "Missing Required paramater 'New'" unless  $params{'New'};
+
+  my @olddir  = split '/', `readlink -q -m $params{'Old'}`;
+  my @newdir  = split '/', `readlink -q -m $params{'New'}`;
+  my @outdir  = @olddir;
+
+  my $out = '';
+  my $i;
+  for ($i = 0; $i <= $#olddir && $i <= $#newdir; $i++) {
+    $out++ if ($olddir[$i] ne $newdir[$i]);
+    shift @outdir unless $out;
+    unshift @outdir, ".." if $out;
+  }
+  if ($#newdir > $#olddir) {
+    for ($i=0; $i < $#newdir; $i++) {
+      unshift @outdir, "..";
+    }
+  }
+  return join ('/', @outdir);
+}
+######################################################################
+######################################################################
+############
+######################################################################
+######################################################################
+
+
+# This routine actually moves the kernel image
+# From: $realimageloc/$kimage-$version (/boot/vmlinuz-2.6.12)
+# To:   $image_dest/$kimage-$version   (/vmlinuz-2.6.12)
+# Note that the image is moved to a versioned destination, but ordinary
+# symlinks we create otherwise are not normally versioned
+sub really_move_image {
+  my $src_dir  = $_[0];
+  my $target   = $_[1];
+  my $dest_dir = $_[2];
+
+  warn "Really move image: src_dir=$src_dir, target=$target,\n destdir=$dest_dir"
+    if $DEBUG;
+  if (-e "$target") {
+    # we should be in dir $dest_dir == $image_dest /, normally
+    rename("$target", "$target.$$") ||
+      die "failed to move " . $dest_dir . "$target:$!";
+    warn "mv $target $target.$$" if $DEBUG;
+  }
+  warn "mv -f $src_dir$target $target" if $DEBUG;
+  my $ret = system("mv -f " . $src_dir . "$target " .
+                   " $target");
+  if ($ret) {
+    die("Failed to move " . $src_dir . "$target to "
+        . $dest_dir . "$target");
+  }
+  # Ok, now we may clobber the previous .old files
+  if (-e "$target.$$") {
+    rename("$target.$$", "$target.old") ||
+      die "failed to move " . $dest_dir . "$target:$!";
+    warn "mv $target.$$ $target " if $DEBUG;
+  }
+}
+
+# Normally called after really_move_image; and only called if we asked for 
+# reversed link this routine reverses the symbolic link that is notmally 
+# created. Since the real kernel image has been moved over to 
+# $image_dest/$kimage-$version. So, this routine links
+# From:   $image_dest/$kimage-$version   (/vmlinuz-2.6.12)
+# To:     $realimageloc/$kimage-$version (/boot/vmlinuz-2.6.12)
+sub really_reverse_link {
+  my $src_dir    = $_[0];
+  my $link_name  = $_[1];
+  my $dest_dir   = $_[2];
+  warn "Really reverse link: src_dir=$src_dir, link name=$link_name\n" .
+    "\tdestdir=$dest_dir" if $DEBUG;
+
+  my $Old = $dest_dir;
+  if (test_relative ('Old Dir' => $Old, 'New Dir' => $src_dir,
+                     'Test File' => "$link_name")) {
+    $Old   =~ s|^/*||o;
+  }
+  # Special case is they are in the same dir
+  my $rel_path = spath('Old' => "$Old", 'New' => "$src_dir" );
+  $Old ="" if $rel_path =~ m/^\s*$/o;
+
+  if ($use_hard_links =~ m/YES/i) {
+    link($Old . "$link_name", $src_dir . "$link_name") ||
+      die("Failed to link " . $dest_dir . "$link_name to " . $src_dir . 
+          "$link_name:$!");
+    warn "ln " . $Old . "$link_name " . $src_dir . "$link_name"  if $DEBUG;
+  }
+  else {
+    symlink($Old . "$link_name", $src_dir . "$link_name") ||
+      die("Failed to symbolic-link " . $dest_dir . "$link_name to " . $src_dir
+          . "$link_name:$!");
+    warn "ln -s " . $Old . "$link_name " . $src_dir . "$link_name" if $DEBUG;
+  }
+}
+
+# This routine is invoked if there is a symbolic link in place
+# in $image_dest/$kimage -- so a symlink exists in the destination.
+# What we are trying to determine is if we need to move the symbolic link over
+# to the the .old location
+sub move_p {
+  my $kimage     = $_[0];       # Name of the symbolic link
+  my $image_dest = $_[1];       # The directory the links goes into
+  my $image_name = $_[2]; 
+  my $src_dir    = $_[3]; 
+  my $force_move = 0;
+  warn "Move?: kimage=$kimage, image_dest=$image_dest, \n" .
+    "\timage_name=$image_name, src_dir=$src_dir" if $DEBUG;
+
+  if ($no_symlink || $reverse_symlink) {
+    # we do not want links, yet we have a symbolic link here!
+    warn "found a symbolic link in " . $image_dest . "$kimage \n" .
+      "even though no_symlink is defined\n" if $no_symlink;
+    warn "found a symbolic link in " . $image_dest . "$kimage \n" .
+      "even though reverse_symlink is defined\n" if $reverse_symlink;
+    # make sure we change this state of affairs
+    $force_move = 1;
+    return $force_move;
+  }
+
+  warn "DEBUG: OK. We found symlink, and we should have a symlink here.\n"
+    if $DEBUG;
+  my $vmlinuz_target = readlink "$kimage";
+  my $real_target = '';
+  my $target = `readlink -q -m "${realimageloc}${kimage}-${version}"`;
+  $real_target = abs_path($vmlinuz_target) if defined($vmlinuz_target);
+
+  if (!defined($vmlinuz_target) || ! -f "$real_target") {
+    # what, a dangling symlink?
+    warn "The link "  . $image_dest . "$kimage is a dangling link" .
+      "to $real_target\n";
+    $force_move = 1;
+    return $force_move;
+  }
+
+
+  warn "DEBUG: The link $kimage points to ($vmlinuz_target)\n" if $DEBUG;
+  warn "DEBUG: ($vmlinuz_target) is really ($real_target)\n" if $DEBUG;
+  my $cwd;
+  chomp ($cwd=`pwd`);
+  if ($vmlinuz_target !~ m|^/|o) {
+    $vmlinuz_target = $cwd . "/" . $vmlinuz_target;
+    $vmlinuz_target =~ s|/+|/|o;
+  }
+  $vmlinuz_target = `readlink -q -m $vmlinuz_target`;
+
+  if ("$vmlinuz_target" ne "$target") {
+    warn "DEBUG: We need to handle this.\n" if $DEBUG;
+    if ($minimal_swap) {
+      warn "DEBUG: Minimal swap.\n" if $DEBUG;
+      if (-l "$kimage.old") {
+        warn "DEBUG: There is an old link at $kimage.old\n" if $DEBUG;
+        my $old_target = readlink "$kimage.old";
+        my $real_old_target = '';
+        $real_old_target=abs_path($old_target) if defined ($old_target);
+
+        if ($real_old_target  && -f "$real_old_target") {
+          if ($old_target !~ m|^/|o) {
+            $old_target = $cwd . "/" . $old_target;
+            $old_target =~ s|/+|/|o;
+          }
+          $old_target = `readlink -q -m $old_target`;
+          if ("$old_target"  ne "$target") {
+            $force_move = 1;
+            warn "DEBUG: Old link ($old_target) does not point to us ($target)\n"
+              if $DEBUG;
+          } 
+          else {            # The .old points to the current
+            warn "$kimage.old --> $target -- doing nothing";
+            $force_move = 0;
+          }
+        } 
+        else { 
+          warn "DEBUG: Well, the old link does not exist -- so we move\n"
+            if $DEBUG;
+          $force_move = 1;
+        }
+      } 
+      else {
+        warn "DEBUG: No .old link -- OK to move\n"
+          if $DEBUG;
+        $force_move = 1;
+      }
+    } 
+    else {
+      warn "DEBUG: ok, minimal swap is no-- so we move.\n"
+        if $DEBUG;
+      $force_move = 1;
+    }
+  }
+  else {                  # already have proper link
+    warn "$kimage($vmlinuz_target) points to $target ($real_target) -- doing nothing";
+    $force_move = 0;
+  }
+  return $force_move;
+}
+
+
+# This routine moves the symbolic link around (/vmlinuz -> /vmlinuz.old)
+# It pays attention to whether we should the fact whether we should be using
+# hard links or not.
+sub really_move_link {
+  my $kimage     = $_[0];       # Name of the symbolic link
+  my $image_dest = $_[1];       # The directory the links goes into
+  my $image_name = $_[2]; 
+  my $src_dir    = $_[3]; 
+  warn "really_move_link: kimage=$kimage, image_dest=$image_dest\n" .
+    "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
+
+  # don't clobber $kimage.old quite yet
+  rename("$kimage", "$kimage.$$") ||
+    die "failed to move " . $image_dest . "$kimage:$!";
+  warn "mv $kimage $kimage.$$" if $DEBUG;
+  my $Old = $src_dir;
+  my $cwd;
+
+  chomp($cwd=`pwd`);
+  if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd,
+                     'Test File' => "$image_name")) {
+    $Old   =~ s|^/*||o;
+  }
+  # Special case is they are in the same dir
+  my $rel_path = spath('Old' => "$Old", 'New' => "$cwd" );
+  $Old ="" if $rel_path =~ m/^\s*$/o;
+
+  if ($use_hard_links =~ m/YES/i) {
+    warn "ln ${Old}${image_name} $kimage" if $DEBUG;
+    if (! link("${Old}${image_name}", "$kimage")) {
+      rename("$kimage.$$", "$kimage");
+      die("Failed to link ${Old}${image_name} to " .
+          "${image_dest}${kimage}:$!");
+    }
+  } 
+  else {
+    warn "ln -s ${Old}${image_name} $kimage" if $DEBUG;
+    if (! symlink("${Old}${image_name}", "$kimage")) {
+      rename("$kimage.$$", "$kimage");
+      die("Failed to symbolic-link ${Old}${image_name} to " .
+          "${image_dest}${kimage}:$!");
+    }
+  }
+
+  # Ok, now we may clobber the previous .old file
+  if (-l "$kimage.old" || ! -e "$kimage.old" ) {
+    rename("$kimage.$$", "$kimage.old");
+    warn "mv $kimage.$$ $kimage.old" if $DEBUG;
+  }
+  else {
+    warn "$kimage.old is not a symlink, not clobbering\n";
+    warn "rm $kimage.$$";
+    unlink "$kimage.$$" if $DEBUG;
+  }
+}
+
+# This routine handles a request to do symlinks, but there is no
+# symlink file already there.  Either we are supposed to use copy, or we are
+# installing on a pristine system, or the user does not want symbolic links at
+# all.  We use a configuration file to tell the last two cases apart, creating
+# a config file if needed.
+sub handle_missing_link {
+  my $kimage     = $_[0];       # Name of the symbolic link
+  my $image_dest = $_[1];       # The directory the links goes into
+  my $image_name = $_[2]; 
+  my $src_dir    = $_[3]; 
+  warn "handle_missing_link: kimage=$kimage, image_dest=$image_dest\n" .
+    "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
+
+  if ($no_symlink) {
+    warn "cp -a --backup=t $realimageloc$image_name $kimage" if $DEBUG;
+    my $ret = system("cp -a --backup=t " . $realimageloc .
+                     "$image_name "   . " $kimage");
+    if ($ret) {
+      die("Failed to copy " . $realimageloc . "$image_name to "
+          . $image_dest . "$kimage");
+    }
+  } 
+  elsif ($reverse_symlink) {
+    warn "mv -f $realimageloc$image_name $kimage" if $DEBUG;
+    my $ret = system("mv -f " . $realimageloc . "$image_name "
+                     . "$kimage");
+    if ($ret) {
+      die("Failed to move " . $realimageloc . "$image_name to "
+          . $image_dest . "$kimage");
+    }
+  } 
+  else {
+    if (! $have_conffile) {
+      my $ret;
+      my $answer='';
+      $do_symlink = "Yes";
+
+      if (open(CONF, ">$CONF_LOC")) {
+        print CONF "# Kernel Image management overrides\n";
+        print CONF "# See kernel-img.conf(5) for details\n";
+        if ($loader =~ /palo/i) {
+          print CONF "link_in_boot = Yes\n";
+          print CONF "do_symlinks = Yes\n";
+          print CONF "relative_links = Yes\n";
+          print CONF "do_bootloader = No\n";
+        } else {
+          print CONF "do_symlinks = $do_symlink\n";
+        }
+        close CONF;
+      }
+      $have_conffile = "Yes";
+    }
+  }
+
+  if (! $no_symlink && $do_symlink =~ /Yes/i) {
+    my $Old = $realimageloc;
+    my $New = $image_dest;
+    my $Name = "$image_name";
+    my $Link_Dest = "$kimage";
+
+    if ($reverse_symlink) {
+      $Old = $image_dest;
+      $New = $realimageloc;
+      $Name = "$kimage";
+      $Link_Dest = $realimageloc . "$image_name";
+    }
+    if (test_relative ('Old Dir' => $Old,
+                       'New Dir' => $New,
+                       'Test File' => $Name)) {
+      $Old   =~ s|^/*||o;
+    }
+    # Special case is they are in the same dir
+    my $rel_path = spath('Old' => "$Old", 'New' => "$New" );
+    $Old ="" if $rel_path =~ m/^\s*$/o;
+
+    symlink($Old . "$Name", "$Link_Dest") ||
+      die("Failed to symbolic-link ${Old}$Name to $Link_Dest:$!");
+    warn "ln -s ${Old}$Name $Link_Dest" if $DEBUG;
+
+  }
+}
+
+# This routine handles the rest of the cases, where the user has requested 
+# non-traditional handling, like using cp, or reverse symlinks, or hard links.
+sub handle_non_symlinks {
+  my $kimage     = $_[0];       # Name of the symbolic link
+  my $image_dest = $_[1];       # The directory the links goes into
+  my $image_name = $_[2]; 
+  my $src_dir    = $_[3]; 
+  warn "handle_non_link: kimage=$kimage, image_dest=$image_dest\n" .
+    "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
+
+  # Save the current image. We do this in all four cases
+  rename("$kimage", "$kimage.$$") || 
+    die "failed to move " . $image_dest . "$kimage:$!";
+  warn "mv $kimage $kimage.$$" if $DEBUG;
+
+  ##,#### 
+  # case One
+  #`####
+  if ($no_symlink) {
+    # Maybe /$image_dest is on a dos system?
+    warn "cp -a --backup=t $realimageloc$image_name $kimage" if $DEBUG;
+    my $ret = system("cp -a --backup=t " . $realimageloc
+                     . "$image_name " . "$kimage");
+    if ($ret) {
+      if (-e "$kimage.$$") {
+        rename("$kimage.$$", "$kimage");
+        warn "mv $kimage.$$ $kimage" if $DEBUG;
+      }
+      die("Failed to copy " . $realimageloc . "$image_name to "
+          . $image_dest . "$kimage");
+    }
+  }
+  ##,#### 
+  # case Two
+  #`####
+  elsif ($reverse_symlink) {  # Maybe /$image_dest is on a dos system?
+    warn "mv -f  $realimageloc$image_name $kimage" if $DEBUG;
+    my $ret = system("mv -f " . $realimageloc . "$image_name "
+                     . $image_dest . "$kimage");
+    if ($ret) {
+      if (-e "$kimage.$$") {
+        rename("$kimage.$$", "$kimage");
+        warn "mv $kimage.$$ $kimage" if $DEBUG;
+      }
+      die("Failed to move " . $realimageloc . "$image_name to "
+          . $image_dest . "$kimage");
+    }
+    my $Old = $image_dest;
+    if (test_relative ('Old Dir' => $Old, 'New Dir' => $realimageloc,
+                       'Test File' => "$kimage")) {
+      $Old   =~ s|^/*||o;
+    }
+    # Special case is they are in the same dir
+    my $rel_path = spath('Old' => "$Old", 'New' => "$realimageloc" );
+    $Old ="" if $rel_path =~ m/^\s*$/o;
+
+    if ($use_hard_links =~ m/YES/i) {
+      warn "ln " . $Old . "$kimage " . $realimageloc . "$image_name" if $DEBUG;
+      if (! link($Old . "$kimage", $realimageloc . "$image_name")) {
+        warn "Could not link " . $image_dest .
+          "$kimage to $image_name :$!";
+      }
+    }
+    else {
+      warn "ln -s " . $Old . "$kimage " . $realimageloc . "$image_name" if $DEBUG;
+      if (! symlink($Old . "$kimage", $realimageloc . "$image_name")) {
+        warn "Could not symlink " . $image_dest .
+          "$kimage to $image_name :$!";
+      }
+    }
+  }
+  ##,####
+  # case Three
+  #`####
+  elsif ($use_hard_links =~ m/YES/i ) {
+    # Ok then. this ought to be a hard link, and hence fair game
+    # don't clobber $kimage.old quite yet
+    my $Old = $realimageloc;
+    my $cwd;
+    chomp($cwd=`pwd`);
+    if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd,
+                       'Test File' => "$image_name")) {
+      $Old   =~ s|^/*||o;
+    }
+    # Special case is they are in the same dir
+    my $rel_path = spath('Old' => "$Old", 'New' => "$cwd" );
+    $Old ="" if $rel_path =~ m/^\s*$/o;
+
+    warn "ln " . $Old . "$image_name " . "$kimage" if $DEBUG;
+    if (! link($Old . "$image_name", "$kimage")) {
+      warn "mv $kimage.$$ $kimage" if $DEBUG;
+      rename("$kimage.$$", "$kimage");
+      die("Failed to link " . $realimageloc . "$image_name to "
+          . $image_dest . "$kimage");
+    }
+  }
+  ##,####
+  # case Five!?!
+  #`####
+  elsif ($do_symlink) {
+    # Ok then. this ought to be a symlink, and hence fair game
+    # don't clobber $kimage.old quite yet
+    my $Old = $realimageloc;
+    my $cwd;
+    chomp($cwd=`pwd`);
+    if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd,
+                       'Test File' => "$image_name")) {
+      $Old   =~ s|^/*||o;
+    }
+    # Special case is they are in the same dir
+    my $rel_path = spath('Old' => "$Old", 'New' => "$cwd" );
+    $Old ="" if $rel_path =~ m/^\s*$/o;
+
+    warn "symlink " . $Old . "$image_name " . "$kimage" if $DEBUG;
+    if (! symlink($Old . "$image_name", "$kimage")) {
+      warn "mv $kimage.$$ $kimage" if $DEBUG;
+      rename("$kimage.$$", "$kimage");
+      die("Failed to link " . $realimageloc . "$image_name to "
+          . $image_dest . "$kimage");
+    }
+  }
+  ##,####
+  # case Four
+  #`####
+  else {
+    # We just use cp
+    warn "cp -a --backup=t $realimageloc$image_name $kimage" if $DEBUG;
+    my $ret = system("cp -a --backup=t " . $realimageloc
+                     . "$image_name " . "$kimage");
+    if ($ret) {
+      if (-e "$kimage.$$") {
+        warn "mv $kimage.$$ $kimage" if $DEBUG;
+        rename("$kimage.$$", "$kimage");
+      }
+      die("Failed to copy " . $realimageloc . "$image_name to "
+          . $image_dest . "$kimage");
+    }
+  }
+  # Ok, now we may clobber the previous .old file
+  warn "mv $kimage.$$ $kimage.old if -e $kimage.$$" if $DEBUG;
+  rename("$kimage.$$", "$kimage.old") if -e "$kimage.$$";
+}
+
+# This routine is responsible for setting up the symbolic links
+# So, the actual kernel image lives in
+# $realimageloc/$image_name (/boot/vmlinuz-2.6.12).
+# This routine creates symbolic links in $image_dest/$kimage (/vmlinuz)
+sub image_magic {
+  my $kimage     = $_[0];       # Name of the symbolic link
+  my $image_dest = $_[1];       # The directory the links goes into
+  my $image_name = "$kimage-$version";
+  my $src_dir    = $realimageloc;
+  warn "image_magic: kimage=$kimage, image_dest=$image_dest\n" .
+    "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
+
+  # Well, in any case, if the destination (the symlink we are trying
+  # to create) is a directory, we should do nothing, except throw a
+  # diagnostic.
+  if (-d "$kimage" ) {
+    die ("Hmm. $kimage is a directory, which I did not expect.  I am\n" .
+         "trying to create a symbolic link with that name linked to \n" .
+         "$image_dest . Since a directory exists here, my assumptions \n" .
+         "are way off, and I am aborting.\n" );
+    exit (3);
+  }
+
+  if ($move_image) {   # Maybe $image_dest is in on dos, or something?
+    #                   source dir,    link name,        dest dir
+    really_move_image(  $realimageloc, $image_name, $image_dest);
+    really_reverse_link($realimageloc, $image_name, $image_dest)
+      if $reverse_symlink;
+    return;
+  }
+
+  if (-l "$kimage") {           # There is a symbolic link
+    warn "DEBUG: There is a symlink for $kimage\n" if $DEBUG;
+    my $force_move = move_p($kimage, $image_dest, $image_name, $src_dir);
+
+    if ($force_move) {
+      really_move_link($kimage, $image_dest, $image_name, $src_dir);
+    }
+  }
+  elsif (! -e "$kimage") {
+    # Hmm. Pristine system? How can that be? Installing from scratch?
+    # Or maybe the user does not want a symbolic link here.
+    # Possibly they do not want a link here. (we should be in /
+    # here[$image_dest, really]
+    handle_missing_link($kimage, $image_dest, $image_name, $src_dir);
+  }
+  elsif (-e "$kimage" ) {
+    # OK, $kimage exists -- but is not a link
+    handle_non_symlinks($kimage, $image_dest, $image_name, $src_dir);
+  }
+}
+
+######################################################################
+######################################################################
+######################################################################
+######################################################################
+
+# We may not have any modules installed
+if ( -d "$modules_base/$version" ) {
+  print STDERR "Running depmod.\n";
+  my $ret = system("depmod -a $version");
+  if ($ret) {
+    print STDERR "Failed to run depmod\n";
+    exit(1);
+  }
+}
+
+
+
+sub find_initrd_tool {
+  my $hostversion = shift;
+  my $version = shift;
+  print STDERR "Finding valid ramdisk creators.\n";
+  my @ramdisks =
+    grep {
+      my $args = 
+        "$_ " .
+          "--supported-host-version=$hostversion " .
+            "--supported-target-version=$version " .
+              "1>/dev/null 2>&1"
+                ;
+      system($args) == 0;
+    }
+      split (/[:,\s]+/, $ramdisk);
+}
+
+# The initrd symlink should probably be in the same dir that the
+# symlinks are in
+if ($initrd) {
+  my $success = 0;
+
+  # Update-initramfs is called slightly different than mkinitrd and
+  # mkinitramfs. XXX It should really be made compatible with this stuff
+  # some how.
+  my $upgrading = 1;
+  if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
+    $upgrading = 0;
+  }
+  my $ret = system("$ramdisk " . ($upgrading ? "-u" : "-c") . " -k " . $version . " >&2");
+  $success = 1 unless $ret;
+  die "Failed to create initrd image.\n" unless $success;
+  if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
+    image_magic("initrd.img", $image_dest);
+  }
+  else {
+    lstat("initrd.img");
+    if (! -e _) {
+      handle_missing_link("initrd.img", $image_dest, "initrd.img-$version",
+                          $realimageloc);
+    }
+    else {
+      print STDERR
+        "Not updating initrd symbolic links since we are being updated/reinstalled \n";
+      print STDERR
+        "($ARGV[1] was configured last, according to dpkg)\n";
+    }
+  }
+
+  if ($initrd && -l "initrd" ) {
+    unlink "initrd";
+  }
+
+  if ($initrd && -l "$image_dir/initrd" && ! $link_in_boot) {
+    unlink "$image_dir/initrd";
+  }
+}
+else {                        # Not making an initrd emage
+  if (-l "initrd.img") {
+    # Ooh, last image was an initrd image? in any case, we should move it. 
+    my $target = readlink "initrd.img";
+    my $real_target = '';
+    $real_target = abs_path($target) if defined ($target);
+
+    if (!defined($target) || ! -f "$real_target") {
+      # Eh. dangling link. can safely be removed.
+      unlink("initrd.img");
+    } else {
+      if (-l "initrd.img.old" || ! -e "initrd.img.old" ) {
+        rename("initrd.img", "initrd.img.old");
+      } else {
+        warn "initrd.img.old is not a symlink, not clobbering\n";
+        unlink("initrd.img");
+      }
+    }
+  }
+}
+
+# Warn of a reboot
+if (-x $notifier) {
+  system($notifier);
+}
+
+# Let programs know not to hibernate if the kernel that would be used for
+# resume-from-hibernate is likely to differ from the currently running kernel.
+system("mountpoint -q /var/run");
+if ($? eq 0) {
+       system("touch /var/run/do-not-hibernate");
+}
+
+# Only change the symlinks if we are not being upgraded
+if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/og) {
+  image_magic($kimage, $image_dest);
+}
+else {
+  lstat("$kimage");
+  if (! -e _) {
+    handle_missing_link($kimage, $image_dest, "$kimage-$version", 
+                        $realimageloc);
+  }
+  else {
+    print STDERR
+      "Not updating image symbolic links since we are being updated/reinstalled \n";
+    print STDERR
+      "($ARGV[1] was configured last, according to dpkg)\n";
+  }
+}
+
+# We used to have System.* files in /
+if (-e "/System.map" || -e "/System.old") {
+  unlink '/System.map' if -e '/System.map';
+  unlink '/System.old' if -e '/System.old';
+}
+
+# creating some info about kernel and initrd
+if ($DEBUG) {
+  my $ksize=sprintf("%.0f",(stat($realimageloc .
+                                 "$kimage-$version"))[7]/1024)."kB";
+  my $initrdsize='';
+  if ($initrd) {
+    $initrdsize=sprintf("%.0f",(stat($realimageloc .
+                                     "initrd.img-$version"))[7]/1024)."kB";
+  }
+
+  print STDERR <<"EOMSG";
+A new kernel image has been installed at $realimageloc$kimage-$version
+ (Size: $ksize)
+
+Symbolic links, unless otherwise specified, can be found in $image_dest
+
+EOMSG
+  ;
+
+  if ($initrd) {
+    print STDERR <<"EOMSGA";
+
+ Initial rootdisk image: ${realimageloc}initrd.img-$version (Size: $initrdsize)
+EOMSGA
+    ;
+  }
+}
+
+# set the env var stem
+$ENV{'STEM'} = "linux";
+sub exec_script {
+  my $type   = shift;
+  my $script = shift;
+  print STDERR "Running $type hook script $script.\n";
+  system ("$script $version $realimageloc$kimage-$version") &&
+    print STDERR "User $type hook script [$script] ";
+  if ($?) {
+    if ($? == -1) {
+      print STDERR "failed to execute: $!\n";
+    }
+    elsif ($? & 127) {
+      printf STDERR "died with signal %d, %s coredump\n",
+        ($? & 127),  ($? & 128) ? 'with' : 'without';
+    }
+    else {
+      printf STDERR "exited with value %d\n", $? >> 8;
+    }
+    exit $? >> 8;
+  }
+}
+sub run_hook {
+  my $type   = shift;
+  my $script = shift;
+  if ($script =~ m,^/,) {
+    # Full path provided for the hook script
+    if (-x "$script") {
+      &exec_script($type,$script);
+    }
+    else {
+      die "The provided $type hook script [$script] could not be run.\n";
+    }
+  }
+  else {
+    # Look for it in a safe path
+    for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
+      if (-x "$path/$script") {
+        &exec_script($type, "$path/$script");
+        return 0;
+      }
+    }
+    # No luck
+    print STDERR "Could not find $type hook script [$script].\n";
+    die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
+  }
+}
+
+my $options;
+for (@ARGV) {
+       s,','\\'',g;
+       $options .= " '$_'";
+}
+$ENV{'DEB_MAINT_PARAMS'}="$options";
+
+## Run user hook script here, if any
+if ($postinst_hook) {
+  &run_hook("postinst", $postinst_hook);
+}
+
+if (-d "/etc/kernel/postinst.d") {
+  print STDERR "Examining /etc/kernel/postinst.d.\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/postinst.d") &&
+            die "Failed to process /etc/kernel/postinst.d";
+}
+
+if (-d "/etc/kernel/postinst.d/$version") {
+  print STDERR "Examining /etc/kernel/postinst.d/$version.\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/postinst.d/$version") &&
+            die "Failed to process /etc/kernel/postinst.d/$version";
+}
+
+LOADER: {
+  last unless $do_boot_enable; # Exit if explicitly asked to
+
+  last if $loader =~ /silo/i; # SILO does not have to be executed.
+  last if $loader =~ /yaboot/i; # yaboot does not have to be executed.
+  last if $loader =~ /milo/i; # MILO does not have to be executed.
+  last if $loader =~ /nettrom/i; # NETTROM does not have to be executed.
+  last if $loader =~ /arcboot/i; # ARCBOOT does not have to be executed.
+  last if $loader =~ /delo/i; # DELO does not have to be executed.
+  last if $loader =~ /quik/i; # maintainer asked quik invocation to be ignored
+
+  last unless $loaderloc;
+  last unless -x $loaderloc;
+  last unless $do_bootloader;
+
+  if (-T "/etc/$loader.conf") {
+    # Trust and use the existing lilo.conf.
+    print STDERR "You already have a $Loader configuration in /etc/$loader.conf\n";
+    my $ret = &run_lilo();
+    exit $ret if $ret;
+  }
+}
+
+
+sub run_lilo (){
+  my $ret;
+  # Try and figure out if the user really wants lilo to be run --
+  # since the default is to run the boot laoder, which is ! grub -- but
+  # the user may be using grub now, and not changed the default.
+
+  # So, if the user has explicitly asked for the loader to be run, or
+  # if there is no postinst hook, or if there is no grub installed --
+  # we are OK. Or else, we ask.
+  if ($explicit_do_loader || (! ($postinst_hook && -x '/usr/sbin/grub')))  {
+    print STDERR "Running boot loader as requested\n";
+  } else {
+    print STDERR "Ok, not running $loader\n";
+  }
+  if ($loader =~ /^lilo/io or $loader =~ /vmelilo/io) {
+    print STDERR "Testing $loader.conf ... \n";
+    unlink $temp_file_name;     # security
+    $ret = system("$loaderloc -t >$temp_file_name 2>&1");
+    if ($ret) {
+      print STDERR "Boot loader test failed\n";
+      return $ret;
+    }
+    unlink "$temp_file_name";
+    print STDERR "Testing successful.\n";
+    print STDERR "Installing the ";
+    print STDERR "partition " if $loader =~ /^lilo/io;
+    print STDERR "boot sector... \n";
+  }
+
+  print STDERR "Running $loaderloc  ... \n";
+  if ($loader =~ /^elilo/io) {
+    $ret = system("$loaderloc 2>&1 | tee $temp_file_name");
+  } else {
+    $ret = system("$loaderloc >$temp_file_name 2>&1");
+  }
+  if ($ret) {
+    print STDERR "Boot loader failed to run\n";
+    return $ret;
+  }
+  unlink $temp_file_name;
+  print STDERR "Installation successful.\n";
+  return 0;
+}
+
+exit 0;
+
+__END__
+
diff --git a/debian/control-scripts/postrm b/debian/control-scripts/postrm
new file mode 100644 (file)
index 0000000..227e351
--- /dev/null
@@ -0,0 +1,361 @@
+#! /usr/bin/perl
+#                              -*- Mode: Cperl -*- 
+# image.postrm --- 
+# Author           : Manoj Srivastava ( srivasta@glaurung.green-gryphon.com ) 
+# Created On       : Sat May 15 11:05:13 1999
+# Created On Node  : glaurung.green-gryphon.com
+# Last Modified By : Manoj Srivastava
+# Last Modified On : Wed Sep 13 11:26:19 2006
+# Last Machine Used: glaurung.internal.golden-gryphon.com
+# Update Count     : 57
+# Status           : Unknown, Use with caution!
+# HISTORY          : 
+# Description      : 
+# 
+#     $Id: image.postrm,v 1.31 2003/10/07 16:24:20 srivasta Exp $
+#
+
+
+# 
+#use strict; #for debugging
+use Cwd 'abs_path';
+
+$|=1;
+
+# Predefined values:
+my $version           = "=V";
+my $link_in_boot      = "";    # Should be empty, mostly
+my $no_symlink        = "";    # Should be empty, mostly
+my $reverse_symlink   = "";    # Should be empty, mostly
+my $do_symlink        = "Yes"; # target machine defined
+my $do_boot_enable    = "Yes"; # target machine defined
+my $do_bootfloppy     = "Yes"; # target machine defined
+my $do_bootloader     = "Yes"; # target machine defined
+my $move_image        = '';       # target machine defined
+my $kimage            = "=K";  # Should be empty, mostly
+my $loader            = "=L";     # lilo, silo, quik, palo, vmelilo, or nettrom
+my $image_dir         = "/boot";     # where the image is located
+my $clobber_modules   = '';       # target machine defined
+my $initrd            = "YES";     # initrd kernel
+my $do_initrd         = '';       # Normally, we don't
+my $warn_initrd       = 'YES';    # Normally we do
+my $use_hard_links    = '';       # hardlinks do not work across fs boundaries
+my $postinst_hook     = '';       #Normally we do not
+my $postrm_hook       = '';       #Normally we do not
+my $preinst_hook      = '';       #Normally we do not
+my $prerm_hook        = '';       #Normally we do not
+my $minimal_swap      = '';       # Do not swap symlinks
+my $ignore_depmod_err = '';    # normally we do not
+my $relink_build_link = 'YES'; # There is no harm in checking the link
+my $force_build_link  = '';    # we shall not create a dangling link
+my $kernel_arch       = "=B";
+my $ramdisk           = "/usr/sbin/update-initramfs";
+my $package_name    = "linux-image-$version";
+
+my $Loader          = "NoLOADER"; # 
+$Loader             = "LILO"     if $loader =~ /^lilo/io;
+$Loader             = "SILO"     if $loader =~ /^silo/io;
+$Loader             = "QUIK"     if $loader =~ /^quik/io;
+$Loader             = "yaboot"   if $loader =~ /^yaboot/io;
+$Loader             = "PALO"     if $loader =~ /^palo/io;
+$Loader             = "NETTROM"  if $loader =~ /^nettrom/io;
+$Loader             = "VMELILO"  if $loader =~ /^vmelilo/io;
+$Loader             = "ZIPL"     if $loader =~ /^zipl/io;
+$Loader             = "ELILO"    if $loader =~ /^elilo/io;
+
+
+# This should not point to /tmp, because of security risks.
+my $temp_file_name = "/var/log/$loader" . "_log.$$";
+
+#known variables
+my @boilerplate     = ();
+my @silotemplate    = ();
+my @quiktemplate    = ();
+my @palotemplate    = ();
+my @vmelilotemplate = ();
+my $bootdevice      = '';
+my $rootdevice      = '';
+my $rootdisk        = '';
+my $rootpartition   = '';
+my $image_dest      = "/";
+my $realimageloc    = "/$image_dir/";
+my $have_conffile   = "";
+my $CONF_LOC        = '/etc/kernel-img.conf';
+my $relative_links = '';
+my $silent_modules  = '';
+my $silent_loader   = '';
+my $warn_reboot     = 'Yes';     # Warn that we are installing a version of
+                                 # the kernel we are running
+
+chdir('/')           or die "could not chdir to /:$!\n";
+# remove multiple leading slashes; make sure there is at least one.
+$realimageloc  =~ s|^/*|/|o;
+$realimageloc  =~ s|/+|/|o;
+
+
+if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
+  if (open(CONF, "$CONF_LOC")) {
+    while (<CONF>) {
+      chomp;
+      s/\#.*$//g;
+      next if /^\s*$/;
+
+      $do_symlink      = "" if /^\s*do_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $no_symlink      = "" if /^\s*no_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $reverse_symlink = "" if /^\s*reverse_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $link_in_boot    = "" if /^\s*image_in_boot\s*=\s*(no|false|0)\s*$/ig;
+      $link_in_boot    = "" if /^\s*link_in_boot\s*=\s*(no|false|0)\s*$/ig;
+      $move_image      = "" if /^\s*move_image\s*=\s*(no|false|0)\s*$/ig;
+      $clobber_modules = '' if /^\s*clobber_modules\s*=\s*(no|false|0)\s*$/ig;
+      $do_boot_enable  = '' if /^\s*do_boot_enable\s*=\s*(no|false|0)\s*$/ig;
+      $do_bootfloppy   = '' if /^\s*do_bootfloppy\s*=\s*(no|false|0)\s*$/ig;
+      $relative_links  = '' if /^\s*relative_links \s*=\s*(no|false|0)\s*$/ig;
+      $do_bootloader   = '' if /^\s*do_bootloader\s*=\s*(no|false|0)\s*$/ig;
+      $do_initrd       = '' if /^\s*do_initrd\s*=\s*(no|false|0)\s*$/ig;
+      $warn_initrd     = '' if /^\s*warn_initrd\s*=\s*(no|false|0)\s*$/ig;
+      $use_hard_links  = '' if /^\s*use_hard_links\s*=\s*(no|false|0)\s*$/ig;
+      $silent_modules  = '' if /^\s*silent_modules\s*=\s*(no|false|0)\s*$/ig;
+      $silent_loader   = '' if /^\s*silent_loader\s*=\s*(no|false|0)\s*$/ig;
+      $warn_reboot     = '' if /^\s*warn_reboot\s*=\s*(no|false|0)\s*$/ig;
+      $minimal_swap    = '' if /^\s*minimal_swap\s*=\s*(no|false|0)\s*$/ig;
+      $ignore_depmod_err = '' if /^\s*ignore_depmod_err\s*=\s*(no|false|0)\s*$/ig;
+      $relink_build_link = '' if /^\s*relink_build_link\s*=\s*(no|false|0)\s*$/ig;
+      $force_build_link = '' if /^\s*force_build_link\s*=\s*(no|false|0)\s*$/ig;
+
+      $do_symlink      = "Yes" if /^\s*do_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $no_symlink      = "Yes" if /^\s*no_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $reverse_symlink = "Yes" if /^\s*reverse_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $link_in_boot    = "Yes" if /^\s*image_in_boot\s*=\s*(yes|true|1)\s*$/ig;
+      $link_in_boot    = "Yes" if /^\s*link_in_boot\s*=\s*(yes|true|1)\s*$/ig;
+      $move_image      = "Yes" if /^\s*move_image\s*=\s*(yes|true|1)\s*$/ig;
+      $clobber_modules = "Yes" if /^\s*clobber_modules\s*=\s*(yes|true|1)\s*$/ig;
+      $do_boot_enable  = "Yes" if /^\s*do_boot_enable\s*=\s*(yes|true|1)\s*$/ig;
+      $do_bootfloppy   = "Yes" if /^\s*do_bootfloppy\s*=\s*(yes|true|1)\s*$/ig;
+      $do_bootloader   = "Yes" if /^\s*do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
+      $relative_links  = "Yes" if /^\s*relative_links\s*=\s*(yes|true|1)\s*$/ig;
+      $do_initrd       = "Yes" if /^\s*do_initrd\s*=\s*(yes|true|1)\s*$/ig;
+      $warn_initrd     = "Yes" if /^\s*warn_initrd\s*=\s*(yes|true|1)\s*$/ig;
+      $use_hard_links  = "Yes" if /^\s*use_hard_links\s*=\s*(yes|true|1)\s*$/ig;
+      $silent_modules  = 'Yes' if /^\s*silent_modules\s*=\s*(yes|true|1)\s*$/ig;
+      $silent_loader   = 'Yes' if /^\s*silent_loader\s*=\s*(yes|true|1)\s*$/ig;
+      $warn_reboot     = 'Yes' if /^\s*warn_reboot\s*=\s*(yes|true|1)\s*$/ig;
+      $minimal_swap    = 'Yes' if /^\s*minimal_swap\s*=\s*(yes|true|1)\s*$/ig;
+      $ignore_depmod_err = 'Yes' if /^\s*ignore_depmod_err\s*=\s*(yes|true|1)\s*$/ig;
+      $relink_build_link = 'Yes' if /^\s*relink_build_link\s*=\s*(yes|true|1)\s*$/ig;
+      $force_build_link = 'Yes' if /^\s*force_build_link\s*=\s*(yes|true|1)\s*$/ig;
+
+      $image_dest      = "$1"  if /^\s*image_dest\s*=\s*(\S+)/ig;
+      $postinst_hook   = "$1"  if /^\s*postinst_hook\s*=\s*(\S+)/ig;
+      $postrm_hook     = "$1"  if /^\s*postrm_hook\s*=\s*(\S+)/ig;
+      $preinst_hook    = "$1"  if /^\s*preinst_hook\s*=\s*(\S+)/ig;
+      $prerm_hook      = "$1"  if /^\s*prerm_hook\s*=\s*(\S+)/ig;
+      $ramdisk         = "$1"  if /^\s*ramdisk\s*=\s*(.+)$/ig;
+    }
+    close CONF;
+    $have_conffile = "Yes";
+  }
+}
+
+if ($link_in_boot) {
+  $image_dest = "/$image_dir/";
+  $image_dest =~ s|^/*|/|o;
+}
+
+$image_dest = "$image_dest/";
+$image_dest =~ s|/+$|/|o;
+
+# The destdir may be gone by now.
+if (-d "$image_dest") {
+  chdir("$image_dest") or die "could not chdir to $image_dest:$!\n";
+}
+
+# Paranoid check to make sure that the correct value is put in there
+if (! $kimage)                    {$kimage = "vmlinuz"} # Hmm. empty
+elsif ($kimage =~ m/^b?uImage$/o) {$kimage = "vmlinuz"} # these produce vmlinuz
+elsif ($kimage =~ m/^b?zImage$/o) {$kimage = "vmlinuz"} # these produce vmlinuz
+elsif ($kimage =~ m/^[iI]mage$/o) { my $nop = $kimage;}
+elsif ($kimage =~ m/^vmlinux$/o)  { my $nop = $kimage;}
+else                              {$kimage = "vmlinuz"} # default
+
+$ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
+
+
+######################################################################
+######################################################################
+############
+######################################################################
+######################################################################
+sub remove_sym_link {
+  my $bad_image = $_[0];
+
+  warn "Removing symbolic link $bad_image \n";
+  if ($loader =~ /lilo/i) 
+    {
+      warn "Unless you used the optional flag in lilo, \n";
+    }
+  warn " you may need to re-run your boot loader" . ($loader ? "[$loader]":"")
+    . "\n";
+  # Remove the dangling link
+  unlink "$bad_image";
+}
+
+######################################################################
+######################################################################
+############
+######################################################################
+######################################################################
+sub CanonicalizePath {
+  my $path = join '/', @_;
+  my @work = split '/', $path;
+  my @out;
+  my $is_absolute;
+
+  if (@work && $work[0] eq "") { $is_absolute = 1; shift @work; }
+
+  while (@work) {
+    my $seg = shift @work;
+    if ($seg eq "." || $seg eq "") {
+    } elsif ($seg eq "..") {
+      if (@out && $out[-1] ne "..") {
+        pop @out;
+      } else {
+        # Leading "..", or "../..", etc.
+        push @out, $seg;
+      }
+    } else {
+      push @out, $seg;
+    }
+  }
+
+  unshift @out, "" if $is_absolute;
+  return join('/', @out);
+}
+
+######################################################################
+######################################################################
+############
+######################################################################
+######################################################################
+# This removes dangling symlinks. What do we do about hard links? Surely a 
+# something with the nane $image_dest . "$kimage" ought not to be left behind? 
+sub image_magic {
+  my $kimage = $_[0];
+  my $image_dest = $_[1];
+
+  if (-l "$kimage") {
+    # There is a symbolic link
+    my $force_move = 0;
+    my $vmlinuz_target = readlink "$kimage";
+    my $real_target = '';
+    $real_target = abs_path($vmlinuz_target) if defined ($vmlinuz_target);
+    if (!defined($vmlinuz_target) || ! -f "$real_target") {
+      # what, a dangling symlink?
+      warn "The link "  . $image_dest . "$kimage is a damaged link\n";
+      # Remove the dangling link
+      &remove_sym_link("$kimage");
+    }
+    else {
+      my $canonical_target = CanonicalizePath("$vmlinuz_target");
+      if (! -e $canonical_target) {
+       warn "The link "  . $image_dest . "$kimage is a dangling link\n";
+       &remove_sym_link("$kimage");
+      }
+    }
+  }
+}
+
+# set the env var stem
+$ENV{'STEM'} = "linux";
+
+sub exec_script {
+  my $type   = shift;
+  my $script = shift;
+  print STDERR "Running $type hook script $script.\n";
+  system ("$script $version $realimageloc$kimage-$version") &&
+    print STDERR "User $type hook script [$script] ";
+  if ($?) {
+    if ($? == -1) {
+      print STDERR "failed to execute: $!\n";
+    }
+    elsif ($? & 127) {
+      printf STDERR "died with signal %d, %s coredump\n",
+        ($? & 127),  ($? & 128) ? 'with' : 'without';
+    }
+    else {
+      printf STDERR "exited with value %d\n", $? >> 8;
+    }
+  }
+}
+sub run_hook {
+  my $type   = shift;
+  my $script = shift;
+  if ($script =~ m,^/,) {
+    # Full path provided for the hook script
+    if (-x "$script") {
+      &exec_script($type,$script);
+    }
+    else {
+      warn "The provided $type hook script [$script] could not be run.\n";
+    }
+  }
+  else {
+    # Look for it in a safe path
+    for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
+      if (-x "$path/$script") {
+        &exec_script($type, "$path/$script");
+        return 0;
+      }
+    }
+    # No luck
+    print STDERR "Could not find $type hook script [$script].\n";
+    warn "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
+  }
+}
+
+my $options;
+for (@ARGV) {
+       s,','\\'',g;
+       $options .= " '$_'";
+}
+$ENV{'DEB_MAINT_PARAMS'}="$options";
+
+## Run user hook script here, if any
+if ($postrm_hook) {
+  &run_hook("postrm", $postrm_hook);
+}
+if (-d "/etc/kernel/postrm.d") {
+  warn "Examining /etc/kernel/postrm.d .\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/postrm.d") &&
+            die "Failed to process /etc/kernel/postrm.d";
+}
+if (-d "/etc/kernel/postrm.d/$version") {
+  warn "Examining /etc/kernel/postrm.d/$version .\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " .
+          "--arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/postrm.d/$version") &&
+            die "Failed to process /etc/kernel/postrm.d/$version";
+}
+
+# check and remove damaged and dangling symlinks
+if ($ARGV[0] !~ /upgrade/) {
+  system("$ramdisk -d -k " . $version . " > /dev/null 2>&1");
+  if (-f $realimageloc . "initrd.img-$version.bak") {
+    unlink $realimageloc . "initrd.img-$version.bak";
+  }
+  image_magic($kimage,          $image_dest);
+  image_magic($kimage . ".old", $image_dest);
+  image_magic("initrd.img",     $image_dest) if $initrd;
+  image_magic("initrd.img.old", $image_dest) if $initrd;
+}
+
+exit 0;
+
+__END__
+
+
+
+
+
+
diff --git a/debian/control-scripts/preinst b/debian/control-scripts/preinst
new file mode 100644 (file)
index 0000000..9723776
--- /dev/null
@@ -0,0 +1,315 @@
+#! /usr/bin/perl
+#                              -*- Mode: Cperl -*-
+# image.preinst ---
+# Author           : Manoj Srivastava ( srivasta@tiamat.datasync.com )
+# Created On       : Sun Jun 14 03:38:02 1998
+# Created On Node  : tiamat.datasync.com
+# Last Modified By : Manoj Srivastava
+# Last Modified On : Sun Sep 24 14:04:42 2006
+# Last Machine Used: glaurung.internal.golden-gryphon.com
+# Update Count     : 99
+# Status           : Unknown, Use with caution!
+# HISTORY          :
+# Description      :
+#
+#
+
+#
+#use strict; #for debugging
+
+use Debconf::Client::ConfModule qw(:all);
+version('2.0');
+my $capb=capb("backup");
+
+$|=1;
+
+# Predefined values:
+my $version         = "=V";
+my $link_in_boot    = "";     # Should be empty, mostly
+my $no_symlink      = "";     # Should be empty, mostly
+my $reverse_symlink = "";     # Should be empty, mostly
+my $do_symlink      = "Yes";   # target machine defined
+my $do_boot_enable  = "Yes";   # target machine defined
+my $do_bootfloppy   = "Yes";   # target machine defined
+my $do_bootloader   = "Yes";   # target machine defined
+my $move_image      = '';       # target machine defined
+my $kimage          = "=K";     # Should be empty, mostly
+my $loader          = "=L";     # lilo, silo, quik, palo, vmelilo, nettrom
+                                # or elilo
+my $image_dir       = "/boot";     # where the image is located
+my $initrd          = "YES";     # initrd kernel
+my $use_hard_links  = '';       # hardlinks do not wirk across fs boundaries
+my $postinst_hook   = '';       #Normally we do not
+my $postrm_hook     = '';       #Normally we do not
+my $preinst_hook    = '';       #Normally we do not
+my $prerm_hook      = '';       #Normally we do not
+my $minimal_swap    = '';       # Do not swap symlinks
+my $ignore_depmod_err = '';    # normally we do not
+my $relink_src_link   = 'YES'; # There is no harm in checking the link
+my $relink_build_link = 'YES'; # There is no harm in checking the link
+my $force_build_link  = '';     # There is no harm in checking the link
+my $kernel_arch       = "=B";
+my $ramdisk           = "/usr/sbin/update-initramfs";  # List of tools to create initial ram fs.
+my $package_name    = "linux-image-$version";
+
+my $Loader          = "NoLOADER"; #
+$Loader             = "LILO"     if $loader =~ /^lilo/io;
+$Loader             = "SILO"     if $loader =~ /^silo/io;
+$Loader             = "QUIK"     if $loader =~ /^quik/io;
+$Loader             = "yaboot"   if $loader =~ /^yaboot/io;
+$Loader             = "PALO"     if $loader =~ /^palo/io;
+$Loader             = "NETTROM"  if $loader =~ /^nettrom/io;
+$Loader             = "VMELILO"  if $loader =~ /^vmelilo/io;
+$Loader             = "ZIPL"     if $loader =~ /^zipl/io;
+$Loader             = "ELILO"    if $loader =~ /^elilo/io;
+
+
+#known variables
+my @boilerplate     = ();
+my @silotemplate    = ();
+my @quiktemplate    = ();
+my @palotemplate    = ();
+my @vmelilotemplate = ();
+my $bootdevice      = '';
+my $rootdevice      = '';
+my $rootdisk        = '';
+my $rootpartition   = '';
+my $image_dest      = "/";
+my $realimageloc    = "/$image_dir/";
+my $have_conffile   = "";
+my $CONF_LOC        = '/etc/kernel-img.conf';
+my $relative_links  = '';
+my $silent_loader   = '';
+my $warn_reboot     = '';        # Warn that we are installing a version of
+                                 # the kernel we are running
+
+my $modules_base    = '/lib/modules';
+
+die "Pre inst Internal error. Aborting." unless $version;
+
+exit 0 if $ARGV[0] =~ /abort-upgrade/;
+exit 1 unless $ARGV[0] =~ /(install|upgrade)/;
+
+$arch = `uname -i`;
+if ($arch =~ m/86/) {
+       system ("grep -q ' pae ' /proc/cpuinfo");
+       if ($?) {
+                       print STDERR "This kernel does not support a non-PAE CPU.\n";
+                       exit 1;
+       }
+}
+
+# remove multiple leading slashes; make sure there is at least one.
+$realimageloc  =~ s|^/*|/|o;
+$realimageloc  =~ s|/+|/|o;
+
+if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
+  if (open(CONF, "$CONF_LOC")) {
+    while (<CONF>) {
+      chomp;
+      s/\#.*$//g;
+      next if /^\s*$/;
+
+      $do_symlink      = "" if /^\s*do_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $no_symlink      = "" if /^\s*no_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $reverse_symlink = "" if /^\s*reverse_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $link_in_boot    = "" if /^\s*image_in_boot\s*=\s*(no|false|0)\s*$/ig;
+      $link_in_boot    = "" if /^\s*link_in_boot\s*=\s*(no|false|0)\s*$/ig;
+      $move_image      = "" if /^\s*move_image\s*=\s*(no|false|0)\s*$/ig;
+      $do_boot_enable  = '' if /^\s*do_boot_enable\s*=\s*(no|false|0)\s*$/ig;
+      $do_bootfloppy   = '' if /^\s*do_bootfloppy\s*=\s*(no|false|0)\s*$/ig;
+      $do_bootloader   = '' if /^\s*do_bootloader\s*=\s*(no|false|0)\s*$/ig;
+      $relative_links  = '' if /^\s*relative_links \s*=\s*(no|false|0)\s*$/ig;
+      $use_hard_links  = '' if /^\s*use_hard_links\s*=\s*(no|false|0)\s*$/ig;
+      $silent_loader   = '' if /^\s*silent_loader\s*=\s*(no|false|0)\s*$/ig;
+      $warn_reboot     = '' if /^\s*warn_reboot\s*=\s*(no|false|0)\s*$/ig;
+      $minimal_swap    = '' if /^\s*minimal_swap\s*=\s*(no|false|0)\s*$/ig;
+      $ignore_depmod_err = '' if /^\s*ignore_depmod_err\s*=\s*(no|false|0)\s*$/ig;
+      $relink_src_link   = '' if /^\s*relink_src_link\s*=\s*(no|false|0)\s*$/ig;
+      $relink_build_link = '' if /^\s*relink_build_link\s*=\s*(no|false|0)\s*$/ig;
+      $force_build_link = '' if /^\s*force_build_link\s*=\s*(no|false|0)\s*$/ig;
+
+      $do_symlink      = "Yes" if /^\s*do_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $no_symlink      = "Yes" if /^\s*no_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $reverse_symlink = "Yes" if /^\s*reverse_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $link_in_boot    = "Yes" if /^\s*image_in_boot\s*=\s*(yes|true|1)\s*$/ig;
+      $link_in_boot    = "Yes" if /^\s*link_in_boot\s*=\s*(yes|true|1)\s*$/ig;
+      $move_image      = "Yes" if /^\s*move_image\s*=\s*(yes|true|1)\s*$/ig;
+      $do_boot_enable  = "Yes" if /^\s*do_boot_enable\s*=\s*(yes|true|1)\s*$/ig;
+      $do_bootfloppy   = "Yes" if /^\s*do_bootfloppy\s*=\s*(yes|true|1)\s*$/ig;
+      $do_bootloader   = "Yes" if /^\s*do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
+      $relative_links  = "Yes" if /^\s*relative_links\s*=\s*(yes|true|1)\s*$/ig;
+      $use_hard_links  = "Yes" if /^\s*use_hard_links\s*=\s*(yes|true|1)\s*$/ig;
+      $silent_loader   = 'Yes' if /^\s*silent_loader\s*=\s*(yes|true|1)\s*$/ig;
+      $warn_reboot     = 'Yes' if /^\s*warn_reboot\s*=\s*(yes|true|1)\s*$/ig;
+      $minimal_swap    = 'Yes' if /^\s*minimal_swap\s*=\s*(yes|true|1)\s*$/ig;
+      $ignore_depmod_err = 'Yes' if /^\s*ignore_depmod_err\s*=\s*(yes|true|1)\s*$/ig;
+      $relink_src_link   = 'Yes' if /^\s*relink_src_link\s*=\s*(yes|true|1)\s*$/ig;
+      $relink_build_link = 'Yes' if /^\s*relink_build_link\s*=\s*(yes|true|1)\s*$/ig;
+      $force_build_link = 'Yes' if /^\s*force_build_link\s*=\s*(yes|true|1)\s*$/ig;
+
+      $image_dest      = "$1"  if /^\s*image_dest\s*=\s*(\S+)/ig;
+      $postinst_hook   = "$1"  if /^\s*postinst_hook\s*=\s*(\S+)/ig;
+      $postrm_hook     = "$1"  if /^\s*postrm_hook\s*=\s*(\S+)/ig;
+      $preinst_hook    = "$1"  if /^\s*preinst_hook\s*=\s*(\S+)/ig;
+      $prerm_hook      = "$1"  if /^\s*prerm_hook\s*=\s*(\S+)/ig;
+      $ramdisk         = "$1"  if /^\s*ramdisk\s*=\s*(.+)$/ig;
+    }
+    close CONF;
+    $have_conffile = "Yes";
+    $have_conffile = "Yes";    # stop perl complaining
+  }
+}
+
+$ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
+
+# About to upgrade this package from version $2 TO THIS VERSION.
+# "prerm upgrade" has already been called for the old version of
+# this package.
+
+sub find_initrd_tool {
+  my $hostversion = shift;
+  my $version = shift;
+  my @ramdisks =
+    grep {
+      my $args = 
+        "$_ " .
+          "--supported-host-version=$hostversion " .
+            "--supported-target-version=$version " .
+              "1>/dev/null 2>&1"
+                ;
+      system($args) == 0;
+    }
+      split (/[:,\s]+/, $ramdisk);
+}
+
+sub check {
+  my $version = shift;
+  my $lib_modules="$modules_base/$version";
+  my $message = '';
+
+  if (-d "$lib_modules") {
+    opendir(DIR, $lib_modules) || die "can’t opendir $lib_modules: $!";
+    my @children = readdir(DIR);
+    if ($#children > 1) {
+      my @dirs  = grep { -d "$lib_modules/$_" } @children;
+      if ($#dirs > 1) { # we have subdirs
+        my $dir_message='';
+        for my $dir (@dirs) {
+          if ($dir =~/kernel$/) {
+            $dir_message="An older install was detected.\n";
+          }
+          else {
+            $dir_message="Module sub-directories were detected.\n"
+              unless $dir_message;
+          }
+        }
+        $message += $dir_message if $dir_message;
+      }
+
+      my @links = grep { -l "$lib_modules/$_" } @children;
+      if ($#links > -1) {
+        my $links_message = '';
+        for my $link (@links) {
+          next if ($link =~ /^build$/);
+          next if ($link =~ /^source$/);
+          $links_message = "Symbolic links were detected in $modules_base/$version.\n";
+        }
+        $message += $links_message if $links_message;
+      }
+      my @files = grep { -f "$lib_modules/$_" } @children;
+      $message += "Additional files also exist in $modules_base/$version.\n"
+        if ($#files > -1);
+    }
+  }
+  else { $message .= "$lib_modules does not exist. ";}
+  return $message;
+}
+
+if (-d "$modules_base/$version") {
+  my $errors=check($version);
+  warn "Info:\n$errors\n" if $errors;
+}
+
+# set the env var stem
+$ENV{'STEM'} = "linux";
+
+sub exec_script {
+  my $type   = shift;
+  my $script = shift;
+  print STDERR "Running $type hook script $script.\n";
+  system ("$script $version $realimageloc$kimage-$version") &&
+    print STDERR "User $type hook script [$script] ";
+  if ($?) {
+    if ($? == -1) {
+      print STDERR "failed to execute: $!\n";
+    }
+    elsif ($? & 127) {
+      printf STDERR "died with signal %d, %s coredump\n",
+        ($? & 127),  ($? & 128) ? 'with' : 'without';
+    }
+    else {
+      printf STDERR "exited with value %d\n", $? >> 8;
+    }
+    exit $? >> 8;
+  }
+}
+sub run_hook {
+  my $type   = shift;
+  my $script = shift;
+  if ($script =~ m,^/,) {
+    # Full path provided for the hook script
+    if (-x "$script") {
+      &exec_script($type,$script);
+    }
+    else {
+      die "The provided $type hook script [$script] could not be run.\n";
+    }
+  }
+  else {
+    # Look for it in a safe path
+    for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
+      if (-x "$path/$script") {
+        &exec_script($type, "$path/$script");
+        return 0;
+      }
+    }
+    # No luck
+    print STDERR "Could not find $type hook script [$script].\n";
+    die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
+  }
+}
+
+
+my $options;
+for (@ARGV) {
+       s,','\\'',g;
+       $options .= " '$_'";
+}
+$ENV{'DEB_MAINT_PARAMS'}="$options";
+
+## Run user hook script here, if any
+if (-x "$preinst_hook") {
+  &run_hook("preinst", $preinst_hook);
+}
+if (-d "/etc/kernel/preinst.d") {
+  print STDERR "Examining /etc/kernel/preinst.d/\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version" .
+          " --arg=$realimageloc$kimage-$version" .
+          " /etc/kernel/preinst.d") &&
+            die "Failed to process /etc/kernel/preinst.d";
+}
+if (-d "/etc/kernel/preinst.d/$version") {
+  print STDERR "Examining /etc/kernel/preinst.d/$version.\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version" .
+          " --arg=$realimageloc$kimage-$version" .
+          " /etc/kernel/preinst.d/$version") &&
+            die "Failed to process /etc/kernel/preinst.d/$version";
+}
+print STDERR "Done.\n";
+
+exit 0;
+
+__END__
+
+
diff --git a/debian/control-scripts/prerm b/debian/control-scripts/prerm
new file mode 100644 (file)
index 0000000..07e4146
--- /dev/null
@@ -0,0 +1,312 @@
+#! /usr/bin/perl
+#                              -*- Mode: Perl -*- 
+# image.prerm --- 
+# Author           : root ( root@melkor.pilgrim.umass.edu ) 
+# Created On       : Fri May 17 03:28:59 1996
+# Created On Node  : melkor.pilgrim.umass.edu
+# Last Modified By : Manoj Srivastava
+# Last Modified On : Sat Aug  5 13:14:17 2006
+# Last Machine Used: glaurung.internal.golden-gryphon.com
+# Update Count     : 85
+# Status           : Unknown, Use with caution!
+# HISTORY          : 
+# Description      : 
+# 
+#
+#    $Id: image.prerm,v 1.22 2003/10/07 16:24:20 srivasta Exp $
+#
+# 
+#use strict;
+
+$|=1;
+# Predefined values:
+my $version         = "=V";
+my $link_in_boot    = "";      # Should be empty, mostly
+my $no_symlink      = "";      # Should be empty, mostly
+my $reverse_symlink = "";      # Should be empty, mostly
+my $do_symlinks     = "Yes";   # target machine defined
+my $do_boot_enable  = "Yes";   # target machine defined
+my $do_bootfloppy   = "Yes";   # target machine defined
+my $do_bootloader   = "Yes";   # target machine defined
+my $move_image      = '';       # target machine defined
+my $kimage          = "=K";    # Should be empty, mostly
+my $loader          = "=L";     # lilo, silo, quik, palo, vmelilo, or nettrom
+my $image_dir       = "/boot";     # where the image is located
+my $clobber_modules = '';       # target machine defined
+my $initrd          = "YES";     # initrd kernel
+my $use_hard_links  = '';       # hardlinks do not wirk across fs boundaries
+my $postinst_hook   = '';       #Normally we do not
+my $postrm_hook     = '';       #Normally we do not
+my $preinst_hook    = '';       #Normally we do not
+my $prerm_hook      = '';       #Normally we do not
+my $minimal_swap    = '';       # Do not swap symlinks
+my $ignore_depmod_err = '';    # normally we do not
+my $relink_build_link = 'YES'; # There is no harm in checking the link
+my $force_build_link = '';     # There is no harm in checking the link
+my $kernel_arch       = "=B";
+my $ramdisk           = "/usr/sbin/update-initramfs";
+my $package_name    = "linux-image-$version";
+
+my $Loader          = "NoLOADER"; # 
+$Loader             = "LILO"     if $loader =~ /^lilo/io;
+$Loader             = "SILO"     if $loader =~ /^silo/io;
+$Loader             = "QUIK"     if $loader =~ /^quik/io;
+$Loader             = "yaboot"   if $loader =~ /^yaboot/io;
+$Loader             = "PALO"     if $loader =~ /^palo/io;
+$Loader             = "NETTROM"  if $loader =~ /^nettrom/io;
+$Loader             = "VMELILO"  if $loader =~ /^vmelilo/io;
+$Loader             = "ZIPL"     if $loader =~ /^zipl/io;
+$Loader             = "ELILO"    if $loader =~ /^elilo/io;
+
+
+# This should not point to /tmp, because of security risks.
+my $temp_file_name = "/var/log/$loader" . "_log.$$";
+
+#known variables
+my $image_dest      = "/";
+my $realimageloc    = "/$image_dir/";
+my $have_conffile   = "";
+my $CONF_LOC        = '/etc/kernel-img.conf';
+my $relative_links = '';
+my $silent_loader   = '';
+my $warn_reboot     = 'Yes';     # Warn that we are installing a version of
+                                 # the kernel we are running
+
+# remove multiple leading slashes; make sure there is at least one.
+$realimageloc  =~ s|^/*|/|o;
+$realimageloc  =~ s|/+|/|o;
+
+my $DEBUG = 0;
+
+# Variables used
+my $image='';
+my $ret=0;
+my $seen='';
+my $answer='';
+my $running = '';
+my $WouldInvalidate = 0;
+
+if ($ARGV[0] && ($ARGV[0] =~ /remove/ || $ARGV[0] =~ /upgrade/)) {
+  if (-l "/usr/doc/linux-image-$version") {
+    unlink "/usr/doc/linux-image-$version";
+  }
+}
+
+# Ignore all invocations uxcept when called on to remove
+exit 0 unless ($ARGV[0] && $ARGV[0] =~ /remove/) ;
+
+# Paranoid check to make sure that the correct value is put in there
+if (! $kimage)                    { $kimage = "vmlinuz";} # Hmm. empty
+elsif ($kimage =~ m/^b?uImage$/o) { $kimage = "vmlinuz";} # these produce vmlinuz
+elsif ($kimage =~ m/^b?zImage$/o) { $kimage = "vmlinuz";} # these produce vmlinuz
+elsif ($kimage =~ m/^[iI]mage$/o) { my $nop = $kimage;  }
+elsif ($kimage =~ m/^vmlinux$/o)  { my $nop = $kimage;  }
+else                              { $kimage = "vmlinuz";} # Default
+
+if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
+  if (open(CONF, "$CONF_LOC")) {
+    while (<CONF>) {
+      chomp;
+      s/\#.*$//g;
+      next if /^\s*$/;
+
+      $do_symlink      = "" if /^\s*do_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $no_symlink      = "" if /^\s*no_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $reverse_symlink = "" if /^\s*reverse_symlinks\s*=\s*(no|false|0)\s*$/ig;
+      $link_in_boot    = "" if /^\s*image_in_boot\s*=\s*(no|false|0)\s*$/ig;
+      $link_in_boot    = "" if /^\s*link_in_boot\s*=\s*(no|false|0)\s*$/ig;
+      $move_image      = "" if /^\s*move_image\s*=\s*(no|false|0)\s*$/ig;
+      $clobber_modules = '' if /^\s*clobber_modules\s*=\s*(no|false|0)\s*$/ig;
+      $do_boot_enable  = '' if /^\s*do_boot_enable\s*=\s*(no|false|0)\s*$/ig;
+      $do_bootfloppy   = '' if /^\s*do_bootfloppy\s*=\s*(no|false|0)\s*$/ig;
+      $relative_links  = '' if /^\s*relative_links \s*=\s*(no|false|0)\s*$/ig;
+      $do_bootloader   = '' if /^\s*do_bootloader\s*=\s*(no|false|0)\s*$/ig;
+      $do_initrd       = '' if /^\s*do_initrd\s*=\s*(no|false|0)\s*$/ig;
+      $use_hard_links  = '' if /^\s*use_hard_links\s*=\s*(no|false|0)\s*$/ig;
+      $silent_loader   = '' if /^\s*silent_loader\s*=\s*(no|false|0)\s*$/ig;
+      $warn_reboot     = '' if /^\s*warn_reboot\s*=\s*(no|false|0)\s*$/ig;
+      $minimal_swap    = '' if /^\s*minimal_swap\s*=\s*(no|false|0)\s*$/ig;
+      $ignore_depmod_err = '' if /^\s*ignore_depmod_err\s*=\s*(no|false|0)\s*$/ig;
+      $relink_build_link = '' if /^\s*relink_build_link\s*=\s*(no|false|0)\s*$/ig;
+      $force_build_link = '' if /^\s*force_build_link\s*=\s*(no|false|0)\s*$/ig;
+
+
+      $do_symlink      = "Yes" if /^\s*do_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $no_symlink      = "Yes" if /^\s*no_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $reverse_symlink = "Yes" if /^\s*reverse_symlinks\s*=\s*(yes|true|1)\s*$/ig;
+      $link_in_boot    = "Yes" if /^\s*image_in_boot\s*=\s*(yes|true|1)\s*$/ig;
+      $link_in_boot    = "Yes" if /^\s*link_in_boot\s*=\s*(yes|true|1)\s*$/ig;
+      $move_image      = "Yes" if /^\s*move_image\s*=\s*(yes|true|1)\s*$/ig;
+      $clobber_modules = "Yes" if /^\s*clobber_modules\s*=\s*(yes|true|1)\s*$/ig;
+      $do_boot_enable  = "Yes" if /^\s*do_boot_enable\s*=\s*(yes|true|1)\s*$/ig;
+      $do_bootfloppy   = "Yes" if /^\s*do_bootfloppy\s*=\s*(yes|true|1)\s*$/ig;
+      $do_bootloader   = "Yes" if /^\s*do_bootloader\s*=\s*(yes|true|1)\s*$/ig;
+      $relative_links  = "Yes" if /^\s*relative_links\s*=\s*(yes|true|1)\s*$/ig;
+      $do_initrd       = "Yes" if /^\s*do_initrd\s*=\s*(yes|true|1)\s*$/ig;
+      $use_hard_links  = "Yes" if /^\s*use_hard_links\s*=\s*(yes|true|1)\s*$/ig;
+      $silent_loader   = 'Yes' if /^\s*silent_loader\s*=\s*(yes|true|1)\s*$/ig;
+      $warn_reboot     = 'Yes' if /^\s*warn_reboot\s*=\s*(yes|true|1)\s*$/ig;
+      $minimal_swap    = 'Yes' if /^\s*minimal_swap\s*=\s*(yes|true|1)\s*$/ig;
+      $ignore_depmod_err = 'Yes' if /^\s*ignore_depmod_err\s*=\s*(yes|true|1)\s*$/ig;
+      $relink_build_link = 'Yes' if /^\s*relink_build_link\s*=\s*(yes|true|1)\s*$/ig;
+      $force_build_link = 'Yes' if /^\s*force_build_link\s*=\s*(yes|true|1)\s*$/ig;
+
+      $image_dest      = "$1"  if /^\s*image_dest\s*=\s*(\S+)/ig;
+      $postinst_hook   = "$1"  if /^\s*postinst_hook\s*=\s*(\S+)/ig;
+      $postrm_hook     = "$1"  if /^\s*postrm_hook\s*=\s*(\S+)/ig;
+      $preinst_hook    = "$1"  if /^\s*preinst_hook\s*=\s*(\S+)/ig;
+      $prerm_hook      = "$1"  if /^\s*prerm_hook\s*=\s*(\S+)/ig;
+      $ramdisk         = "$1"  if /^\s*ramdisk\s*=\s*(.+)$/ig;
+    }
+    close CONF;
+    $have_conffile = "Yes";
+  }
+}
+
+
+$ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
+
+#check to see if we are trying to remove a running kernel
+# if so we abort right now.
+chop($running=`uname -r`);
+if ($running eq $version) {
+  print STDERR "WARN: Proceeding with removing running kernel image.\n";
+}
+
+#Now, they have an alternate kernel which they are currently running
+
+# This is just us being nice to lilo users.
+
+chdir("/") or die "could not chdir to /:$!\n";
+
+if (-f "/etc/$loader.conf") { #I know, could be a link, but ..
+  open (LILO, "/etc/$loader.conf") || &success(); # this is not critical
+  while (<LILO>) {
+    chop;
+    s/\#.*//;                    # nix the comments
+    next unless /^\s*image\s*=\s(\S+)/o;
+    $image = $1;
+    if ($image && -e $image) {
+      while (defined($image) && -l $image) {
+       $image = readlink ($image);
+      }
+      if (defined($image) && -e $image) {
+       $WouldInvalidate |= $image =~ /$kimage-$version/;
+      }
+      else {
+       &success(); # invalid $loader.conf file
+      }
+    }
+    else {
+      &success(); # invalid $loader.conf file
+    }
+  }
+  close (LILO);
+  if ($WouldInvalidate) {
+    print STFERR "WARN: Proceeding with removing running kernel image.\n";
+    &success();
+  }
+}
+
+
+# set the env var stem
+$ENV{'STEM'} = "linux";
+
+sub exec_script {
+  my $type   = shift;
+  my $script = shift;
+  print STDERR "Running $type hook script $script.\n";
+  system ("$script $version $realimageloc$kimage-$version") &&
+    print STDERR "User $type hook script [$script] ";
+  if ($?) {
+    if ($? == -1) {
+      print STDERR "failed to execute: $!\n";
+    }
+    elsif ($? & 127) {
+      printf STDERR "died with signal %d, %s coredump\n",
+        ($? & 127),  ($? & 128) ? 'with' : 'without';
+    }
+    else {
+      printf STDERR "exited with value %d\n", $? >> 8;
+    }
+    exit $? >> 8;
+  }
+}
+sub run_hook {
+  my $type   = shift;
+  my $script = shift;
+  if ($script =~ m,^/,) {
+    # Full path provided for the hook script
+    if (-x "$script") {
+      &exec_script($type,$script);
+    }
+    else {
+      die "The provided $type hook script [$script] could not be run.\n";
+    }
+  }
+  else {
+    # Look for it in a safe path
+    for my $path ('/bin', '/sbin', '/usr/bin', '/usr/sbin') {
+      if (-x "$path/$script") {
+        &exec_script($type, "$path/$script");
+        return 0;
+      }
+    }
+    # No luck
+    print STDERR "Could not find $type hook script [$script].\n";
+    die "Looked in: '/bin', '/sbin', '/usr/bin', '/usr/sbin'\n";
+  }
+}
+
+
+my $options;
+for (@ARGV) {
+       s,','\\'',g;
+       $options .= " '$_'";
+}
+$ENV{'DEB_MAINT_PARAMS'}="$options";
+
+## Run user hook script here, if any
+if (-x "$prerm_hook") {
+  &run_hook("prerm", $prerm_hook);
+}
+if (-d "/etc/kernel/prerm.d") {
+  print STDERR "Examining /etc/kernel/prerm.d.\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version " . 
+          "--arg=$realimageloc$kimage-$version /etc/kernel/prerm.d") &&
+            die "Failed to process /etc/kernel/prerm.d";
+}
+if (-d "/etc/kernel/prerm.d/$version") {
+  print STDERR "Examining /etc/kernel/prerm.d/$version.\n";
+  system ("run-parts --verbose --exit-on-error --arg=$version" .
+          " --arg=$realimageloc$kimage-$version " .
+          "/etc/kernel/prerm.d/$version") &&
+            die "Failed to process /etc/kernel/prerm.d/$version";
+}
+
+sub success () {
+  # NOTE: need to keep this list in sync with rules.d/2-binary-arch.mk
+  my %files_to_keep = (
+       'modules.builtin'       => 1,
+       'modules.order'         => 1,
+  );
+  my $short;
+  for my $file (</lib/modules/$version/modules.*>) {
+    $short = $file; $short =~ s,.*/,,;
+    if (!defined $files_to_keep{$short}) {
+      unlink "$file";
+    }
+  }
+  exit 0;
+}
+
+
+
+&success();
+exit 0;
+__END__
+
+
+
+
+
diff --git a/debian/debian.env b/debian/debian.env
new file mode 100644 (file)
index 0000000..be31a0c
--- /dev/null
@@ -0,0 +1 @@
+DEBIAN=debian.master
diff --git a/debian/docs/README.inclusion-list b/debian/docs/README.inclusion-list
new file mode 100644 (file)
index 0000000..b025393
--- /dev/null
@@ -0,0 +1,51 @@
+This README describes the reason for, and the use of, module
+inclusion lists.
+
+The original Hardy release had the notion of sub-flavours,
+e.g., a flavour that was constructed as a subset of an existing flavour.
+For example, the virtual flavour was extracted from the server flavour using
+a subset of the server flavour modules. However, there were some difficult
+mainteneance issues with regard to packaging, make rules, and scripts. This
+re-implementation of the sub-flavours philosophy is hopefully simpler,
+and retrofitable to all releases.
+
+A module inclusion list looks at the problem of of constructing a package
+from the perspective of what modules do we _want_ in the package, as opposed
+to what modules we _don't_ want. As the kernel matures, more and more devices are added
+which makes the problem of configuration maintenance a real pain in the ass.
+If we took the approach of disabling all of the config options that we don't want,
+then the differences between flavours will quickly become quite large, making
+it difficult to quickly compare the individual flavour configs.  Each time a
+new config option is added then we also have to make a decision about disabling in
+order to continue to keep the minimal number of modules.
+
+A module inclusion list is applied on a per-flavour basis. For example,
+debian.<BRANCH>/control.d/${flavour}.inclusion-list. For example, the
+config for virtual is very close to server and generic, but the inclusion list
+causes the virtual package to be constructed with _only_ the modules described 
+in the inclusion list.
+
+The inclusion list format is a simple bash regular expression list of files. For example,
+
+arch/*/{crypto,kernel,oprofile}
+drivers/acpi/*
+drivers/ata/ahci.ko
+
+These 3 regular expression forms are suitable for expansion by bash and as inputs to 'find'.
+See debian/scripts/module-inclusion for details.
+
+There are 2 log files created as a side effect of the application of the module
+inclusion list; $(flavour).inclusion-list.log and $(flavour).depmod.log.
+
+$(flavour).inclusion-list.log : This log is created while the inclusion list
+modules are being copied. If any are missing, then those warnings go in this log.
+While its not considered a fatal error, you should endevour to correct your inclusion
+list such that there are no missing modules.
+
+$(flavour).depmod.log : The log is created as a result of running depmod on the
+resulting set of modules. If there are missing symbols then you'll find that information
+here. Again, you should modify your inclusion list such that there are no missing
+symbols.
+
+Tim Gardner <tim.gardner@canonical.com>
+June 2, 2010
diff --git a/debian/gbp.conf b/debian/gbp.conf
new file mode 100644 (file)
index 0000000..8ce5fda
--- /dev/null
@@ -0,0 +1,2 @@
+[buildpackage]
+debian-tag = Ubuntu-%(version)s
diff --git a/debian/linux-cloud-tools-common.hv-fcopy-daemon.service b/debian/linux-cloud-tools-common.hv-fcopy-daemon.service
new file mode 100644 (file)
index 0000000..43a3ecf
--- /dev/null
@@ -0,0 +1,12 @@
+# On Azure/Hyper-V systems start the hv_fcopy_daemon
+#
+# author "Andy Whitcroft <apw@canonical.com>"
+[Unit]
+Description=Hyper-V File Copy Protocol Daemon
+ConditionVirtualization=microsoft
+
+[Service]
+ExecStart=/usr/sbin/hv_fcopy_daemon -n
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/linux-cloud-tools-common.hv-fcopy-daemon.upstart b/debian/linux-cloud-tools-common.hv-fcopy-daemon.upstart
new file mode 100644 (file)
index 0000000..566bfbb
--- /dev/null
@@ -0,0 +1,22 @@
+# On Azure/Hyper-V systems start the hv_fcopy_daemon
+#
+description "Hyper-V File Copy Protocol Daemon"
+author "Andy Whitcroft <apw@canonical.com>"
+
+start on runlevel [2345]
+stop on runlevel [!2345]
+console log
+
+pre-start script
+        if [ -e "/etc/default/hv-kvp-daemon-init" ]; then
+                . /etc/default/hv-kvp-daemon-init
+        fi
+        [ "$RUN_FCOPY_DAEMON" -eq 0 ] && { stop; exit 0; }
+       if [ -d /sys/class/dmi/id/. ]; then
+               read company </sys/class/dmi/id/sys_vendor
+               read product </sys/class/dmi/id/product_name
+               [ "$company:$product" = 'Microsoft Corporation:Virtual Machine' ] || { stop; exit 0; }
+       fi
+end script
+
+exec /usr/sbin/hv_fcopy_daemon -n
diff --git a/debian/linux-cloud-tools-common.hv-kvp-daemon.service b/debian/linux-cloud-tools-common.hv-kvp-daemon.service
new file mode 100644 (file)
index 0000000..c86a812
--- /dev/null
@@ -0,0 +1,12 @@
+# On Azure/Hyper-V systems start the hv_kvp_daemon
+#
+# author "Andy Whitcroft <apw@canonical.com>"
+[Unit]
+Description=Hyper-V KVP Protocol Daemon
+ConditionVirtualization=microsoft
+
+[Service]
+ExecStart=/usr/sbin/hv_kvp_daemon -n
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/linux-cloud-tools-common.hv-kvp-daemon.upstart b/debian/linux-cloud-tools-common.hv-kvp-daemon.upstart
new file mode 100644 (file)
index 0000000..198184a
--- /dev/null
@@ -0,0 +1,22 @@
+# On Azure/Hyper-V systems start the hv_kvp_daemon
+#
+description "Hyper-V KVP Protocol Daemon"
+author "Adam Conrad <adconrad@canonical.com>"
+
+start on runlevel [2345]
+stop on runlevel [!2345]
+console log
+
+pre-start script
+        if [ -e "/etc/default/hv-kvp-daemon-init" ]; then
+                . /etc/default/hv-kvp-daemon-init
+        fi
+        [ "$RUN_KVP_DAEMON" = 0 ] && { stop; exit 0; }
+       if [ -d /sys/class/dmi/id/. ]; then
+               read company </sys/class/dmi/id/sys_vendor
+               read product </sys/class/dmi/id/product_name
+               [ "$company:$product" = 'Microsoft Corporation:Virtual Machine' ] || { stop; exit 0; }
+       fi
+end script
+
+exec /usr/sbin/hv_kvp_daemon -n
diff --git a/debian/linux-cloud-tools-common.hv-vss-daemon.service b/debian/linux-cloud-tools-common.hv-vss-daemon.service
new file mode 100644 (file)
index 0000000..20717a7
--- /dev/null
@@ -0,0 +1,12 @@
+# On Azure/Hyper-V systems start the hv_vss_daemon
+#
+# author "Andy Whitcroft <apw@canonical.com>"
+[Unit]
+Description=Hyper-V VSS Protocol Daemon
+ConditionVirtualization=microsoft
+
+[Service]
+ExecStart=/usr/sbin/hv_vss_daemon -n
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/linux-cloud-tools-common.hv-vss-daemon.upstart b/debian/linux-cloud-tools-common.hv-vss-daemon.upstart
new file mode 100644 (file)
index 0000000..3f3326a
--- /dev/null
@@ -0,0 +1,22 @@
+# On Azure/Hyper-V systems start the hv_vss_daemon
+#
+description "Hyper-V VSS Protocol Daemon"
+author "Ben Howard <ben.howard@canonical.com>"
+
+start on runlevel [2345]
+stop on runlevel [!2345]
+console log
+
+pre-start script
+        if [ -e "/etc/default/hv-kvp-daemon-init" ]; then
+                . /etc/default/hv-kvp-daemon-init
+        fi
+        [ "$RUN_VSS_DAEMON" -eq 0 ] && { stop; exit 0; }
+       if [ -d /sys/class/dmi/id/. ]; then
+               read company </sys/class/dmi/id/sys_vendor
+               read product </sys/class/dmi/id/product_name
+               [ "$company:$product" = 'Microsoft Corporation:Virtual Machine' ] || { stop; exit 0; }
+       fi
+end script
+
+exec /usr/sbin/hv_vss_daemon -n
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..5fbe78f
--- /dev/null
@@ -0,0 +1,170 @@
+#!/usr/bin/make -f
+#
+# $(DEBIAN)/rules for Ubuntu linux
+#
+# Use this however you want, just give credit where credit is due.
+#
+# Copyright (c) 2007 Ben Collins <bcollins@ubuntu.com>
+#
+
+DEBIAN=$(shell awk -F= '($$1 == "DEBIAN") { print $$2 }' <debian/debian.env)
+
+# dpkg-buildpackage passes options that are incomptatible
+# with the kernel build.
+unexport CFLAGS
+unexport LDFLAGS
+
+export LC_ALL=C
+export SHELL=/bin/bash -e
+
+# Where do we find the common configuration.
+export DROOT=debian
+
+# Common variables for all architectures
+include $(DROOT)/rules.d/0-common-vars.mk
+
+# Pull in some arch specific stuff
+-include $(DEBIAN)/rules.d/$(arch).mk
+
+# Pull in some branch specific stuff. Used by LTS backport
+# branches to override master branch settings such as do_tools_common.
+-include $(DEBIAN)/rules.d/hooks.mk
+
+# Maintainer targets
+include $(DROOT)/rules.d/1-maintainer.mk
+
+do_linux_tools=$(sort $(filter-out false,$(do_tools_usbip) $(do_tools_cpupower) $(do_tools_perf) $(do_tools_x86)))
+do_cloud_tools=$(sort $(filter-out false,$(do_tools_hyperv)))
+do_tools_common=true
+
+# Don't build tools or udebs in a cross compile environment.
+ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
+       do_tools=false
+       disable_d_i=true
+       do_zfs=false
+       do_zfs_disable:=$(shell cat $(DROOT)/zfs-modules.ignore >>$(prev_abidir)/../modules.ignore)
+endif
+
+# Stages -- support both DEB_STAGE=stage1 and DEB_BUILD_PROFILE=bootstrap
+ifeq ($(DEB_STAGE),stage1)
+    DEB_BUILD_PROFILES=stage1
+endif
+ifneq ($(DEB_BUILD_PROFILE),)
+    DEB_BUILD_PROFILES=$(DEB_BUILD_PROFILE)
+endif
+ifneq ($(filter stage1,$(DEB_BUILD_PROFILES)),)
+    do_tools=false
+    do_doc_package=false
+    do_source_package=false
+    do_flavour_image_package=false
+    do_flavour_header_package=false
+endif
+
+# Being used to build a mainline build -- turn off things which do not work.
+ifeq ($(do_mainline_build),true)
+       do_extras_package=false
+       do_tools=false
+       no_dumpfile=1
+       do_zfs=false
+endif
+
+# Disable tools build and packaging if do_tools != true
+ifneq ($(do_tools),true)
+       do_linux_tools=
+       do_cloud_tools=
+       do_tools_common=
+endif
+
+# Either tools package needs the common source preparation
+do_any_tools=$(sort $(filter-out false,$(do_linux_tools) $(do_cloud_tools)))
+
+# autopkgtest -- rebuild support
+#  only build the first flavour on the assumption it is representative
+ifeq ($(DEB_BUILD_PROFILE),autopkgtest)
+flavours := $(firstword $(flavours))
+endif
+
+# Debian Build System targets
+binary: binary-indep binary-arch
+
+build: build-arch build-indep
+
+clean: debian/control
+       dh_testdir
+       dh_testroot
+       dh_clean
+
+       # d-i stuff
+       rm -rf $(DEBIAN)/d-i-$(arch)
+       # Generated on the fly.
+       rm -f $(DEBIAN)/d-i/firmware/$(arch)/kernel-image
+
+       # normal build junk
+       rm -rf $(DEBIAN)/abi/$(release)-$(revision)
+       rm -rf $(builddir)
+       rm -f $(stampdir)/stamp-*
+       rm -rf $(DEBIAN)/linux-*
+
+       # This gets rid of the d-i packages in control
+       cp -f $(DEBIAN)/control.stub $(DROOT)/control
+       cp $(DEBIAN)/changelog debian/changelog
+
+       # Install the copyright information.
+       cp $(DEBIAN)/copyright debian/copyright
+
+       # If we have a reconstruct script use it.
+       [ -f $(DEBIAN)/reconstruct ] && bash $(DEBIAN)/reconstruct
+
+       # Remove generated intermediate files
+       rm -f $(DROOT)/control.stub $(DEBIAN)/control.stub
+
+distclean: clean
+       rm -rf $(DROOT)/control debian/changelog \
+               debian/control debian/control.stub debian/copyright
+
+# Builds the image, arch headers and debug packages
+include $(DROOT)/rules.d/2-binary-arch.mk
+
+# Rules for building the udebs ($(DEBIAN)-installer)
+include $(DROOT)/rules.d/5-udebs.mk
+
+# Builds the source, doc and linux-headers indep packages
+include $(DROOT)/rules.d/3-binary-indep.mk
+
+# Various checks to be performed on builds
+include $(DROOT)/rules.d/4-checks.mk
+
+# Misc stuff
+.PHONY: $(DEBIAN)/control.stub
+$(DEBIAN)/control.stub:                                \
+               $(DROOT)/scripts/control-create         \
+               $(DEBIAN)/control.stub.in                       \
+               $(DEBIAN)/changelog                     \
+               $(wildcard $(DEBIAN)/control.d/* $(DEBIAN)/sub-flavours/*.vars)
+       for i in $(DEBIAN)/control.stub.in; do                                  \
+         new=`echo $$i | sed 's/\.in$$//'`;                                    \
+         cat $$i | sed -e 's/PKGVER/$(release)/g'                              \
+               -e 's/ABINUM/$(abinum)/g'                                       \
+               -e 's/SRCPKGNAME/$(src_pkg_name)/g'                             \
+               -e 's/=HUMAN=/$(human_arch)/g'                                    \
+         > $$new;                                                              \
+       done
+       flavours="$(sort $(wildcard $(DEBIAN)/control.d/vars.* $(DEBIAN)/sub-flavours/*.vars))";\
+       for i in $$flavours; do                                                 \
+         $(SHELL) $(DROOT)/scripts/control-create $$i |                                \
+               sed -e 's/PKGVER/$(release)/g'                                  \
+               -e 's/ABINUM/$(abinum)/g'                                       \
+               -e 's/SRCPKGNAME/$(src_pkg_name)/g'                             \
+               -e 's/=HUMAN=/$(human_arch)/g'                                    \
+               >> $(DEBIAN)/control.stub;                                              \
+       done
+
+.PHONY: debian/control
+debian/control: $(DEBIAN)/control.stub
+       echo "# placebo control.stub for kernel-wedge flow change" >debian/control.stub
+       cp $(DEBIAN)/control.stub debian/control
+       export KW_DEFCONFIG_DIR=$(DEBIAN)/d-i && \
+       export KW_CONFIG_DIR=$(DEBIAN)/d-i && \
+       LANG=C kernel-wedge gen-control $(release)-$(abinum) | \
+               perl -f $(DROOT)/scripts/misc/kernel-wedge-arch.pl $(arch) \
+               >>$(CURDIR)/debian/control
diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
new file mode 100644 (file)
index 0000000..ccc65dc
--- /dev/null
@@ -0,0 +1,244 @@
+# Used when you need to 'escape' a comma.
+comma = ,
+
+#
+# The source package name will be the first token from $(DEBIAN)/changelog
+#
+src_pkg_name=$(shell sed -n '1s/^\(.*\) (.*).*$$/\1/p' $(DEBIAN)/changelog)
+
+# Get some version info
+release := $(shell sed -n '1s/^$(src_pkg_name).*(\(.*\)-.*).*$$/\1/p' $(DEBIAN)/changelog)
+revisions := $(shell sed -n 's/^$(src_pkg_name)\ .*($(release)-\(.*\)).*$$/\1/p' $(DEBIAN)/changelog | tac)
+revision ?= $(word $(words $(revisions)),$(revisions))
+prev_revisions := $(filter-out $(revision),0.0 $(revisions))
+prev_revision := $(word $(words $(prev_revisions)),$(prev_revisions))
+
+prev_fullver ?= $(shell dpkg-parsechangelog -l$(DEBIAN)/changelog -o1 -c1 | sed -ne 's/^Version: *//p')
+
+family=ubuntu
+
+# This is an internally used mechanism for the daily kernel builds. It
+# creates packages whose ABI is suffixed with a minimal representation of
+# the current git HEAD sha. If .git/HEAD is not present, then it uses the
+# uuidgen program,
+#
+# AUTOBUILD can also be used by anyone wanting to build a custom kernel
+# image, or rebuild the entire set of Ubuntu packages using custom patches
+# or configs.
+AUTOBUILD=
+
+ifneq ($(AUTOBUILD),)
+skipabi                = true
+skipmodule     = true
+skipdbg                = true
+gitver=$(shell if test -f .git/HEAD; then cat .git/HEAD; else uuidgen; fi)
+gitverpre=$(shell echo $(gitver) | cut -b -3)
+gitverpost=$(shell echo $(gitver) | cut -b 38-40)
+abi_suffix = -$(gitverpre)$(gitverpost)
+endif
+
+ifneq ($(NOKERNLOG),)
+ubuntu_log_opts += --no-kern-log
+endif
+ifneq ($(PRINTSHAS),)
+ubuntu_log_opts += --print-shas
+endif
+
+# Get the kernels own extra version to be added to the release signature.
+raw_kernelversion=$(shell make kernelversion)
+
+#
+# full_build -- are we doing a full buildd style build
+#
+ifeq ($(wildcard /CurrentlyBuilding),)
+full_build?=false
+else
+full_build?=true
+endif
+
+#
+# The debug packages are ginormous, so you probably want to skip
+# building them (as a developer).
+#
+ifeq ($(full_build),false)
+skipdbg=true
+endif
+
+abinum         := $(shell echo $(revision) | sed -r -e 's/([^\+~]*)\.[^\.]+(~.*)?(\+.*)?$$/\1/')$(abi_suffix)
+prev_abinum    := $(shell echo $(prev_revision) | sed -r -e 's/([^\+~]*)\.[^\.]+(~.*)?(\+.*)?$$/\1/')$(abi_suffix)
+abi_release    := $(release)-$(abinum)
+
+uploadnum      := $(shell echo $(revision) | sed -r -e 's/[^\+~]*\.([^\.~]+(~.*)?(\+.*)?$$)/\1/')
+ifneq ($(full_build),false)
+  uploadnum    := $(uploadnum)-Ubuntu
+endif
+
+# XXX: linux-libc-dev got bumped to -803.N inadvertantly by a ti-omap4 upload
+#      shift our version higher for this package only.  Ensure this only
+#      occurs for the v2.6.35 kernel so that we do not propogate this into
+#      any other series.
+raw_uploadnum  := $(shell echo $(revision) | sed -e 's/.*\.//')
+libc_dev_version :=
+ifeq ($(DEBIAN),debian.master)
+ifeq ($(release),2.6.35)
+libc_dev_version := -v$(release)-$(shell expr "$(abinum)" + 1000).$(raw_uploadnum)
+endif
+endif
+
+DEB_HOST_MULTIARCH = $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
+DEB_HOST_GNU_TYPE  = $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE = $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+DEB_HOST_ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH)
+DEB_BUILD_ARCH = $(shell dpkg-architecture -qDEB_BUILD_ARCH)
+
+#
+# Detect invocations of the form 'fakeroot debian/rules binary arch=armhf'
+# within an x86'en schroot. This only gets you part of the way since the
+# packaging phase fails, but you can at least compile the kernel quickly.
+#
+arch := $(DEB_HOST_ARCH)
+ifneq ($(arch),$(DEB_HOST_ARCH))
+       CROSS_COMPILE ?= $(shell dpkg-architecture -a$(arch) -qDEB_HOST_GNU_TYPE -f 2>/dev/null)-
+endif
+
+#
+# Detect invocations of the form 'dpkg-buildpackage -B -aarmhf' within
+# an x86'en schroot. This is the only way to build all of the packages
+# (except for tools).
+#
+ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
+       CROSS_COMPILE ?= $(DEB_HOST_GNU_TYPE)-
+endif
+
+abidir         := $(CURDIR)/$(DEBIAN)/abi/$(release)-$(revision)/$(arch)
+prev_abidir    := $(CURDIR)/$(DEBIAN)/abi/$(release)-$(prev_revision)/$(arch)
+commonconfdir  := $(CURDIR)/$(DEBIAN)/config
+archconfdir    := $(CURDIR)/$(DEBIAN)/config/$(arch)
+sharedconfdir  := $(CURDIR)/debian.master/config
+builddir       := $(CURDIR)/debian/build
+stampdir       := $(CURDIR)/debian/stamps
+
+#
+# The binary package name always starts with linux-image-$KVER-$ABI.$UPLOAD_NUM. There
+# are places that you'll find linux-image hard coded, but I guess thats OK since the
+# assumption that the binary package always starts with linux-image will never change.
+#
+bin_pkg_name=linux-image-$(abi_release)
+extra_pkg_name=linux-image-extra-$(abi_release)
+hdrs_pkg_name=linux-headers-$(abi_release)
+indep_hdrs_pkg_name=$(src_pkg_name)-headers-$(abi_release)
+
+#
+# The generation of content in the doc package depends on both 'AUTOBUILD=' and
+# 'do_doc_package_content=true'. There are usually build errors during the development
+# cycle, so its OK to leave 'do_doc_package_content=false' until those build
+# failures get sorted out. Finally, the doc package doesn't really need to be built
+# for developer testing (its kind of slow), so only do it if on a buildd.
+do_doc_package=true
+do_doc_package_content=true
+ifeq ($(full_build),false)
+do_doc_package_content=false
+endif
+doc_pkg_name=$(src_pkg_name)-doc
+
+#
+# Similarly with the linux-source package, you need not build it as a developer. Its
+# somewhat I/O intensive and utterly useless.
+#
+do_source_package=true
+do_source_package_content=true
+ifeq ($(full_build),false)
+do_source_package_content=false
+endif
+
+# linux-libc-dev may not be needed, default to building it.
+do_libc_dev_package=true
+
+# common headers normally is built as an indep package, but may be arch
+do_common_headers_indep=true
+
+# add a 'full source' mode
+do_full_source=false
+
+# build tools
+ifneq ($(wildcard $(CURDIR)/tools),)
+       ifeq ($(do_tools),)
+               ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
+                       do_tools=false
+               endif
+       endif
+       do_tools?=true
+else
+       do_tools?=false
+endif
+tools_pkg_name=$(src_pkg_name)-tools-$(abi_release)
+tools_common_pkg_name=$(src_pkg_name)-tools-common
+tools_flavour_pkg_name=linux-tools-$(abi_release)
+cloud_pkg_name=$(src_pkg_name)-cloud-tools-$(abi_release)
+cloud_common_pkg_name=$(src_pkg_name)-cloud-tools-common
+cloud_flavour_pkg_name=linux-cloud-tools-$(abi_release)
+
+# The general flavour specific image package.
+do_flavour_image_package=true
+
+# The general flavour specific header package.
+do_flavour_header_package=true
+
+# DTBs
+do_dtbs=false
+
+# Support parallel=<n> in DEB_BUILD_OPTIONS (see #209008)
+#
+# These 2 environment variables set the -j value of the kernel build. For example,
+# CONCURRENCY_LEVEL=16 fakeroot $(DEBIAN)/rules binary-debs
+# or
+# DEB_BUILD_OPTIONS=parallel=16 fakeroot $(DEBIAN)/rules binary-debs
+#
+# The default is to use the number of CPUs.
+#
+COMMA=,
+DEB_BUILD_OPTIONS_PARA = $(subst parallel=,,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS))))
+ifneq (,$(DEB_BUILD_OPTIONS_PARA))
+  CONCURRENCY_LEVEL := $(DEB_BUILD_OPTIONS_PARA)
+endif
+
+ifeq ($(CONCURRENCY_LEVEL),)
+  # Check the environment
+  CONCURRENCY_LEVEL := $(shell echo $$CONCURRENCY_LEVEL)
+  # No? Then build with the number of CPUs on the host.
+  ifeq ($(CONCURRENCY_LEVEL),)
+      CONCURRENCY_LEVEL := $(shell expr `getconf _NPROCESSORS_ONLN` \* 1)
+  endif
+  # Oh hell, give 'em one
+  ifeq ($(CONCURRENCY_LEVEL),)
+    CONCURRENCY_LEVEL := 1
+  endif
+endif
+
+conc_level             = -j$(CONCURRENCY_LEVEL)
+
+# target_flavour is filled in for each step
+kmake = make ARCH=$(build_arch) \
+       CROSS_COMPILE=$(CROSS_COMPILE) \
+       KERNELVERSION=$(abi_release)-$(target_flavour) \
+       CONFIG_DEBUG_SECTION_MISMATCH=y \
+       KBUILD_BUILD_VERSION="$(uploadnum)" \
+       LOCALVERSION= localver-extra= \
+       CFLAGS_MODULE="-DPKG_ABI=$(abinum)"
+ifneq ($(LOCAL_ENV_CC),)
+kmake += CC=$(LOCAL_ENV_CC) DISTCC_HOSTS=$(LOCAL_ENV_DISTCC_HOSTS)
+endif
+
+# Locking is required in parallel builds to prevent loss of contents
+# of the debian/files.
+lockme_file = $(CURDIR)/debian/.LOCK
+lockme_cmd = flock -w 60
+lockme = $(lockme_cmd) $(lockme_file)
+
+# Don't fail if a link already exists.
+LN = ln -sf
+
+# Checks if a var is overriden by the custom rules. Called with var and
+# flavour as arguments.
+custom_override = \
+ $(shell if [ -n "$($(1)_$(2))" ]; then echo "$($(1)_$(2))"; else echo "$($(1))"; fi)
diff --git a/debian/rules.d/1-maintainer.mk b/debian/rules.d/1-maintainer.mk
new file mode 100644 (file)
index 0000000..0c579c8
--- /dev/null
@@ -0,0 +1,130 @@
+# The following targets are for the maintainer only! do not run if you don't
+# know what they do.
+
+.PHONY: printenv updateconfigs printchanges insertchanges startnewrelease diffupstream help updateportsconfigs editportsconfigs autoreconstruct
+
+help:
+       @echo "These are the targets in addition to the normal $(DEBIAN) ones:"
+       @echo
+       @echo "  printenv        : Print some variables used in the build"
+       @echo
+       @echo "  updateconfigs        : Update core arch configs"
+       @echo
+       @echo "  editconfigs          : Update core arch configs interractively"
+       @echo "  genconfigs           : Generate core arch configs in CONFIGS/*"
+       @echo
+       @echo "  updateportsconfigs   : Update ports arch configs"
+       @echo
+       @echo "  editportsconfigs     : Update ports arch configs interactivly"
+       @echo "  genportconfigs       : Generate ports arch configs in CONFIGS/*"
+       @echo
+       @echo "  printchanges    : Print the current changelog entries (from git)"
+       @echo
+       @echo "  insertchanges   : Insert current changelog entries (from git)"
+       @echo
+       @echo "  startnewrelease : Start a new changelog set"
+       @echo
+       @echo "  diffupstream    : Diff stock kernel code against upstream (git)"
+       @echo
+       @echo "  help            : If you are kernel hacking, you need the professional"
+       @echo "                    version of this"
+       @echo
+       @echo "Environment variables:"
+       @echo
+       @echo "  NOKERNLOG       : Do not add upstream kernel commits to changelog"
+       @echo "  CONCURRENCY_LEVEL=X"
+       @echo "                  : Use -jX for kernel compile"
+       @echo "  PRINTSHAS       : Include SHAs for commits in changelog"
+
+printdebian:
+       @echo "$(DEBIAN)"
+
+updateconfigs defaultconfigs editconfigs genconfigs dumpconfigs:
+       dh_testdir;
+       $(SHELL) $(DROOT)/scripts/misc/kernelconfig $@
+       rm -rf build
+
+updateportsconfigs defaultportsconfigs editportsconfigs genportsconfigs askconfigs:
+       dh_testdir;
+       $(SHELL) $(DROOT)/scripts/misc/kernelconfig $@ ports
+       rm -rf build
+
+printenv:
+       dh_testdir
+       @echo "src package name  = $(src_pkg_name)"
+       @echo "release           = $(release)"
+       @echo "revisions         = $(revisions)"
+       @echo "revision          = $(revision)"
+       @echo "uploadnum         = $(uploadnum)"
+       @echo "prev_revisions    = $(prev_revisions)"
+       @echo "prev_revision     = $(prev_revision)"
+       @echo "abinum            = $(abinum)"
+       @echo "gitver            = $(gitver)"
+       @echo "flavours          = $(flavours)"
+       @echo "skipabi           = $(skipabi)"
+       @echo "skipmodule        = $(skipmodule)"
+       @echo "skipdbg           = $(skipdbg)"
+       @echo "ubuntu_log_opts   = $(ubuntu_log_opts)"
+       @echo "CONCURRENCY_LEVEL = $(CONCURRENCY_LEVEL)"
+       @echo "bin package name  = $(bin_pkg_name)"
+       @echo "hdr package name  = $(hdrs_pkg_name)"
+       @echo "doc package name  = $(doc_pkg_name)"
+       @echo "do_doc_package            = $(do_doc_package)"
+       @echo "do_doc_package_content    = $(do_doc_package_content)"
+       @echo "do_source_package         = $(do_source_package)"
+       @echo "do_source_package_content = $(do_source_package_content)"
+       @echo "do_libc_dev_package       = $(do_libc_dev_package)"
+       @echo "do_flavour_image_package  = $(do_flavour_image_package)"
+       @echo "do_flavour_header_package = $(do_flavour_header_package)"
+       @echo "do_common_headers_indep   = $(do_common_headers_indep)"
+       @echo "do_full_source            = $(do_full_source)"
+       @echo "do_tools                  = $(do_tools)"
+       @echo "do_any_tools              = $(do_any_tools)"
+       @echo "do_linux_tools            = $(do_linux_tools)"
+       @echo " do_tools_cpupower         = $(do_tools_cpupower)"
+       @echo " do_tools_perf             = $(do_tools_perf)"
+       @echo " do_tools_x86              = $(do_tools_x86)"
+       @echo "do_cloud_tools            = $(do_cloud_tools)"
+       @echo " do_tools_hyperv           = $(do_tools_hyperv)"
+       @echo "full_build                = $(full_build)"
+       @echo "libc_dev_version          = $(libc_dev_version)"
+       @echo "DEB_HOST_GNU_TYPE         = $(DEB_HOST_GNU_TYPE)"
+       @echo "DEB_BUILD_GNU_TYPE        = $(DEB_BUILD_GNU_TYPE)"
+       @echo "DEB_HOST_ARCH             = $(DEB_HOST_ARCH)"
+       @echo "DEB_BUILD_ARCH            = $(DEB_BUILD_ARCH)"
+       @echo "arch                      = $(arch)"
+       @echo "kmake                     = $(kmake)"
+
+printchanges:
+       @baseCommit=$$(git log --pretty=format:'%H %s' | \
+               gawk '/UBUNTU: '".*Ubuntu-`echo $(prev_fullver) | sed 's/+/\\\\+/'`"'$$/ { print $$1; exit }'); \
+               git log "$$baseCommit"..HEAD | \
+               $(DROOT)/scripts/misc/git-ubuntu-log $(ubuntu_log_opts)
+
+insertchanges: autoreconstruct
+       @perl -w -f $(DROOT)/scripts/misc/insert-changes.pl $(DROOT) $(DEBIAN) 
+
+autoreconstruct:
+       $(DROOT)/scripts/misc/gen-auto-reconstruct $(release) $(DEBIAN)/reconstruct $(DROOT)/source/options
+
+diffupstream:
+       @git diff-tree -p refs/remotes/linux-2.6/master..HEAD $(shell ls | grep -vE '^(ubuntu|$(DEBIAN)|\.git.*)')
+
+startnewrelease:
+       dh_testdir
+       @nextminor=$(shell expr `echo $(revision) | gawk -F. '{print $$2}'` + 1); \
+       nextmajor=$(shell expr `echo $(revision) | awk -F. '{print $$1}'` + 1); \
+       now="$(shell date -R)"; \
+       echo "Creating new changelog set for $(release)-$$nextmajor.$$nextminor..."; \
+       echo -e "$(src_pkg_name) ($(release)-$$nextmajor.$$nextminor) UNRELEASED; urgency=low\n" > $(DEBIAN)/changelog.new; \
+       echo "  CHANGELOG: Do not edit directly. Autogenerated at release." >> \
+               $(DEBIAN)/changelog.new; \
+       echo "  CHANGELOG: Use the printchanges target to see the curent changes." \
+               >> $(DEBIAN)/changelog.new; \
+       echo "  CHANGELOG: Use the insertchanges target to create the final log." \
+               >> $(DEBIAN)/changelog.new; \
+       echo -e "\n -- $$DEBFULLNAME <$$DEBEMAIL>  $$now\n" >> \
+               $(DEBIAN)/changelog.new ; \
+       cat $(DEBIAN)/changelog >> $(DEBIAN)/changelog.new; \
+       mv $(DEBIAN)/changelog.new $(DEBIAN)/changelog
+
diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
new file mode 100644 (file)
index 0000000..4f1c7ce
--- /dev/null
@@ -0,0 +1,736 @@
+# We don't want make removing intermediary stamps
+.SECONDARY :
+
+# Prepare the out-of-tree build directory
+ifeq ($(do_full_source),true)
+build_cd = cd $(builddir)/build-$*; #
+build_O  =
+else
+build_cd =
+build_O  = O=$(builddir)/build-$*
+endif
+
+# Typically supplied from the arch makefile, e.g., debian.master/control.d/armhf.mk
+ifneq ($(gcc),)
+kmake += CC=$(CROSS_COMPILE)$(gcc)
+endif
+
+shlibdeps_opts = $(if $(CROSS_COMPILE),-- -l$(CROSS_COMPILE:%-=/usr/%)/lib)
+
+$(stampdir)/stamp-prepare-%: config-prepare-check-%
+       @echo Debug: $@
+       @touch $@
+$(stampdir)/stamp-prepare-tree-%: target_flavour = $*
+$(stampdir)/stamp-prepare-tree-%: $(commonconfdir)/config.common.$(family) $(archconfdir)/config.common.$(arch) $(archconfdir)/config.flavour.%
+       @echo Debug: $@
+       install -d $(builddir)/build-$*
+       touch $(builddir)/build-$*/ubuntu-build
+       [ "$(do_full_source)" != 'true' ] && true || \
+               rsync -a --exclude debian --exclude debian.master --exclude $(DEBIAN) * $(builddir)/build-$*
+       cat $^ | sed -e 's/.*CONFIG_VERSION_SIGNATURE.*/CONFIG_VERSION_SIGNATURE="Ubuntu $(release)-$(revision)-$* $(raw_kernelversion)"/' > $(builddir)/build-$*/.config
+       find $(builddir)/build-$* -name "*.ko" | xargs rm -f
+       $(build_cd) $(kmake) $(build_O) -j1 silentoldconfig prepare scripts
+       touch $@
+
+# Used by developers as a shortcut to prepare a tree for compilation.
+prepare-%: $(stampdir)/stamp-prepare-%
+       @echo Debug: $@
+# Used by developers to allow efficient pre-building without fakeroot.
+build-%: $(stampdir)/stamp-build-%
+       @echo Debug: $@
+
+define build_zfs =
+       #
+       # SPL/ZFS wants a fully built kernel before you can configure and build.
+       # It seems to be impossible to tease out the application configuration
+       # from the modules, but at least one can build just the modules.
+       #
+       install -d $(builddir)/build-$*/spl
+       rsync -a --exclude=dkms.conf --delete spl/ $(builddir)/build-$*/spl/
+       cd $(builddir)/build-$*/spl; sh autogen.sh; sh configure $(splopts)
+       $(kmake) -C $(builddir)/build-$*/spl/module $(conc_level)
+
+       install -d $(builddir)/build-$*/zfs
+       rsync -a --exclude=dkms.conf --delete zfs/ $(builddir)/build-$*/zfs/
+       cd $(builddir)/build-$*/zfs; sh autogen.sh; sh configure $(zfsopts)
+       $(kmake) -C $(builddir)/build-$*/zfs/module $(conc_level)
+endef
+
+# Do the actual build, including image and modules
+$(stampdir)/stamp-build-%: target_flavour = $*
+$(stampdir)/stamp-build-%: splopts  = --with-linux=$(CURDIR)
+$(stampdir)/stamp-build-%: splopts += --with-linux-obj=$(builddir)/build-$*
+$(stampdir)/stamp-build-%: zfsopts  = $(splopts)
+$(stampdir)/stamp-build-%: zfsopts += --with-spl=$(builddir)/build-$*/spl
+$(stampdir)/stamp-build-%: zfsopts += --with-spl-obj=$(builddir)/build-$*/spl
+$(stampdir)/stamp-build-%: zfsopts += --prefix=/usr --with-config=kernel
+$(stampdir)/stamp-build-%: bldimg = $(call custom_override,build_image,$*)
+$(stampdir)/stamp-build-%: enable_zfs = $(call custom_override,do_zfs,$*)
+$(stampdir)/stamp-build-%: $(stampdir)/stamp-prepare-%
+       @echo Debug: $@ build_image $(build_image) bldimg $(bldimg)
+       $(build_cd) $(kmake) $(build_O) $(conc_level) $(bldimg) modules $(if $(filter true,$(do_dtbs)),dtbs)
+
+       $(if $(filter true,$(enable_zfs)),$(call build_zfs))
+
+       @touch $@
+
+define install_zfs =
+       cd $(builddir)/build-$*/spl/module; \
+               $(kmake) -C $(builddir)/build-$* SUBDIRS=`pwd` modules_install $(splopts)
+       cd $(builddir)/build-$*/zfs/module; \
+               $(kmake) -C $(builddir)/build-$* SUBDIRS=`pwd` modules_install $(zfsopts)
+endef
+
+# Install the finished build
+install-%: pkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*
+install-%: pkgdir_ex = $(CURDIR)/debian/$(extra_pkg_name)-$*
+install-%: bindoc = $(pkgdir)/usr/share/doc/$(bin_pkg_name)-$*
+install-%: dbgpkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*-dbgsym
+install-%: signed = $(CURDIR)/debian/$(bin_pkg_name)-signed
+install-%: toolspkgdir = $(CURDIR)/debian/$(tools_flavour_pkg_name)-$*
+install-%: cloudpkgdir = $(CURDIR)/debian/$(cloud_flavour_pkg_name)-$*
+install-%: basepkg = $(hdrs_pkg_name)
+install-%: indeppkg = $(indep_hdrs_pkg_name)
+install-%: kernfile = $(call custom_override,kernel_file,$*)
+install-%: instfile = $(call custom_override,install_file,$*)
+install-%: hdrdir = $(CURDIR)/debian/$(basepkg)-$*/usr/src/$(basepkg)-$*
+install-%: target_flavour = $*
+install-%: MODHASHALGO=sha512
+install-%: MODSECKEY=$(builddir)/build-$*/certs/signing_key.pem
+install-%: MODPUBKEY=$(builddir)/build-$*/certs/signing_key.x509
+install-%: build_dir=$(builddir)/build-$*
+install-%: enable_zfs = $(call custom_override,do_zfs,$*)
+install-%: splopts  = INSTALL_MOD_STRIP=1
+install-%: splopts += INSTALL_MOD_PATH=$(pkgdir)/
+install-%: splopts += INSTALL_MOD_DIR=kernel/zfs
+install-%: splopts += $(conc_level)
+install-%: zfsopts  = $(splopts)
+install-%: checks-%
+       @echo Debug: $@ kernel_file $(kernel_file) kernfile $(kernfile) install_file $(install_file) instfile $(instfile)
+       dh_testdir
+       dh_testroot
+       dh_clean -k -p$(bin_pkg_name)-$*
+       dh_clean -k -p$(hdrs_pkg_name)-$*
+ifneq ($(skipdbg),true)
+       dh_clean -k -p$(dbg_pkg_name)-$*
+endif
+
+       # The main image
+       # compress_file logic required because not all architectures
+       # generate a zImage automatically out of the box
+ifeq ($(compress_file),)
+       install -m600 -D $(builddir)/build-$*/$(kernfile) \
+               $(pkgdir)/boot/$(instfile)-$(abi_release)-$*
+else
+       install -d $(pkgdir)/boot
+       gzip -c9v $(builddir)/build-$*/$(kernfile) > \
+               $(pkgdir)/boot/$(instfile)-$(abi_release)-$*
+       chmod 600 $(pkgdir)/boot/$(instfile)-$(abi_release)-$*
+endif
+
+ifeq ($(uefi_signed),true)
+       install -d $(signed)/$(release)-$(revision)
+       # Check to see if this supports handoff, if not do not sign it.
+       # Check the identification area magic and version >= 0x020b
+       handoff=`dd if="$(pkgdir)/boot/$(instfile)-$(abi_release)-$*" bs=1 skip=514 count=6 2>/dev/null | od -s | gawk '($$1 == 0 && $$2 == 25672 && $$3 == 21362 && $$4 >= 523) { print "GOOD" }'`; \
+       if [ "$$handoff" = "GOOD" ]; then \
+               cp -p $(pkgdir)/boot/$(instfile)-$(abi_release)-$* \
+                       $(signed)/$(release)-$(revision)/$(instfile)-$(abi_release)-$*.efi; \
+       fi
+endif
+
+       install -m644 $(builddir)/build-$*/.config \
+               $(pkgdir)/boot/config-$(abi_release)-$*
+       install -m644 $(abidir)/$* \
+               $(pkgdir)/boot/abi-$(abi_release)-$*
+       install -m600 $(builddir)/build-$*/System.map \
+               $(pkgdir)/boot/System.map-$(abi_release)-$*
+       if [ "$(filter true,$(do_dtbs))" ]; then \
+               $(build_cd) $(kmake) $(build_O) $(conc_level) dtbs_install \
+                       INSTALL_DTBS_PATH=$(pkgdir)/lib/firmware/$(abi_release)-$*/device-tree; \
+               ( cd $(pkgdir)/lib/firmware/$(abi_release)-$*/ && find device-tree -print ) | \
+               while read dtb_file; do \
+                       echo "$$dtb_file ?" >> $(DEBIAN)/d-i/firmware/$(arch)/kernel-image; \
+               done; \
+       fi
+ifeq ($(no_dumpfile),)
+       makedumpfile -g $(pkgdir)/boot/vmcoreinfo-$(abi_release)-$* \
+               -x $(builddir)/build-$*/vmlinux
+       chmod 0600 $(pkgdir)/boot/vmcoreinfo-$(abi_release)-$*
+endif
+
+       $(build_cd) $(kmake) $(build_O) $(conc_level) modules_install $(vdso) \
+               INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$(pkgdir)/ \
+               INSTALL_FW_PATH=$(pkgdir)/lib/firmware/$(abi_release)-$*
+
+       $(if $(filter true,$(enable_zfs)),$(call install_zfs))
+
+       #
+       # Build module blacklists:
+       #  - blacklist all watchdog drivers (LP:1432837)
+       #
+       install -d $(pkgdir)/lib/modprobe.d
+       echo "# Kernel supplied blacklist for $(src_pkg_name) $(abi_release)-$* $(arch)" \
+               >$(pkgdir)/lib/modprobe.d/blacklist_$(src_pkg_name)_$(abi_release)-$*.conf
+       for conf in $(arch)-$* $(arch) common.conf; do \
+               if [ -f $(DEBIAN)/modprobe.d/$$conf ]; then \
+                       echo "# modprobe.d/$$conf"; \
+                       cat $(DEBIAN)/modprobe.d/$$conf; \
+               fi; \
+       done >>$(pkgdir)/lib/modprobe.d/blacklist_$(src_pkg_name)_$(abi_release)-$*.conf
+       echo "# Autogenerated watchdog blacklist" \
+               >>$(pkgdir)/lib/modprobe.d/blacklist_$(src_pkg_name)_$(abi_release)-$*.conf
+       ls -1 $(pkgdir)/lib/modules/$(abi_release)-$*/kernel/drivers/watchdog/ | \
+               sed -e 's/^/blacklist /' -e 's/.ko$$//' | \
+               sort -u \
+               >>$(pkgdir)/lib/modprobe.d/blacklist_$(src_pkg_name)_$(abi_release)-$*.conf
+
+ifeq ($(do_extras_package),true)
+       #
+       # Remove all modules not in the inclusion list.
+       #
+       if [ -f $(DEBIAN)/control.d/$(target_flavour).inclusion-list ] ; then \
+               /sbin/depmod -v -b $(pkgdir) $(abi_release)-$* | \
+                       sed -e "s@$(pkgdir)/lib/modules/$(abi_release)-$*/kernel/@@g" | \
+                       awk '{ print $$1 " " $$NF}' >$(build_dir)/module-inclusion.depmap; \
+               mkdir -p $(pkgdir_ex)/lib/modules/$(abi_release)-$*; \
+               mv $(pkgdir)/lib/modules/$(abi_release)-$*/kernel \
+                       $(pkgdir_ex)/lib/modules/$(abi_release)-$*/kernel; \
+               $(SHELL) $(DROOT)/scripts/module-inclusion --master \
+                       $(pkgdir_ex)/lib/modules/$(abi_release)-$*/kernel \
+                       $(pkgdir)/lib/modules/$(abi_release)-$*/kernel \
+                       $(DEBIAN)/control.d/$(target_flavour).inclusion-list \
+                       $(build_dir)/module-inclusion.depmap 2>&1 | \
+                               tee $(target_flavour).inclusion-list.log; \
+               /sbin/depmod -b $(pkgdir) -ea -F $(pkgdir)/boot/System.map-$(abi_release)-$* \
+                       $(abi_release)-$* 2>&1 |tee $(target_flavour).depmod.log; \
+               if [ `grep -c 'unknown symbol' $(target_flavour).depmod.log` -gt 0 ]; then \
+                       echo "EE: Unresolved module dependencies in base package!"; \
+                       exit 1; \
+               fi \
+       fi
+endif
+
+ifeq ($(no_dumpfile),)
+       makedumpfile -g $(pkgdir)/boot/vmcoreinfo-$(abi_release)-$* \
+               -x $(builddir)/build-$*/vmlinux
+       chmod 0600 $(pkgdir)/boot/vmcoreinfo-$(abi_release)-$*
+endif
+       rm -f $(pkgdir)/lib/modules/$(abi_release)-$*/build
+       rm -f $(pkgdir)/lib/modules/$(abi_release)-$*/source
+
+       # Some initramfs-tools specific modules
+       install -d $(pkgdir)/lib/modules/$(abi_release)-$*/initrd
+       if [ -f $(pkgdir)/lib/modules/$(abi_release)-$*/kernel/drivers/video/vesafb.ko ]; then\
+         $(LN) $(pkgdir)/lib/modules/$(abi_release)-$*/kernel/drivers/video/vesafb.ko \
+               $(pkgdir)/lib/modules/$(abi_release)-$*/initrd/; \
+       fi
+
+       # Now the image scripts
+       install -d $(pkgdir)/DEBIAN
+       for script in postinst postrm preinst prerm; do                         \
+         sed -e 's/=V/$(abi_release)-$*/g' -e 's/=K/$(instfile)/g'             \
+             -e 's/=L/$(loader)/g'         -e 's@=B@$(build_arch)@g'           \
+              $(DROOT)/control-scripts/$$script > $(pkgdir)/DEBIAN/$$script;   \
+         chmod 755 $(pkgdir)/DEBIAN/$$script;                                  \
+       done
+ifeq ($(do_extras_package),true)
+       # Install the postinit/postrm scripts in the extras package.
+       if [ -f $(DEBIAN)/control.d/$(target_flavour).inclusion-list ] ; then   \
+               install -d $(pkgdir_ex)/DEBIAN;                                 \
+               for script in postinst postrm ; do                              \
+                       sed -e 's/=V/$(abi_release)-$*/g' -e 's/=K/$(instfile)/g'               \
+                           -e 's/=L/$(loader)/g'         -e 's@=B@$(build_arch)@g'             \
+                           debian/control-scripts/extra-post > $(pkgdir_ex)/DEBIAN/$$script; \
+                       chmod 755 $(pkgdir_ex)/DEBIAN/$$script;                 \
+               done;                                                           \
+       fi
+endif
+
+       # Install the full changelog.
+ifeq ($(do_doc_package),true)
+       install -d $(bindoc)
+       cat $(DEBIAN)/changelog $(DEBIAN)/changelog.historical | \
+               gzip -9 >$(bindoc)/changelog.Debian.old.gz
+       chmod 644 $(bindoc)/changelog.Debian.old.gz
+endif
+
+ifneq ($(skipsub),true)
+       for sub in $($(*)_sub); do                                      \
+               if ! (TO=$$sub FROM=$* ABI_RELEASE=$(abi_release) $(SHELL)              \
+                       $(DROOT)/scripts/sub-flavour); then exit 1; fi;         \
+               /sbin/depmod -b debian/$(bin_pkg_name)-$$sub            \
+                       -ea -F debian/$(bin_pkg_name)-$$sub/boot/System.map-$(abi_release)-$* \
+                       $(abi_release)-$*;                                      \
+               install -d debian/$(bin_pkg_name)-$$sub/DEBIAN; \
+               for script in postinst postrm preinst prerm; do                 \
+                       sed -e 's/=V/$(abi_release)-$*/g'                       \
+                           -e 's/=K/$(instfile)/g'                             \
+                           -e 's/=L/$(loader)/g'                               \
+                           -e 's@=B@$(build_arch)@g'                           \
+                               $(DROOT)/control-scripts/$$script >             \
+                               debian/$(bin_pkg_name)-$$sub/DEBIAN/$$script;\
+                       chmod 755  debian/$(bin_pkg_name)-$$sub/DEBIAN/$$script;\
+               done;                                                           \
+       done
+endif
+
+ifneq ($(skipdbg),true)
+       # Debug image is simple
+       install -m644 -D $(builddir)/build-$*/vmlinux \
+               $(dbgpkgdir)/usr/lib/debug/boot/vmlinux-$(abi_release)-$*
+       $(build_cd) $(kmake) $(build_O) modules_install $(vdso) \
+               INSTALL_MOD_PATH=$(dbgpkgdir)/usr/lib/debug
+       # Add .gnu_debuglink sections to each stripped .ko
+       # pointing to unstripped verson
+       find $(pkgdir) -name '*.ko' | sed 's|$(pkgdir)||'| while read module ; do \
+               if [[ -f "$(dbgpkgdir)/usr/lib/debug/$$module" ]] ; then \
+                       $(CROSS_COMPILE)objcopy \
+                               --add-gnu-debuglink=$(dbgpkgdir)/usr/lib/debug/$$module \
+                               $(pkgdir)/$$module; \
+                       if grep -q CONFIG_MODULE_SIG=y $(builddir)/build-$*/.config; then \
+                               $(builddir)/build-$*/scripts/sign-file $(MODHASHALGO) \
+                                       $(MODSECKEY) \
+                                       $(MODPUBKEY) \
+                                       $(pkgdir)/$$module; \
+                       fi; \
+               fi; \
+       done
+       rm -f $(dbgpkgdir)/usr/lib/debug/lib/modules/$(abi_release)-$*/build
+       rm -f $(dbgpkgdir)/usr/lib/debug/lib/modules/$(abi_release)-$*/source
+       rm -f $(dbgpkgdir)/usr/lib/debug/lib/modules/$(abi_release)-$*/modules.*
+       rm -fr $(dbgpkgdir)/usr/lib/debug/lib/firmware
+endif
+
+       # The flavour specific headers image
+       # TODO: Would be nice if we didn't have to dupe the original builddir
+       install -d -m755 $(hdrdir)
+       cat $(builddir)/build-$*/.config | \
+               sed -e 's/.*CONFIG_DEBUG_INFO=.*/# CONFIG_DEBUG_INFO is not set/g' > \
+               $(hdrdir)/.config
+       chmod 644 $(hdrdir)/.config
+       $(kmake) O=$(hdrdir) -j1 silentoldconfig prepare scripts
+       # We'll symlink this stuff
+       rm -f $(hdrdir)/Makefile
+       rm -rf $(hdrdir)/include2 $(hdrdir)/source
+       # Copy over the compilation version.
+       cp "$(builddir)/build-$*/include/generated/compile.h" \
+               "$(hdrdir)/include/generated/compile.h"
+       # Add UTS_UBUNTU_RELEASE_ABI since UTS_RELEASE is difficult to parse.
+       echo "#define UTS_UBUNTU_RELEASE_ABI $(abinum)" >> $(hdrdir)/include/generated/utsrelease.h
+       # powerpc kernel arch seems to need some .o files for external module linking. Add them in.
+ifeq ($(build_arch),powerpc)
+       mkdir -p $(hdrdir)/arch/powerpc/lib
+       cp $(builddir)/build-$*/arch/powerpc/lib/*.o $(hdrdir)/arch/powerpc/lib
+endif
+       # Script to symlink everything up
+       $(SHELL) $(DROOT)/scripts/link-headers "$(hdrdir)" "$(indeppkg)" "$*"
+       # The build symlink
+       install -d debian/$(basepkg)-$*/lib/modules/$(abi_release)-$*
+       $(LN) /usr/src/$(basepkg)-$* \
+               debian/$(basepkg)-$*/lib/modules/$(abi_release)-$*/build
+       # And finally the symvers
+       install -m644 $(builddir)/build-$*/Module.symvers \
+               $(hdrdir)/Module.symvers
+
+       # Now the header scripts
+       install -d $(CURDIR)/debian/$(basepkg)-$*/DEBIAN
+       for script in postinst; do                                              \
+         sed -e 's/=V/$(abi_release)-$*/g' -e 's/=K/$(instfile)/g'     \
+               $(DROOT)/control-scripts/headers-$$script >                     \
+                       $(CURDIR)/debian/$(basepkg)-$*/DEBIAN/$$script;         \
+         chmod 755 $(CURDIR)/debian/$(basepkg)-$*/DEBIAN/$$script;             \
+       done
+
+       # At the end of the package prep, call the tests
+       DPKG_ARCH="$(arch)" KERN_ARCH="$(build_arch)" FLAVOUR="$*"      \
+        VERSION="$(abi_release)" REVISION="$(revision)"                \
+        PREV_REVISION="$(prev_revision)" ABI_NUM="$(abinum)"           \
+        PREV_ABI_NUM="$(prev_abinum)" BUILD_DIR="$(builddir)/build-$*" \
+        INSTALL_DIR="$(pkgdir)" SOURCE_DIR="$(CURDIR)"                 \
+        run-parts -v $(DROOT)/tests-build
+
+       #
+       # Remove files which are generated at installation by postinst,
+       # except for modules.order and modules.builtin
+       # 
+       # NOTE: need to keep this list in sync with postrm
+       #
+       mkdir $(pkgdir)/lib/modules/$(abi_release)-$*/_
+       mv $(pkgdir)/lib/modules/$(abi_release)-$*/modules.order \
+               $(pkgdir)/lib/modules/$(abi_release)-$*/_
+       if [ -f $(pkgdir)/lib/modules/$(abi_release)-$*/modules.builtin ] ; then \
+           mv $(pkgdir)/lib/modules/$(abi_release)-$*/modules.builtin \
+               $(pkgdir)/lib/modules/$(abi_release)-$*/_; \
+       fi
+       rm -f $(pkgdir)/lib/modules/$(abi_release)-$*/modules.*
+       mv $(pkgdir)/lib/modules/$(abi_release)-$*/_/* \
+               $(pkgdir)/lib/modules/$(abi_release)-$*
+       rmdir $(pkgdir)/lib/modules/$(abi_release)-$*/_
+
+ifeq ($(do_linux_tools),true)
+       # Create the linux-tools tool links
+       install -d $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+ifeq ($(do_tools_usbip),true)
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/usbip $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/usbipd $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+ifeq ($(do_tools_cpupower),true)
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/cpupower $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+ifeq ($(do_tools_perf),true)
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/perf $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+ifeq ($(do_tools_x86),true)
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/x86_energy_perf_policy $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/turbostat $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+endif
+ifeq ($(do_cloud_tools),true)
+ifeq ($(do_tools_hyperv),true)
+       # Create the linux-hyperv tool links
+       install -d $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/hv_kvp_daemon $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/hv_vss_daemon $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/hv_fcopy_daemon $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/lsvmbus $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+endif
+
+headers_tmp := $(CURDIR)/debian/tmp-headers
+headers_dir := $(CURDIR)/debian/linux-libc-dev
+
+hmake := $(MAKE) -C $(CURDIR) O=$(headers_tmp) \
+       KERNELVERSION=$(abi_release) INSTALL_HDR_PATH=$(headers_tmp)/install \
+       SHELL="$(SHELL)" ARCH=$(header_arch)
+
+install-arch-headers:
+       @echo Debug: $@
+       dh_testdir
+       dh_testroot
+       dh_clean -k -plinux-libc-dev
+
+       rm -rf $(headers_tmp)
+       install -d $(headers_tmp) $(headers_dir)/usr/include/
+
+       $(hmake) $(defconfig)
+       mv $(headers_tmp)/.config $(headers_tmp)/.config.old
+       sed -e 's/^# \(CONFIG_MODVERSIONS\) is not set$$/\1=y/' \
+         -e 's/.*CONFIG_LOCALVERSION_AUTO.*/# CONFIG_LOCALVERSION_AUTO is not set/' \
+         $(headers_tmp)/.config.old > $(headers_tmp)/.config
+       $(hmake) silentoldconfig
+       $(hmake) headers_install
+
+       ( cd $(headers_tmp)/install/include/ && \
+               find . -name '.' -o -name '.*' -prune -o -print | \
+                cpio -pvd --preserve-modification-time \
+                       $(headers_dir)/usr/include/ )
+       mkdir $(headers_dir)/usr/include/$(DEB_HOST_MULTIARCH)
+       mv $(headers_dir)/usr/include/asm $(headers_dir)/usr/include/$(DEB_HOST_MULTIARCH)/
+
+       rm -rf $(headers_tmp)
+
+binary-arch-headers: install-arch-headers
+       @echo Debug: $@
+       dh_testdir
+       dh_testroot
+ifeq ($(do_libc_dev_package),true)
+ifneq ($(DEBIAN),debian.master)
+       echo "non-master branch building linux-libc-dev, aborting"
+       exit 1
+endif
+       dh_installchangelogs -plinux-libc-dev
+       dh_installdocs -plinux-libc-dev
+       dh_compress -plinux-libc-dev
+       dh_fixperms -plinux-libc-dev
+       dh_installdeb -plinux-libc-dev
+       $(lockme) dh_gencontrol -plinux-libc-dev -- $(libc_dev_version)
+       dh_md5sums -plinux-libc-dev
+       dh_builddeb -plinux-libc-dev
+endif
+
+binary-%: pkgimg = $(bin_pkg_name)-$*
+binary-%: pkgimg_ex = $(extra_pkg_name)-$*
+binary-%: pkghdr = $(hdrs_pkg_name)-$*
+binary-%: dbgpkg = $(bin_pkg_name)-$*-dbgsym
+binary-%: dbgpkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*-dbgsym
+binary-%: pkgtools = $(tools_flavour_pkg_name)-$*
+binary-%: pkgcloud = $(cloud_flavour_pkg_name)-$*
+binary-%: rprovides = $(if $(filter true,$(call custom_override,do_zfs,$*)),$(comma) spl-dkms$(comma) zfs-dkms)
+binary-%: target_flavour = $*
+binary-%: install-%
+       @echo Debug: $@
+       dh_testdir
+       dh_testroot
+
+       dh_installchangelogs -p$(pkgimg)
+       dh_installdocs -p$(pkgimg)
+       dh_compress -p$(pkgimg)
+       dh_fixperms -p$(pkgimg) -X/boot/
+       dh_installdeb -p$(pkgimg)
+       dh_shlibdeps -p$(pkgimg) $(shlibdeps_opts)
+       $(lockme) dh_gencontrol -p$(pkgimg) -- -Vlinux:rprovides='$(rprovides)'
+       dh_md5sums -p$(pkgimg)
+       dh_builddeb -p$(pkgimg) -- -Zbzip2 -z9
+
+ifeq ($(do_extras_package),true)
+       if [ -f $(DEBIAN)/control.d/$(target_flavour).inclusion-list ] ; then \
+               dh_installchangelogs -p$(pkgimg_ex); \
+               dh_installdocs -p$(pkgimg_ex); \
+               dh_compress -p$(pkgimg_ex); \
+               dh_fixperms -p$(pkgimg_ex) -X/boot/; \
+               dh_installdeb -p$(pkgimg_ex); \
+               dh_shlibdeps -p$(pkgimg_ex) $(shlibdeps_opts); \
+               $(lockme) dh_gencontrol -p$(pkgimg_ex); \
+               dh_md5sums -p$(pkgimg_ex); \
+               dh_builddeb -p$(pkgimg_ex) -- -Zbzip2 -z9; \
+       fi
+endif
+
+       dh_installchangelogs -p$(pkghdr)
+       dh_installdocs -p$(pkghdr)
+       dh_compress -p$(pkghdr)
+       dh_fixperms -p$(pkghdr)
+       dh_shlibdeps -p$(pkghdr) $(shlibdeps_opts)
+       dh_installdeb -p$(pkghdr)
+       $(lockme) dh_gencontrol -p$(pkghdr)
+       dh_md5sums -p$(pkghdr)
+       dh_builddeb -p$(pkghdr)
+
+ifneq ($(skipsub),true)
+       @set -e; for sub in $($(*)_sub); do             \
+               pkg=$(bin_pkg_name)-$$sub;      \
+               dh_installchangelogs -p$$pkg;           \
+               dh_installdocs -p$$pkg;                 \
+               dh_compress -p$$pkg;                    \
+               dh_fixperms -p$$pkg -X/boot/;           \
+               dh_shlibdeps -p$$pkg $(shlibdeps_opts); \
+               dh_installdeb -p$$pkg;                  \
+               $(lockme) dh_gencontrol -p$$pkg;                        \
+               dh_md5sums -p$$pkg;                     \
+               dh_builddeb -p$$pkg;                    \
+       done
+endif
+
+ifneq ($(skipdbg),true)
+       dh_installchangelogs -p$(dbgpkg)
+       dh_installdocs -p$(dbgpkg)
+       dh_compress -p$(dbgpkg)
+       dh_fixperms -p$(dbgpkg)
+       dh_installdeb -p$(dbgpkg)
+       $(lockme) dh_gencontrol -p$(dbgpkg)
+       dh_md5sums -p$(dbgpkg)
+       dh_builddeb -p$(dbgpkg)
+
+       # Hokay...here's where we do a little twiddling...
+       # Renaming the debug package prevents it from getting into
+       # the primary archive, and therefore prevents this very large
+       # package from being mirrored. It is instead, through some
+       # archive admin hackery, copied to http://ddebs.ubuntu.com.
+       #
+       mv ../$(dbgpkg)_$(release)-$(revision)_$(arch).deb \
+               ../$(dbgpkg)_$(release)-$(revision)_$(arch).ddeb
+       set -e; \
+       ( \
+               $(lockme_cmd) 9 || exit 1; \
+               if grep -qs '^Build-Debug-Symbols: yes$$' /CurrentlyBuilding; then \
+                       sed -i '/^$(dbgpkg)_/s/\.deb /.ddeb /' debian/files; \
+               else \
+                       grep -v '^$(dbgpkg)_.*$$' debian/files > debian/files.new; \
+                       mv debian/files.new debian/files; \
+               fi; \
+       ) 9>$(lockme_file)
+       # Now, the package wont get into the archive, but it will get put
+       # into the debug system.
+endif
+
+ifeq ($(do_linux_tools),true)
+       dh_installchangelogs -p$(pkgtools)
+       dh_installdocs -p$(pkgtools)
+       dh_compress -p$(pkgtools)
+       dh_fixperms -p$(pkgtools)
+       dh_shlibdeps -p$(pkgtools) $(shlibdeps_opts)
+       dh_installdeb -p$(pkgtools)
+       $(lockme) dh_gencontrol -p$(pkgtools)
+       dh_md5sums -p$(pkgtools)
+       dh_builddeb -p$(pkgtools)
+endif
+ifeq ($(do_cloud_tools),true)
+       dh_installchangelogs -p$(pkgcloud)
+       dh_installdocs -p$(pkgcloud)
+       dh_compress -p$(pkgcloud)
+       dh_fixperms -p$(pkgcloud)
+       dh_shlibdeps -p$(pkgcloud) $(shlibdeps_opts)
+       dh_installdeb -p$(pkgcloud)
+       $(lockme) dh_gencontrol -p$(pkgcloud)
+       dh_md5sums -p$(pkgcloud)
+       dh_builddeb -p$(pkgcloud)
+endif
+
+ifneq ($(full_build),false)
+       # Clean out this flavours build directory.
+       rm -rf $(builddir)/build-$*
+       # Clean out the debugging package source directory.
+       rm -rf $(dbgpkgdir)
+endif
+
+#
+# per-architecture packages
+#
+builddirpa = $(builddir)/tools-perarch
+
+$(stampdir)/stamp-prepare-perarch:
+       @echo Debug: $@
+ifeq ($(do_any_tools),true)
+       rm -rf $(builddirpa)
+       install -d $(builddirpa)
+       rsync -a --exclude debian --exclude debian.master --exclude $(DEBIAN) --exclude .git -a ./ $(builddirpa)/
+endif
+       touch $@
+
+$(stampdir)/stamp-build-perarch: $(stampdir)/stamp-prepare-perarch install-arch-headers
+       @echo Debug: $@
+ifeq ($(do_linux_tools),true)
+ifeq ($(do_tools_usbip),true)
+       chmod 755 $(builddirpa)/tools/usb/usbip/autogen.sh
+       cd $(builddirpa)/tools/usb/usbip && ./autogen.sh
+       chmod 755 $(builddirpa)/tools/usb/usbip/configure
+       cd $(builddirpa)/tools/usb/usbip && ./configure --prefix=$(builddirpa)/tools/usb/usbip/bin
+       cd $(builddirpa)/tools/usb/usbip && make install CFLAGS="-g -O2 -static" CROSS_COMPILE=$(CROSS_COMPILE)
+endif
+ifeq ($(do_tools_cpupower),true)
+       # Allow for multiple installed versions of cpupower and libcpupower.so:
+       # Override LIB_MIN in order to to generate a versioned .so named
+       # libcpupower.so.$(abi_release) and link cpupower with that.
+       make -C $(builddirpa)/tools/power/cpupower \
+               CROSS_COMPILE=$(CROSS_COMPILE) \
+               CROSS=$(CROSS_COMPILE) \
+               LIB_MIN=$(abi_release) CPUFREQ_BENCH=false
+endif
+ifeq ($(do_tools_perf),true)
+       cd $(builddirpa) && $(kmake) $(defconfig)
+       mv $(builddirpa)/.config $(builddirpa)/.config.old
+       sed -e 's/^# \(CONFIG_MODVERSIONS\) is not set$$/\1=y/' \
+         -e 's/.*CONFIG_LOCALVERSION_AUTO.*/# CONFIG_LOCALVERSION_AUTO is not set/' \
+         $(builddirpa)/.config.old > $(builddirpa)/.config
+       cd $(builddirpa) && $(kmake) silentoldconfig
+       cd $(builddirpa) && $(kmake) prepare
+       cd $(builddirpa)/tools/perf && \
+               $(kmake) prefix=/usr HAVE_CPLUS_DEMANGLE=1 CROSS_COMPILE=$(CROSS_COMPILE) NO_LIBPYTHON=1 NO_LIBPERL=1 PYTHON=python2.7
+endif
+ifeq ($(do_tools_x86),true)
+       cd $(builddirpa)/tools/power/x86/x86_energy_perf_policy && make CROSS_COMPILE=$(CROSS_COMPILE)
+       cd $(builddirpa)/tools/power/x86/turbostat && make CROSS_COMPILE=$(CROSS_COMPILE)
+endif
+endif
+ifeq ($(do_cloud_tools),true)
+ifeq ($(do_tools_hyperv),true)
+       cd $(builddirpa)/tools/hv && make CFLAGS="-I$(headers_dir)/usr/include -I$(headers_dir)/usr/include/$(DEB_HOST_MULTIARCH)" CROSS_COMPILE=$(CROSS_COMPILE) hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
+endif
+endif
+       @touch $@
+
+install-perarch: toolspkgdir = $(CURDIR)/debian/$(tools_pkg_name)
+install-perarch: cloudpkgdir = $(CURDIR)/debian/$(cloud_pkg_name)
+install-perarch: $(stampdir)/stamp-build-perarch
+       @echo Debug: $@
+       # Add the tools.
+ifeq ($(do_linux_tools),true)
+       install -d $(toolspkgdir)/usr/lib
+       install -d $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+ifeq ($(do_tools_usbip),true)
+       install -m755 $(builddirpa)/tools/usb/usbip/bin/sbin/usbip \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/usb/usbip/bin/sbin/usbipd \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+endif
+ifeq ($(do_tools_cpupower),true)
+       install -m755 $(builddirpa)/tools/power/cpupower/cpupower \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       # Install only the full versioned libcpupower.so.$(abi_release), not
+       # the usual symlinks to it.
+       install -m644 $(builddirpa)/tools/power/cpupower/libcpupower.so.$(abi_release) \
+               $(toolspkgdir)/usr/lib/
+endif
+ifeq ($(do_tools_perf),true)
+       install -m755 $(builddirpa)/tools/perf/perf $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+endif
+ifeq ($(do_tools_x86),true)
+       install -m755 $(builddirpa)/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/power/x86/turbostat/turbostat \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+endif
+endif
+ifeq ($(do_cloud_tools),true)
+ifeq ($(do_tools_hyperv),true)
+       install -d $(cloudpkgdir)/usr/lib
+       install -d $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/hv/hv_kvp_daemon \
+               $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/hv/hv_vss_daemon \
+               $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/hv/hv_fcopy_daemon \
+               $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/hv/lsvmbus \
+               $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+endif
+endif
+
+binary-perarch: toolspkg = $(tools_pkg_name)
+binary-perarch: cloudpkg = $(cloud_pkg_name)
+binary-perarch: install-perarch
+       @echo Debug: $@
+ifeq ($(do_linux_tools),true)
+       dh_strip -p$(toolspkg)
+       dh_installchangelogs -p$(toolspkg)
+       dh_installdocs -p$(toolspkg)
+       dh_compress -p$(toolspkg)
+       dh_fixperms -p$(toolspkg)
+       dh_shlibdeps -p$(toolspkg) $(shlibdeps_opts)
+       dh_installdeb -p$(toolspkg)
+       $(lockme) dh_gencontrol -p$(toolspkg)
+       dh_md5sums -p$(toolspkg)
+       dh_builddeb -p$(toolspkg)
+endif
+ifeq ($(do_cloud_tools),true)
+       dh_strip -p$(cloudpkg)
+       dh_installchangelogs -p$(cloudpkg)
+       dh_installdocs -p$(cloudpkg)
+       dh_compress -p$(cloudpkg)
+       dh_fixperms -p$(cloudpkg)
+       dh_shlibdeps -p$(cloudpkg) $(shlibdeps_opts)
+       dh_installdeb -p$(cloudpkg)
+       $(lockme) dh_gencontrol -p$(cloudpkg)
+       dh_md5sums -p$(cloudpkg)
+       dh_builddeb -p$(cloudpkg)
+endif
+
+binary-debs: signed = $(CURDIR)/debian/$(bin_pkg_name)-signed
+binary-debs: signedv = $(CURDIR)/debian/$(bin_pkg_name)-signed/$(release)-$(revision)
+binary-debs: signed_tar = $(src_pkg_name)_$(release)-$(revision)_$(arch).tar.gz
+binary-debs: binary-perarch $(addprefix binary-,$(flavours))
+       @echo Debug: $@
+ifeq ($(uefi_signed),true)
+       echo $(release)-$(revision) > $(signedv)/version
+       cd $(signedv) && ls *.efi >flavours
+       cd $(signed) && tar czvf ../../../$(signed_tar) .
+       dpkg-distaddfile $(signed_tar) raw-uefi -
+endif
+
+build-arch-deps-$(do_flavour_image_package) += $(addprefix $(stampdir)/stamp-build-,$(flavours))
+build-arch: $(build-arch-deps-true)
+       @echo Debug: $@
+
+ifeq ($(AUTOBUILD),)
+binary-arch-deps-$(do_flavour_image_package) += binary-udebs
+else
+binary-arch-deps-$(do_flavour_image_package) = binary-debs
+endif
+binary-arch-deps-$(do_libc_dev_package) += binary-arch-headers
+ifneq ($(do_common_headers_indep),true)
+binary-arch-deps-$(do_flavour_header_package) += binary-headers
+endif
+binary-arch: $(binary-arch-deps-true)
+       @echo Debug: $@
+
diff --git a/debian/rules.d/3-binary-indep.mk b/debian/rules.d/3-binary-indep.mk
new file mode 100644 (file)
index 0000000..36cc169
--- /dev/null
@@ -0,0 +1,177 @@
+build-indep:
+       @echo Debug: $@
+
+# The binary-indep dependency chain is:
+#
+# install-headers <- install-doc <- install-source <- install-tools <- install-indep <- binary-indep
+# install-headers <- binary-headers
+#
+indep_hdrpkg = $(indep_hdrs_pkg_name)
+indep_hdrdir = $(CURDIR)/debian/$(indep_hdrpkg)/usr/src/$(indep_hdrpkg)
+install-headers:
+       @echo Debug: $@
+       dh_testdir
+       dh_testroot
+       dh_prep
+
+ifeq ($(do_flavour_header_package),true)
+       install -d $(indep_hdrdir)
+       find . -path './debian' -prune -o -path './$(DEBIAN)' -prune \
+         -o -path './include/*' -prune \
+         -o -path './scripts/*' -prune -o -type f \
+         \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
+            -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
+         -print | cpio -pd --preserve-modification-time $(indep_hdrdir)
+       cp -a scripts include $(indep_hdrdir)
+       (find arch -name include -type d -print | \
+               xargs -n1 -i: find : -type f) | \
+               cpio -pd --preserve-modification-time $(indep_hdrdir)
+endif
+
+docpkg = $(doc_pkg_name)
+docdir = $(CURDIR)/debian/$(docpkg)/usr/share/doc/$(docpkg)
+install-doc: install-headers
+       @echo Debug: $@
+ifeq ($(do_doc_package),true)
+       dh_testdir
+       dh_testroot
+
+       install -d $(docdir)
+ifeq ($(do_doc_package_content),true)
+       # First the html docs. We skip these for autobuilds
+       if [ -z "$(AUTOBUILD)" ]; then \
+               install -d $(docdir)/$(doc_pkg_name)-tmp; \
+               $(kmake) O=$(docdir)/$(doc_pkg_name)-tmp htmldocs; \
+               install -d $(docdir)/html; \
+               rsync -aL $(docdir)/$(doc_pkg_name)-tmp/Documentation/DocBook/ \
+                       $(docdir)/html/; \
+               rm -rf $(docdir)/$(doc_pkg_name)-tmp; \
+       fi
+endif
+       # Copy the rest
+       cp -a Documentation/* $(docdir)
+       rm -rf $(docdir)/DocBook
+       find $(docdir) -name .gitignore | xargs rm -f
+endif
+
+srcpkg = linux-source-$(release)
+srcdir = $(CURDIR)/debian/$(srcpkg)/usr/src/$(srcpkg)
+balldir = $(CURDIR)/debian/$(srcpkg)/usr/src/$(srcpkg)/$(srcpkg)
+install-source: install-doc
+       @echo Debug: $@
+ifeq ($(do_source_package),true)
+
+       install -d $(srcdir)
+ifeq ($(do_source_package_content),true)
+       find . -path './debian' -prune -o -path './$(DEBIAN)' -prune -o \
+               -path './.*' -prune -o -print | \
+               cpio -pd --preserve-modification-time $(balldir)
+       (cd $(srcdir); tar cf - $(srcpkg)) | bzip2 -9c > \
+               $(srcdir)/$(srcpkg).tar.bz2
+       rm -rf $(balldir)
+       find './debian' './$(DEBIAN)' \
+               -path './debian/linux-*' -prune -o \
+               -path './debian/$(src_pkg_name)-*' -prune -o \
+               -path './debian/build' -prune -o \
+               -path './debian/files' -prune -o \
+               -path './debian/stamps' -prune -o \
+               -path './debian/tmp' -prune -o \
+               -print | \
+               cpio -pd --preserve-modification-time $(srcdir)
+       $(LN) $(srcpkg)/$(srcpkg).tar.bz2 $(srcdir)/..
+endif
+endif
+
+install-tools: toolspkg = $(tools_common_pkg_name)
+install-tools: toolsbin = $(CURDIR)/debian/$(toolspkg)/usr/bin
+install-tools: toolssbin = $(CURDIR)/debian/$(toolspkg)/usr/sbin
+install-tools: toolsman = $(CURDIR)/debian/$(toolspkg)/usr/share/man
+install-tools: cloudpkg = $(cloud_common_pkg_name)
+install-tools: cloudbin = $(CURDIR)/debian/$(cloudpkg)/usr/bin
+install-tools: cloudsbin = $(CURDIR)/debian/$(cloudpkg)/usr/sbin
+install-tools: cloudman = $(CURDIR)/debian/$(cloudpkg)/usr/share/man
+install-tools: install-source $(stampdir)/stamp-build-perarch
+       @echo Debug: $@
+
+ifeq ($(do_tools_common),true)
+       rm -rf $(builddir)/tools
+       install -d $(builddir)/tools
+       for i in *; do $(LN) $(CURDIR)/$$i $(builddir)/tools/; done
+       rm $(builddir)/tools/tools
+       rsync -a tools/ $(builddir)/tools/tools/
+
+       install -d $(toolsbin)
+       install -d $(toolsman)/man1
+
+       install -m755 debian/tools/generic $(toolsbin)/usbip
+       install -m755 debian/tools/generic $(toolsbin)/usbipd
+       install -m644 $(CURDIR)/tools/usb/usbip/doc/*.8 $(toolsman)/man1/
+
+       install -m755 debian/tools/generic $(toolsbin)/cpupower
+       install -m644 $(CURDIR)/tools/power/cpupower/man/*.1 $(toolsman)/man1/
+
+       install -m755 debian/tools/generic $(toolsbin)/perf
+
+       install -m755 debian/tools/generic $(toolsbin)/x86_energy_perf_policy
+       install -m755 debian/tools/generic $(toolsbin)/turbostat
+
+       cd $(builddir)/tools/tools/perf && make man
+       install -m644 $(builddir)/tools/tools/perf/Documentation/*.1 \
+               $(toolsman)/man1
+
+       install -d $(toolsman)/man8
+       install -m644 $(CURDIR)/tools/power/x86/x86_energy_perf_policy/*.8 $(toolsman)/man8
+       install -m644 $(CURDIR)/tools/power/x86/turbostat/*.8 $(toolsman)/man8
+
+       install -d $(cloudsbin)
+       install -m755 debian/tools/generic $(cloudsbin)/hv_kvp_daemon
+       install -m755 debian/tools/generic $(cloudsbin)/hv_vss_daemon
+       install -m755 debian/tools/generic $(cloudsbin)/hv_fcopy_daemon
+       install -m755 debian/tools/generic $(cloudsbin)/lsvmbus
+       install -m755 debian/cloud-tools/hv_get_dhcp_info $(cloudsbin)
+       install -m755 debian/cloud-tools/hv_get_dns_info $(cloudsbin)
+       install -m755 debian/cloud-tools/hv_set_ifconfig $(cloudsbin)
+
+       install -d $(cloudman)/man8
+       install -m644 $(CURDIR)/tools/hv/*.8 $(cloudman)/man8
+
+endif
+
+install-indep: install-tools
+       @echo Debug: $@
+
+# This is just to make it easy to call manually. Normally done in
+# binary-indep target during builds.
+binary-headers: install-headers
+       @echo Debug: $@
+       dh_installchangelogs -p$(indep_hdrpkg)
+       dh_installdocs -p$(indep_hdrpkg)
+       dh_compress -p$(indep_hdrpkg)
+       dh_fixperms -p$(indep_hdrpkg)
+       dh_installdeb -p$(indep_hdrpkg)
+       $(lockme) dh_gencontrol -p$(indep_hdrpkg)
+       dh_md5sums -p$(indep_hdrpkg)
+       dh_builddeb -p$(indep_hdrpkg)
+
+binary-indep: cloudpkg = $(cloud_common_pkg_name)
+binary-indep: install-indep
+       @echo Debug: $@
+
+       dh_installchangelogs -i
+       dh_installdocs -i
+       dh_compress -i
+       dh_fixperms -i
+ifeq ($(do_tools_common),true)
+       dh_installinit -p$(cloudpkg) -n --name hv-kvp-daemon
+       dh_installinit -p$(cloudpkg) -n --name hv-vss-daemon
+       dh_installinit -p$(cloudpkg) -n --name hv-fcopy-daemon
+       dh_systemd_enable -p$(cloudpkg)
+       dh_installinit -p$(cloudpkg) -o --name hv-kvp-daemon
+       dh_installinit -p$(cloudpkg) -o --name hv-vss-daemon
+       dh_installinit -p$(cloudpkg) -o --name hv-fcopy-daemon
+       dh_systemd_start -p$(cloudpkg)
+endif
+       dh_installdeb -i
+       $(lockme) dh_gencontrol -i
+       dh_md5sums -i
+       dh_builddeb -i
diff --git a/debian/rules.d/4-checks.mk b/debian/rules.d/4-checks.mk
new file mode 100644 (file)
index 0000000..a431d0b
--- /dev/null
@@ -0,0 +1,27 @@
+# Check ABI for package against last release (if not same abinum)
+abi-check-%: $(stampdir)/stamp-build-%
+       @echo Debug: $@
+       install -d $(abidir)
+       sed -e 's/^\(.\+\)[[:space:]]\+\(.\+\)[[:space:]]\(.\+\)$$/\3 \2 \1/'   \
+               $(builddir)/build-$*/Module.symvers | sort > $(abidir)/$*
+       @perl -f $(DROOT)/scripts/abi-check "$*" "$(prev_abinum)" "$(abinum)" \
+               "$(prev_abidir)" "$(abidir)" "$(skipabi)"
+
+# Check the module list against the last release (always)
+module-check-%: $(stampdir)/stamp-build-%
+       @echo Debug: $@
+       install -d $(abidir)
+       find $(builddir)/build-$*/ -name \*.ko | \
+               sed -e 's/.*\/\([^\/]*\)\.ko/\1/' | sort > $(abidir)/$*.modules
+       @perl -f $(DROOT)/scripts/module-check "$*" \
+               "$(prev_abidir)" "$(abidir)" $(skipmodule)
+
+checks-%: module-check-% abi-check-%
+       @echo Debug: $@
+
+# Check the config against the known options list.
+config-prepare-check-%: $(stampdir)/stamp-prepare-tree-%
+       @echo Debug: $@
+       @perl -f $(DROOT)/scripts/config-check \
+               $(builddir)/build-$*/.config "$(arch)" "$*" "$(commonconfdir)" "$(skipconfig)"
+
diff --git a/debian/rules.d/5-udebs.mk b/debian/rules.d/5-udebs.mk
new file mode 100644 (file)
index 0000000..d6f23fa
--- /dev/null
@@ -0,0 +1,77 @@
+# Do udebs if not disabled in the arch-specific makefile
+binary-udebs: binary-debs
+       @echo Debug: $@
+ifeq ($(disable_d_i),)
+       @$(MAKE) --no-print-directory -f $(DROOT)/rules DEBIAN=$(DEBIAN) \
+               do-binary-udebs
+endif
+
+do-binary-udebs: linux_udeb_name=$(shell if echo $(src_pkg_name)|egrep -q '(linux-lts|linux-hwe)'; then echo $(src_pkg_name); else echo linux; fi)
+do-binary-udebs: debian/control
+       @echo Debug: $@
+       dh_testdir
+       dh_testroot
+
+       # unpack the kernels into a temporary directory
+       mkdir -p debian/d-i-${arch}
+
+       imagelist=$$(cat $(CURDIR)/$(DEBIAN)/d-i/kernel-versions | grep ^${arch} | gawk '{print $$3}') && \
+       for f in $$imagelist; do \
+         i=$(release)-$(abinum)-$$f; \
+         dpkg -x $$(ls ../linux-image-$$i\_$(release)-$(revision)_${arch}.deb) \
+               debian/d-i-${arch}; \
+         if [ -f ../linux-image-extra-$$i\_$(release)-$(revision)_${arch}.deb ] ; then \
+           dpkg -x ../linux-image-extra-$$i\_$(release)-$(revision)_${arch}.deb \
+                 debian/d-i-${arch}; \
+         fi; \
+         /sbin/depmod -b debian/d-i-${arch} $$i; \
+       done
+
+       # kernel-wedge will error if no modules unless this is touched
+       touch $(DEBIAN)/d-i/no-modules
+
+       touch $(CURDIR)/$(DEBIAN)/d-i/ignore-dups
+       export KW_DEFCONFIG_DIR=$(CURDIR)/$(DEBIAN)/d-i && \
+       export KW_CONFIG_DIR=$(CURDIR)/$(DEBIAN)/d-i && \
+       export SOURCEDIR=$(CURDIR)/debian/d-i-${arch} && \
+         kernel-wedge install-files $(release)-$(abinum) && \
+         kernel-wedge check
+
+        # Build just the udebs
+       dilist=$$(dh_listpackages -s | grep "\-di$$") && \
+       [ -z "$dilist" ] || \
+       for i in $$dilist; do \
+         dh_fixperms -p$$i; \
+         $(lockme) dh_gencontrol -p$$i; \
+         dh_builddeb -p$$i; \
+       done
+       
+       # Generate the meta-udeb dependancy lists.
+       @gawk '                                                                         \
+               /^Package:/ {                                                           \
+                       package=$$2; flavour=""; parch="" }                             \
+               (/Package-Type: udeb/ && package !~ /^$(linux_udeb_name)-udebs-/) {      \
+                       match(package, "'$(release)'-'$(abinum)'-(.*)-di", bits);       \
+                       flavour = bits[1];                                              \
+               }                                                                       \
+               (/^Architecture:/ && $$0 " " ~ / '$(arch)'/) {                          \
+                       parch=$$0;                                                      \
+               }                                                                       \
+               (flavour != "" && parch != "") {                                        \
+                       udebs[flavour] = udebs[flavour] package ", ";                   \
+                       flavour=""; parch="";                                           \
+               }                                                                       \
+               END {                                                                   \
+                       for (flavour in udebs) {                                        \
+                               package="$(linux_udeb_name)-udebs-" flavour;            \
+                               file="debian/" package ".substvars";                    \
+                               print("udeb:Depends=" udebs[flavour]) > file;           \
+                               metas="'$(builddir)'/udeb-meta-packages";               \
+                               print(package) >metas                                   \
+                       }                                                               \
+               }                                                                       \
+       ' <$(CURDIR)/debian/control
+       @while read i; do \
+               $(lockme) dh_gencontrol -p$$i; \
+               dh_builddeb -p$$i; \
+       done <$(builddir)/udeb-meta-packages
diff --git a/debian/scripts/abi-check b/debian/scripts/abi-check
new file mode 100755 (executable)
index 0000000..c7a02c5
--- /dev/null
@@ -0,0 +1,210 @@
+#!/usr/bin/perl -w
+
+my $flavour = shift;
+my $prev_abinum = shift;
+my $abinum = shift;
+my $prev_abidir = shift;
+my $abidir = shift;
+my $skipabi = shift;
+
+my $fail_exit = 1;
+my $EE = "EE:";
+my $errors = 0;
+my $abiskip = 0;
+
+my $count;
+
+print "II: Checking ABI for $flavour...\n";
+
+if (-f "$prev_abidir/ignore"
+    or -f "$prev_abidir/$flavour.ignore" or "$skipabi" eq "true") {
+       print "WW: Explicitly asked to ignore ABI, running in no-fail mode\n";
+       $fail_exit = 0;
+       $abiskip = 1;
+       $EE = "WW:";
+}
+
+if ($prev_abinum != $abinum) {
+       print "II: Different ABI's, running in no-fail mode\n";
+       $fail_exit = 0;
+       $EE = "WW:";
+}
+
+if (not -f "$abidir/$flavour" or not -f "$prev_abidir/$flavour") {
+       print "EE: Previous or current ABI file missing!\n";
+       print "    $abidir/$flavour\n" if not -f "$abidir/$flavour";
+       print "    $prev_abidir/$flavour\n" if not -f "$prev_abidir/$flavour";
+
+       # Exit if the ABI files are missing, but return status based on whether
+       # skip ABI was indicated.
+       if ("$abiskip" eq "1") {
+               exit(0);
+       } else {
+               exit(1);
+       }
+}
+
+my %symbols;
+my %symbols_ignore;
+my %modules_ignore;
+my %module_syms;
+
+# See if we have any ignores
+my $ignore = 0;
+print "    Reading symbols/modules to ignore...";
+
+for $file ("$prev_abidir/../blacklist", "$prev_abidir/../../perm-blacklist") {
+       if (-f $file) {
+               open(IGNORE, "< $file") or
+                       die "Could not open $file";
+               while (<IGNORE>) {
+                       chomp;
+                       if ($_ =~ m/M: (.*)/) {
+                               $modules_ignore{$1} = 1;
+                       } else {
+                               $symbols_ignore{$_} = 1;
+                       }
+                       $ignore++;
+               }
+               close(IGNORE);
+       }
+}
+print "read $ignore symbols/modules.\n";
+
+sub is_ignored($$) {
+       my ($mod, $sym) = @_;
+
+       die "Missing module name in is_ignored()" if not defined($mod);
+       die "Missing symbol name in is_ignored()" if not defined($sym);
+
+       if (defined($symbols_ignore{$sym}) or defined($modules_ignore{$mod})) {
+               return 1;
+       }
+       return 0;
+}
+
+# Read new syms first
+print "    Reading new symbols ($abinum)...";
+$count = 0;
+open(NEW, "< $abidir/$flavour") or
+       die "Could not open $abidir/$flavour";
+while (<NEW>) {
+       chomp;
+       m/^(\S+)\s(.+)\s(0x[0-9a-f]+)\s(.+)$/;
+       $symbols{$4}{'type'} = $1;
+       $symbols{$4}{'loc'} = $2;
+       $symbols{$4}{'hash'} = $3;
+       $module_syms{$2} = 0;
+       $count++;
+}
+close(NEW);
+print "read $count symbols.\n";
+
+# Now the old symbols, checking for missing ones
+print "    Reading old symbols ($prev_abinum)...";
+$count = 0;
+open(OLD, "< $prev_abidir/$flavour") or
+       die "Could not open $prev_abidir/$flavour";
+while (<OLD>) {
+       chomp;
+       m/^(\S+)\s(.+)\s(0x[0-9a-f]+)\s(.+)$/;
+       $symbols{$4}{'old_type'} = $1;
+       $symbols{$4}{'old_loc'} = $2;
+       $symbols{$4}{'old_hash'} = $3;
+       $count++;
+}
+close(OLD);
+
+print "read $count symbols.\n";
+
+print "II: Checking for missing symbols in new ABI...";
+$count = 0;
+foreach $sym (keys(%symbols)) {
+       if (!defined($symbols{$sym}{'type'})) {
+               print "\n" if not $count;
+               printf("    MISS : %s%s\n", $sym,
+                       is_ignored($symbols{$sym}{'old_loc'}, $sym) ? " (ignored)" : "");
+               $count++ if !is_ignored($symbols{$sym}{'old_loc'}, $sym);
+       }
+}
+print "    " if $count;
+print "found $count missing symbols\n";
+if ($count) {
+       print "$EE Symbols gone missing (what did you do!?!)\n";
+       $errors++;
+}
+
+
+print "II: Checking for new symbols in new ABI...";
+$count = 0;
+foreach $sym (keys(%symbols)) {
+       if (!defined($symbols{$sym}{'old_type'})) {
+               print "\n" if not $count;
+               print "    NEW : $sym\n";
+               $count++;
+       }
+}
+print "    " if $count;
+print "found $count new symbols\n";
+if ($count and $prev_abinum == $abinum) {
+       print "WW: Found new symbols within same ABI. Not recommended\n";
+}
+
+print "II: Checking for changes to ABI...\n";
+$count = 0;
+my $moved = 0;
+my $changed_type = 0;
+my $changed_hash = 0;
+foreach $sym (keys(%symbols)) {
+       if (!defined($symbols{$sym}{'old_type'}) or
+           !defined($symbols{$sym}{'type'})) {
+               next;
+       }
+
+       # Changes in location don't hurt us, but log it anyway
+       if ($symbols{$sym}{'loc'} ne $symbols{$sym}{'old_loc'}) {
+               printf("    MOVE : %-40s : %s => %s\n", $sym, $symbols{$sym}{'old_loc'},
+                       $symbols{$sym}{'loc'});
+               $moved++;
+       }
+
+       # Changes to export type are only bad if new type isn't
+       # EXPORT_SYMBOL. Changing things to GPL are bad.
+       if ($symbols{$sym}{'type'} ne $symbols{$sym}{'old_type'}) {
+               printf("    TYPE : %-40s : %s => %s%s\n", $sym, $symbols{$sym}{'old_type'}.
+                       $symbols{$sym}{'type'}, is_ignored($symbols{$sym}{'loc'}, $sym)
+                       ? " (ignored)" : "");
+               $changed_type++ if $symbols{$sym}{'type'} ne "EXPORT_SYMBOL"
+                       and !is_ignored($symbols{$sym}{'loc'}, $sym);
+       }
+
+       # Changes to the hash are always bad
+       if ($symbols{$sym}{'hash'} ne $symbols{$sym}{'old_hash'}) {
+               printf("    HASH : %-40s : %s => %s%s\n", $sym, $symbols{$sym}{'old_hash'},
+                       $symbols{$sym}{'hash'}, is_ignored($symbols{$sym}{'loc'}, $sym)
+                       ? " (ignored)" : "");
+               $changed_hash++ if !is_ignored($symbols{$sym}{'loc'}, $sym);
+               $module_syms{$symbols{$sym}{'loc'}}++;
+       }
+}
+
+print "WW: $moved symbols changed location\n" if $moved;
+print "$EE $changed_type symbols changed export type and weren't ignored\n" if $changed_type;
+print "$EE $changed_hash symbols changed hash and weren't ignored\n" if $changed_hash;
+
+$errors++ if $changed_hash or $changed_type;
+if ($changed_hash) {
+       print "II: Module hash change summary...\n";
+       foreach $mod (sort { $module_syms{$b} <=> $module_syms{$a} } keys %module_syms) {
+               next if ! $module_syms{$mod};
+               printf("    %-40s: %d\n", $mod, $module_syms{$mod});
+       }
+}
+
+print "II: Done\n";
+
+if ($errors) {
+       exit($fail_exit);
+} else {
+       exit(0);
+}
diff --git a/debian/scripts/config-check b/debian/scripts/config-check
new file mode 100755 (executable)
index 0000000..224be08
--- /dev/null
@@ -0,0 +1,121 @@
+#!/usr/bin/perl
+#
+# check-config -- check the current config for issues
+#
+use strict;
+
+my $P = 'check-config';
+
+my $test = -1;
+if ($ARGV[0] eq '--test') {
+       $test = $ARGV[1] + 0;
+} elsif ($#ARGV != 4) {
+       die "Usage: $P <config> <arch> <flavour> <commonconfig> <warn-only>\n";
+}
+
+my ($config, $arch, $flavour, $commonconfig, $warn_only) = @ARGV;
+
+my %values = ();
+
+# If we are in overridden then still perform the checks and emit the messages
+# but do not return failure.  Those items marked FATAL will alway trigger
+# failure.
+my $fail_exit = 1;
+$fail_exit = 0 if ($warn_only eq 'true' || $warn_only eq '1');
+my $exit_val = 0;
+
+# Load up the current configuration values -- FATAL if this fails
+print "$P: $config: loading config\n";
+open(CONFIG, "<$config") || die "$P: $config: open failed -- $! -- aborting\n";
+while (<CONFIG>) {
+       # Pull out values.
+       /^#*\s*(CONFIG_\w+)[\s=](.*)$/ or next;
+       if ($2 eq 'is not set') {
+               $values{$1} = 'n';
+       } else {
+               $values{$1} = $2;
+       }
+}
+close(CONFIG);
+
+# ANNOTATIONS: check any annotations marked for enforcement
+my $pass = 0;
+my $total = 0;
+my $annotations = "$commonconfig/annotations";
+my ($config, $value, $options, $option, $value, $check, $policy);
+print "$P: $annotations loading annotations\n";
+my %annot;
+my $form = 1;
+open(ANNOTATIONS, "<$annotations") || die "$P: $annotations: open failed -- $! -- aborting\n";
+while (<ANNOTATIONS>) {
+       if (/^# FORMAT: (\S+)/) {
+               die "$P: $1: unknown annotations format\n" if ($1 != 2);
+               $form = $1;
+       }
+
+       /^#/ && next;
+       chomp;
+       /^$/ && next;
+
+       /^CONFIG_/ || next;
+
+       if ($form == 1) {
+               ($config, $value, $options) = split(' ', $_, 3);
+       } elsif ($form == 2) {
+               ($config, $options) = split(' ', $_, 2);
+       }
+
+       $annot{$config} = $annot{$config} . ' ' . $options;
+}
+close(ANNOTATIONS);
+
+my $config;
+for $config (keys %annot) {
+       $check = 0;
+       $options = $annot{$config};
+
+       $policy = undef;
+       while ($options =~ /\s*(\S+)<(.*?)?>/g) {
+               ($option, $value) = ($1, $2);
+
+               if ($option eq 'mark' && $value eq 'ENFORCED') {
+                       $check = 1;
+
+               } elsif ($option eq 'policy') {
+                       if ($value =~ /^{/) {
+                               $value =~ s/:/=>/g;
+                               $policy = eval($value);
+                               warn "$config: $@" if ($@);
+                       } else {
+                               $policy = undef;
+                       }
+               }
+       }
+       if ($check == 1 && !defined($policy)) {
+               print "$P: INVALID POLICY (use policy<{...}>) $config$options\n";
+               $total++;
+               $check = 0;
+       }
+       if ($check) {
+               my $is = '-';
+               $is = $values{$config} if (defined $values{$config});
+
+               my $value = '-';
+               for my $which ("$arch-$flavour", "$arch-*", "*-$flavour", "$arch", "*") {
+                       if (defined $policy->{$which}) {
+                               $value = $policy->{$which};
+                               last;
+                       }
+               }
+               if ($is eq $value) {
+                       $pass++;
+               } else {
+                       print "$P: FAIL ($is != $value): $config$options\n";
+                       $exit_val = $fail_exit;
+               }
+               $total++;
+       }
+}
+
+print "$P: $pass/$total checks passed -- exit $exit_val\n";
+exit $exit_val;
diff --git a/debian/scripts/control-create b/debian/scripts/control-create
new file mode 100755 (executable)
index 0000000..f8ee9a2
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+. debian/debian.env
+
+vars=$1
+
+. $vars
+
+if [ "$is_sub" = "" ]; then
+       flavour=$(basename $vars | sed 's/.*\.//')
+       stub=${DEBIAN}/control.d/flavour-control.stub
+else
+       flavour=$(basename $vars .vars)
+       stub=${DEBIAN}/sub-flavours/control.stub
+fi
+
+cat $stub | grep -v '^#' | sed                 \
+       -e "s#FLAVOUR#$flavour#g"               \
+       -e "s#DESC#$desc#g"                     \
+       -e "s#ARCH#$arch#g"                     \
+       -e "s#SUPPORTED#$supported#g"           \
+       -e "s#TARGET#$target#g"                 \
+       -e "s#BOOTLOADER#$bootloader#g"         \
+       -e "s#=PROVIDES=#$provides#g"           \
+       -e "s#=CONFLICTS=#$conflicts#g"
diff --git a/debian/scripts/link-headers b/debian/scripts/link-headers
new file mode 100755 (executable)
index 0000000..fb42dbd
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/bash -e
+
+. debian/debian.env
+
+hdrdir="$1"
+symdir="$2"
+flavour="$3"
+
+echo "Symlinking and copying headers for $flavour..."
+
+excludes="( -path ./debian -prune -o -path ./${DEBIAN} -prune -o -path ./.git ) -prune -o"
+
+(
+find . $excludes  -type f \
+       \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
+       -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) -print
+find ./include ./scripts -name .gitignore -prune -o -type f -print
+find ./include -mindepth 1 -maxdepth 1 $excludes -type d -print
+) | (
+while read file; do
+       dir=$file
+       lastdir=$file
+
+       if [ -e "$hdrdir/$file" -o -L "$hdrdir/$file" ]; then
+               continue
+       fi
+
+       while [ ! -e "$hdrdir/$dir" -a ! -L "$hdrdir/$dir" ]; do
+               lastdir=$dir
+               dir=`dirname $dir`
+       done
+       # If the last item to exist is a symlink we assume all is good
+       if [ ! -L "$hdrdir/$dir" ]; then
+               # Turns things like "./foo" into "../"
+               deref="`echo -n $lastdir | sed -e 's/^\.//' -e's,/[^/]*,../,g'`"
+               item="`echo -n $lastdir | sed -e 's/^\.\///'`"
+               ln -s $deref$symdir/$item $hdrdir/$item
+       fi
+done
+)
+
+exit
diff --git a/debian/scripts/misc/find-obsolete-firmware b/debian/scripts/misc/find-obsolete-firmware
new file mode 100755 (executable)
index 0000000..97a1f30
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/bash
+#
+# Find all duplicate or obsolete firmware that is being carried
+# in the kernel firmware directory. Compare these files against
+# the linux-firmware package for the approriate release. For example,
+# assuming this is raring, then compare the kernel firmware files
+# against the raring branch of linux-firmware.
+#
+# Example: $0 ~/ubuntu/linux-firmware-raring
+
+USEAGE="$0 LINUX-FIRMWARE"
+
+. debian/debian.env
+
+NFWINFO="`find $DEBIAN -name fwinfo|wc -l`"
+if [ ! "$NFWINFO" = "1" ]
+then
+       echo Your repo is hosed. There can only be one fwinfo file.
+       find $DEBIAN -name fwinfo
+       exit 1
+fi
+
+FWINFO="`pwd`/`find $DEBIAN -name fwinfo`"
+
+if [ "$1" = "" ]
+then
+       echo $USEAGE
+       exit 1
+fi
+FW="$1"
+
+if [ ! -f $FW/WHENCE ]
+then
+       echo Bogus linux-firmware directory
+       exit 1
+fi
+if ! egrep -q "^firmware:" $FWINFO
+then
+       echo Bogus firmware info file
+       exit 1
+fi
+
+#
+# Prepare the tree and make firmware.
+#
+TEE="tee -a"
+LO=`pwd`/firmware.txt
+LF=`pwd`/lib/firmware
+rm -rf debian/build $LF $LO
+fakeroot debian/rules clean prepare-generic
+cp debian/build/build-generic/.config .
+mkdir -p $LF
+make firmware_install INSTALL_MOD_PATH=`pwd`
+
+(cd $LF
+find . -type f | while read f
+do
+       BN="`basename $f`"
+
+       if ! grep -q $BN $FWINFO
+       then
+               echo "Unused firmware: $f" | $TEE $LO
+       else
+               if [ -f $FW/$f ]
+               then
+                       if ! cmp $FW/$f $f
+                       then
+                               echo "$f differs" | $TEE $LO
+                       else
+                               echo "$f is duplicated" | $TEE $LO
+                       fi
+               else
+                       echo "$f does not exist in $FW" | $TEE $LO
+               fi
+       fi
+done)
+
+#
+# Check for firmware files referenced by the kernel
+# that do not exist in either location.
+#
+cat $FWINFO | while read fwi f
+do
+       if [ -s lib/firmware/$f ] || [ -s $FW/$f ]
+       then
+               continue
+       else
+               echo "Missing firmware $f" | $TEE $LO
+       fi
+done
+
diff --git a/debian/scripts/misc/fw-to-ihex.sh b/debian/scripts/misc/fw-to-ihex.sh
new file mode 100755 (executable)
index 0000000..a63fe67
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+F=$1
+if [ "$F" = "" ]
+then
+       echo You must supply a firmware file.
+       exit 1
+fi
+
+echo "unsigned char d[] = {" > $F.c
+hexdump -v -e '"\t" 8/1 "0x%02x, " "\n"' $F >> $F.c
+echo "};" >> $F.c
+sed -i 's/0x .*$//' $F.c
+
+O="`dirname $F`/`basename $F`.o"
+gcc -o $O -c $F.c
+objcopy -Oihex $F.o $F.ihex
+
diff --git a/debian/scripts/misc/gen-auto-reconstruct b/debian/scripts/misc/gen-auto-reconstruct
new file mode 100755 (executable)
index 0000000..a76e341
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+if [ "$#" -ne 3 ]; then
+       echo "Usage: $0 <orig tag>|<base release> <reconstruct> <options>" 1>&2
+       exit 1
+fi
+tag="$1"
+reconstruct="$2"
+options="$3"
+
+case "$tag" in
+v*)    ;;
+*)     tag="v${tag%.*}" ;;
+esac
+
+# Validate the tag.
+count=$( git tag -l "$tag" | wc -l )
+if [ "$count" != 1 ]; then
+       echo "$0: $tag: tag invalid" 1>&2
+       exit 1
+fi
+
+#git ls-tree -r --full-tree HEAD | grep ^120 | \
+#while read mode type blobid name
+
+(
+       # Identify all new symlinks since the proffered tag.
+       echo "# Recreate any symlinks created since the orig."
+       git diff "$tag.." --raw --no-renames | awk '(/^:000000 120000/ && $5 == "A") { print $NF }' | \
+       while read name
+       do
+               link=$( readlink "$name" )
+
+               echo "[ ! -L '$name' ] && ln -sf '$link' '$name'"
+       done
+
+       # Identify all removed files since the proffered tag.
+       echo "# Remove any files deleted from the orig."
+       git diff "$tag.." --raw --no-renames | awk '(/^:/ && $5 == "D") { print $NF }' | \
+       while read name
+       do
+               echo "rm -f '$name'"
+       done
+
+       # All done, make sure this does not complete in error.
+       echo "exit 0"
+) >"$reconstruct"
+
+(
+       # Identify all new symlinks since the proffered tag.
+       echo "# Ignore any symlinks created since the orig which are rebuilt by reconstruct."
+       git diff "$tag.." --raw --no-renames | awk '(/^:000000 120000/ && $5 == "A") { print $NF }' | \
+       while read name
+       do
+               echo "extend-diff-ignore=$name"
+       done
+) >"$options.update"
+
+
+head='^## autoreconstruct -- begin$'
+foot='^## autoreconstruct -- end$'
+sed -i -e "
+       /$head/,/$foot/{
+               /$head/{
+                       p;
+                       r $options.update
+               };
+               /$foot/p;
+               d
+       }
+" "$options"
+rm -f "$options.update"
diff --git a/debian/scripts/misc/get-firmware b/debian/scripts/misc/get-firmware
new file mode 100755 (executable)
index 0000000..b1ed8e6
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+# Find all files in linux-firmware that are new or different since the previous release
+# and copy them into the kernel firmware directory. You should only do this on the
+# backport branch since it would be redundant on the released kernel. It assumed you've
+# unpacked linux-firmware from each release into separate directories.
+#
+# Example: $0 ~/ubuntu/linux-firmware-precise ~/ubuntu/linux-firmware-quantal
+
+if [ "$1" = "" ] || [ "$2" = "" ] || [ ! -f $1/WHENCE ] || [ ! -f $2/WHENCE ]
+then
+       echo You must supply 2 firmware directories.
+       exit 1
+fi
+
+if [ ! -f debian/debian.env ]
+then
+       echo You must run this script from the root of the repo
+       exit 1
+fi
+. debian/debian.env
+
+NFWINFO="`find $DEBIAN -name fwinfo|wc -l`"
+if [ ! "$NFWINFO" = "1" ]
+then
+       echo Your repo is hosed. There can only be one fwinfo file.
+       find $DEBIAN -name fwinfo
+       exit 1
+fi
+
+FWINFO="`pwd`/`find $DEBIAN -name fwinfo`"
+
+CDIR=`pwd`
+OFW=$1
+NFW=$2
+
+cd $NFW
+#
+# Find all files in $NFW that are new or different from $1
+#
+(find . -type f | egrep -v "debian|git|LICEN|WHEN|READ|Make|configure" | sed 's;\./;;' | \
+while read f
+do
+       if grep -q $f $FWINFO
+       then
+               if [ ! -f $OFW/$f ]
+               then
+                       echo $f
+               elif ! cmp $f $OFW/$f > /dev/null
+               then
+                       echo $f
+               fi
+       fi
+done) |\
+while read f
+do
+       mkdir -p $CDIR/firmware/`dirname $f`
+       if [ ! -f $CDIR/firmware/`dirname $f`/`basename $f`.ihex ]
+       then
+               cp -v $f $CDIR/firmware/`dirname $f`
+       fi
+done
diff --git a/debian/scripts/misc/getabis b/debian/scripts/misc/getabis
new file mode 100755 (executable)
index 0000000..2aad5dd
--- /dev/null
@@ -0,0 +1,135 @@
+#!/bin/bash
+
+if [ "$#" != "2" ]; then
+       echo "Usage: $0 <release> <revision>" 1>&2
+       exit 1
+fi
+
+if [ "$DEBIAN" = "" ]; then
+       . debian/debian.env
+fi
+
+ver=$1
+revision=$2
+abi=$(echo $revision | sed -r -e 's/([^\+~]*)\.[^\.]+(~.*)?(\+.*)?$/\1/')
+
+verabi=$ver-$abi
+verfull=$ver-$revision
+
+WGET="wget --tries=1 --timeout=10 --quiet -c"
+
+abidir="`pwd`/$DEBIAN/abi/$verfull"
+tmpdir="`pwd`/abi-tmp-$verfull"
+origdir="`pwd`"
+fwinfo=$abidir/fwinfo
+
+test -d $tmpdir || mkdir $tmpdir
+
+package_prefixes() {
+       __package_prefixes="$@"
+}
+
+getall() {
+       arch=$1
+       shift
+
+       mkdir -p $abidir/$arch
+
+       for sub in $@; do
+               if [ -f $abidir/$arch/$sub ]; then
+                       echo "Exists: $sub"
+                       continue
+               fi
+               echo -n "Fetching $sub($arch)..."
+               prefixes=""
+               filenames=""
+               cd $tmpdir
+               for prefix in $__package_prefixes
+               do
+                       filename=${prefix}-${verabi}-${sub}_${verfull}_${arch}.deb
+                       for r in "${repo_list[@]}"
+                       do
+                               if ! [ -f $filename ]; then
+                                       $WGET $r/$filename
+                               fi
+                               if [ -f $filename ]; then
+                                       prefixes="$prefixes $prefix"
+                                       filenames="$filenames $filename"
+                                       break
+                               fi
+                       done
+               done
+               if [ "$filenames" != "" ]; then
+                       echo -n "extracting$prefixes..."
+                       for filename in $filenames
+                       do
+                               dpkg-deb --extract $filename tmp
+                       done
+                       find tmp -name "*.ko" | while read f; do
+                               modinfo $f | grep ^firmware >> $fwinfo
+                       done
+                       if [ -f tmp/boot/abi-* ]; then
+                               mv tmp/boot/abi-* $abidir/$arch/$sub
+                       else
+                               echo -n "NO ABI FILE..."
+                       fi
+                       (cd tmp; find lib/modules/$verabi-$sub/kernel -name '*.ko') | \
+                               sed -e 's/.*\/\([^\/]*\)\.ko/\1/' | sort > \
+                               $abidir/$arch/$sub.modules
+                       (
+                               cd tmp;
+                               # Prevent exposing some errors when called by python scripts. SIGPIPE seems to get
+                               # exposed when using the `find ...` form of the command.
+                               ko=$(find lib/modules/$verabi-$sub/kernel \
+                                       -name '*.ko' | head -1)
+                               readelf -p .comment "$ko" | gawk '
+                                       ($1 == "[") {
+                                               printf("%s", $3);
+                                               for (n=4; n<=NF; n++) {
+                                                       printf(" %s", $n);
+                                               }
+                                               print ""
+                                       }' | sort -u >$abidir/$arch/$sub.compiler
+                               version=`cat $abidir/$arch/$sub.compiler`
+                               echo -n "$version..."
+                       )
+                       rm -rf tmp $filenames
+                       echo "done."
+               else
+                       echo "FAILED."
+               fi
+               cd $origdir
+       done
+}
+
+# MAIN
+
+# Setup abi directory
+mkdir -p $abidir
+echo $abi > $abidir/abiname
+
+# NOTE: The flavours are hardcoded, because they may have changed from the
+# current build.
+
+__package_prefixes="linux-image"
+
+. $DEBIAN/etc/getabis
+
+# Extract compiler source package version from e.g.:
+#   GCC: (Ubuntu/Linaro 4.8.2-19ubuntu1) 4.8.2
+compilers=`sed 's/^.*(.* \(.*\)).*$/\1/' $abidir/*/*.compiler | sort -u | wc -l`
+if [ "$compilers" != 1 ]; then
+       echo "WARNING: inconsistent compiler versions detected:" 1>&2
+       sort -u $abidir/*/*.compiler | sed 's/^/WARNING:    /' 1>&2
+fi
+
+sort < $fwinfo | uniq > fwinfo.tmp
+mv fwinfo.tmp $fwinfo
+
+rmdir $tmpdir
+
+# If this is running in a git repo, add the new ABI directory, remove the old
+if [ -d ".git" ]; then
+    git add $abidir
+    find $DEBIAN/abi/* -maxdepth 0 -type d | grep -v $verfull | while read f; do git rm -r $f;done
+fi
diff --git a/debian/scripts/misc/git-ubuntu-log b/debian/scripts/misc/git-ubuntu-log
new file mode 100755 (executable)
index 0000000..eee983f
--- /dev/null
@@ -0,0 +1,125 @@
+#!/usr/bin/python3
+
+import os
+import sys
+
+import codecs
+import urllib.request
+import json
+
+import textwrap
+
+sys.stdin = codecs.getreader("utf-8")(sys.stdin.detach())
+sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
+
+entries = []
+def add_entry(entry):
+    if entry and 'ignore' not in entry:
+        if 'bugs' not in entry and 'cves' in entry:
+            for cve in entry['cves']:
+                if cve not in bugs:
+                    bugs.append(cve)
+        entries.append(entry)
+
+# Suck up the git log output and extract the information we need.
+bugs = []
+entry = None
+subject_wait = False
+for line in sys.stdin:
+    if line.startswith('commit '):
+        add_entry(entry)
+        entry = {}
+        subject_wait = True
+
+    elif line.startswith('Author: '):
+        bits = line.strip().split(maxsplit=1)
+        entry['author'] = bits[1]
+
+    elif subject_wait and line.startswith('    '):
+        subject_wait = False
+        entry['subject'] = line.strip()
+
+    elif line.startswith('    BugLink: ') and 'launchpad.net' in line:
+        bits = line.strip().split(maxsplit=1)
+        bits = bits[1].split('/')
+        entry.setdefault('bugs', []).append(bits[-1])
+
+        # Accumulate bug numbers.
+        if bits[-1] not in bugs:
+            bugs.append(bits[-1])
+
+    elif line.startswith('    CVE-'):
+        entry.setdefault('cves', []).append(line.strip())
+
+    elif line.startswith('    Ignore:'):
+        entry['ignore'] = True
+
+add_entry(entry)
+
+entries.reverse()
+
+# Go through the entries and clear out authors for upstream commits.
+for entry in entries:
+    if entry['subject'].startswith('UBUNTU:'):
+        entry['subject'] = entry['subject'][7:].strip()
+    else:
+        del entry['author']
+
+# Lump everything without a bug at the bottom.
+bugs.append('__packaging__')
+bugs.append('__mainline__')
+
+emit_nl = False
+for bug in bugs:
+    if bug == '__packaging__':
+        title = 'Miscellaneous Ubuntu changes'
+    elif bug == '__mainline__':
+        title = 'Miscellaneous upstream changes'
+    elif bug.startswith('CVE-'):
+        title = bug
+    else:
+        bug_info = None
+
+        try:
+            #urllib.request.urlcleanup()
+            request = urllib.request.Request('https://api.launchpad.net/devel/bugs/' + bug)
+            request.add_header('Cache-Control', 'max-age=0')
+            with urllib.request.urlopen(request) as response:
+                data = response.read()
+                bug_info = json.loads(data.decode('utf-8'))
+            
+            title = bug_info['title']
+            if 'description' in bug_info:
+                for line in bug_info['description'].split('\n'):
+                    if line.startswith('Kernel-Description:'):
+                        title = line.split(' ', 1)[1]
+
+        except urllib.error.HTTPError:
+            title = 'INVALID or PRIVATE BUG'
+
+        title += ' (LP###' + bug + ')'
+
+    emit_title = True
+    for entry in entries:
+        if (bug == '__packaging__' and 'bugs' not in entry and 'cves' not in entry and 'author' in entry) or \
+           (bug == '__mainline__' and 'bugs' not in entry and 'cves' not in entry and 'author' not in entry) or \
+           ('bugs' in entry and bug in entry['bugs']) or \
+           ('cves' in entry and bug in entry['cves']):
+            if emit_title:
+                if emit_nl:
+                    print('')
+                emit_nl = True
+
+                title_lines = textwrap.wrap(title, 76)
+                print('  * ' + title_lines[0].replace('LP###', 'LP: #'))
+                for line in title_lines[1:]:
+                    line = line.replace('LP###', 'LP: #')
+                    print('    ' + line)
+
+                emit_title = False
+            title_lines = textwrap.wrap(entry['subject'], 76)
+            print('    - ' + title_lines[0])
+            for line in title_lines[1:]:
+                line = line.replace('LP###', 'LP: #')
+                print('      ' + line)
+
diff --git a/debian/scripts/misc/insert-changes.pl b/debian/scripts/misc/insert-changes.pl
new file mode 100755 (executable)
index 0000000..c820597
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/perl -w
+
+my $debian;
+$droot = $ARGV[0] if (defined $ARGV[0]);
+$droot = 'debian' if (!defined $droot);
+$debian = $ARGV[1] if (defined $ARGV[1]);
+$debian = 'debian.master' if (!defined $debian);
+
+system("make -s -f $droot/rules printchanges > $debian/changes");
+
+open(CHANGELOG, "< $debian/changelog") or die "Cannot open changelog";
+open(CHANGES, "< $debian/changes") or die "Cannot open new changes";
+open(NEW, "> $debian/changelog.new") or die "Cannot open new changelog";
+
+$printed = 0;
+
+while (<CHANGELOG>) {
+       if (/^  CHANGELOG: /) {
+               next if $printed;
+
+               while (<CHANGES>) {
+                       print NEW;
+               }
+
+               $printed = 1;
+       } else {
+               print NEW;
+       }
+}
+
+close(NEW);
+close(CHANGES);
+close(CHANGELOG);
+
+rename("$debian/changelog.new", "$debian/changelog");
+unlink("$debian/changes");
diff --git a/debian/scripts/misc/insert-mainline-changes b/debian/scripts/misc/insert-mainline-changes
new file mode 100755 (executable)
index 0000000..5678b10
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+if ($#ARGV != 2) {
+       warn "Usage: $0 <changelog> <to> <range>\n";
+       die  "       $0 debian.master/changelog v3.2.3 v3.2.2..v3.2.3\n";
+}
+my ($changelog, $to, $range) = @ARGV;
+
+my @changes = ();
+
+push(@changes, "\n");
+push(@changes, "  [ Upstream Kernel Changes ]\n\n");
+push(@changes, "  * rebase to $to\n");
+
+open(LOG, "git log '$range'|") || die "$0: git log failed: - $!\n";
+while (<LOG>) {
+       if (m@BugLink: .*launchpad.net/.*/([0-9]+)\s$@) {
+               push(@changes, "    - LP: #$1\n");
+       }
+}
+close(LOG);
+
+open(CHANGELOG, "< $changelog") or die "Cannot open changelog";
+open(NEW, "> $changelog.new") or die "Cannot open new changelog";
+
+$printed = 3;
+while (<CHANGELOG>) {
+       if (/^  CHANGELOG: /) {
+               $printed--;
+               print NEW;
+               if ($printed == 0) {
+                       print NEW @changes;
+               }
+               next;
+       }
+       print NEW;
+}
+
+close(NEW);
+close(CHANGELOG);
+
+rename("$changelog.new", "$changelog");
diff --git a/debian/scripts/misc/insert-ubuntu-changes b/debian/scripts/misc/insert-ubuntu-changes
new file mode 100755 (executable)
index 0000000..9ede7f3
--- /dev/null
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+if ($#ARGV != 2) {
+       die "Usage: $0 <changelog> <stop at> <start at>\n";
+}
+my ($changelog, $end, $start) = @ARGV;
+
+$end =~ s/.*\.//;
+$start =~ s/.*\.//;
+
+my @changes = ();
+my $output = 0;
+open(CHG, "<debian.master/changelog") ||
+       open(CHG, "<debian/changelog") ||
+       die "$0: debian/changelog: open failed - $!\n";
+while (<CHG>) {
+       if (/^\S+\s+\((.*\.(\d+))\)/) {
+               if ($2 <= $end) {
+                       last;
+               }
+               if ($2 == $start) {
+                       $output = 1;
+               }
+               if ($output) {
+                       push(@changes, "\n  [ Ubuntu: $1 ]\n\n");
+                       next;
+               }
+       }
+       next if ($output == 0);
+
+       next if (/^\s*$/);
+       next if (/^\s--/);
+       next if (/^\s\s[^\*\s]/);
+
+       push(@changes, $_);
+}
+close(CHG);
+
+open(CHANGELOG, "< $changelog") or die "Cannot open changelog";
+open(NEW, "> $changelog.new") or die "Cannot open new changelog";
+
+$printed = 3;
+while (<CHANGELOG>) {
+       if (/^  CHANGELOG: /) {
+               $printed--;
+               print NEW;
+               if ($printed == 0) {
+                       print NEW @changes;
+               }
+               next;
+       }
+       print NEW;
+}
+
+close(NEW);
+close(CHANGELOG);
+
+rename("$changelog.new", "$changelog");
diff --git a/debian/scripts/misc/kernel-wedge-arch.pl b/debian/scripts/misc/kernel-wedge-arch.pl
new file mode 100755 (executable)
index 0000000..4b4fefe
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+#
+# kernel-wedge-arch.pl -- select only specifiers for the supplied arch.
+#
+use strict;
+
+require Dpkg::Control;
+require Dpkg::Deps;
+
+my $fh = \*STDIN;
+
+my @entries;
+
+my $wanted = $ARGV[0];
+
+my $entry;
+while (!eof($fh)) {
+       $entry = Dpkg::Control->new();
+       $entry->parse($fh, '???');
+
+       if ($entry->{'Architecture'} eq $wanted) {
+               print("\n" . $entry);
+       }
+}
+
+close($fh);
diff --git a/debian/scripts/misc/kernelconfig b/debian/scripts/misc/kernelconfig
new file mode 100755 (executable)
index 0000000..ffb6082
--- /dev/null
@@ -0,0 +1,172 @@
+#!/bin/bash
+
+. debian/debian.env
+
+# Script to merge all configs and run 'make silentoldconfig' on it to wade out bad juju.
+# Then split the configs into distro-commmon and flavour-specific parts
+
+# We have to be in the top level kernel source directory
+if [ ! -f MAINTAINERS ] || [ ! -f Makefile ]; then
+       echo "This does not appear to be the kernel source directory." 1>&2
+       exit 1
+fi
+
+mode=${1:?"Usage: $0 [oldconfig|editconfig]"}
+yes=0
+case "$mode" in
+    update*configs)  mode='silentoldconfig' ;;
+    default*configs) mode='oldconfig'; yes=1 ;;
+    edit*configs)    ;; # All is good
+    gen*configs)     mode='genconfigs' ;; # All is good
+    dump*configs)    mode='config'; yes=1 ;;
+    *) echo "$0 called with invalid mode" 1>&2
+       exit 1 ;;
+esac
+kerneldir="`pwd`"
+confdir="$kerneldir/${DEBIAN}/config"
+variant="$2"
+
+. $DEBIAN/etc/kernelconfig
+
+bindir="`pwd`/${DROOT}/scripts/misc"
+common_conf="$confdir/config.common.$family"
+tmpdir=`mktemp -d`
+mkdir "$tmpdir/CONFIGS"
+
+if [ "$mode" = "genconfigs" ]; then
+       keep=1
+       mode="oldconfig"
+       test -d CONFIGS || mkdir CONFIGS
+fi
+
+for arch in $archs; do
+       rm -rf build
+       mkdir build
+
+       # Map debian archs to kernel archs
+       case "$arch" in
+               ppc64|ppc64el)  kernarch="powerpc"      ;;
+               amd64)          kernarch="x86_64"       ;;
+               lpia)           kernarch="x86"          ;;
+               sparc)          kernarch="sparc64"      ;;
+               armel|armhf)    kernarch="arm"          ;;
+               s390x)          kernarch="s390"         ;;
+               *)              kernarch="$arch"        ;;
+       esac
+
+       archconfdir=$confdir/$arch
+       flavourconfigs=$(cd $archconfdir && ls config.flavour.*)
+
+       # Merge configs
+       # We merge config.common.ubuntu + config.common.<arch> +
+       # config.flavour.<flavour>
+
+       for config in $flavourconfigs; do
+               fullconf="$tmpdir/$arch-$config-full"
+               case $config in
+               *)
+                       : >"$fullconf"
+                       if [ -f $common_conf ]; then
+                               cat $common_conf >> "$fullconf"
+                       fi
+                       if [ -f $archconfdir/config.common.$arch ]; then
+                               cat $archconfdir/config.common.$arch >> "$fullconf"
+                       fi
+                       cat "$archconfdir/$config" >>"$fullconf"
+                       if [ -f $confdir/OVERRIDES ]; then
+                               cat $confdir/OVERRIDES >> "$fullconf"
+                       fi
+                       ;;
+               esac
+       done
+
+       for config in $flavourconfigs; do
+               if [ -f $archconfdir/$config ]; then
+                       fullconf="$tmpdir/$arch-$config-full"
+                       cat "$fullconf" > build/.config
+                       # Call oldconfig or menuconfig
+                       case "$mode" in
+                           editconfigs)
+                               # Interactively edit config parameters
+                               while : ; do
+                                       echo -n "Do you want to edit config: $arch/$config? [Y/n] "
+                                       read choice
+                                       
+                                       case "$choice" in
+                                       y* | Y* | "" )
+                                               make O=`pwd`/build ARCH=$kernarch menuconfig
+                                               break ;;
+                                       n* | N* )
+                                               break ;;
+                                       *)
+                                               echo "Entry not valid"
+                                       esac
+                               done
+                               ;;
+                           *)
+                               echo "* Run $mode (yes=$yes) on $arch/$config ..."
+                               if [ "$yes" -eq 1 ]; then
+                                       yes "" | make O=`pwd`/build ARCH=$kernarch "$mode"
+                               else
+                                       make O=`pwd`/build ARCH=$kernarch "$mode"
+                               fi ;;
+                       esac
+                       cat build/.config > $archconfdir/$config
+                       cat build/.config > "$tmpdir/CONFIGS/$arch-$config"
+                       if [ "$keep" = "1" ]; then
+                               cat build/.config > CONFIGS/$arch-$config
+                       fi
+               else
+                       echo "!! Config not found $archconfdir/$config..."
+               fi
+       done
+
+       echo "Running splitconfig.pl for $arch"
+       echo
+
+       # Can we make this more robust by avoiding $tmpdir completely?
+       # This approach was used for now because I didn't want to change
+       # splitconfig.pl
+       (cd $archconfdir; $bindir/splitconfig.pl config.flavour.*; mv config.common \
+        config.common.$arch; cp config.common.$arch $tmpdir)
+done
+
+rm -f $common_conf
+
+# Now run splitconfig.pl on all the config.common.<arch> copied to
+# $tmpdir
+(cd $tmpdir; $bindir/splitconfig.pl *)
+(
+       cd $confdir;
+       rm -f *-full
+       grep -v 'is UNMERGABLE' <$tmpdir/config.common >$common_conf
+       for arch in $archs; do
+               grep -v 'is UNMERGABLE' <$tmpdir/config.common.$arch \
+                       >$arch/config.common.$arch
+       done
+)
+
+echo ""
+echo "Running config-check for all configurations ..."
+echo ""
+fail=0
+for arch in $archs; do
+       archconfdir=$confdir/$arch
+       flavourconfigs=$(cd $archconfdir && ls config.flavour.*)
+       for config in $flavourconfigs; do
+               flavour="${config##*.}"
+               if [ -f $archconfdir/$config ]; then
+                       fullconf="$tmpdir/CONFIGS/$arch-$config"
+                       "$bindir/../config-check" "$fullconf" "$arch" "$flavour" "$confdir" "0" || let "fail=$fail+1"
+               fi
+       done
+done
+
+if [ "$fail" != 0 ]; then
+       echo ""
+       echo "*** ERROR: $fail config-check failures detected"
+       echo ""
+fi
+
+rm -rf build
+
diff --git a/debian/scripts/misc/retag b/debian/scripts/misc/retag
new file mode 100755 (executable)
index 0000000..94cf169
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -w
+
+open(TAGS, "git tag -l |") or die "Could not get list of tags";
+@tags = <TAGS>;
+close(TAGS);
+
+open(LOGS, "git log --pretty=short |") or die "ERROR: Calling git log";
+my $commit = "";
+
+while (<LOGS>) {
+       my $origtag;
+
+       if (m|^commit (.*)$|) {
+               $commit = $1;
+               next;
+       }
+
+       m|\s*UBUNTU: (Ubuntu-2\.6\..*)| or next;
+
+       $tag = $1;
+
+       ($origtag) = grep(/^$tag.orig$/, @tags);
+
+       if (!defined($origtag)) {
+               print "I: Adding original tag for $tag\n";
+               system("git tag -m $tag $tag.orig $tag");
+       }
+
+       print "I: Tagging $tag => $commit\n";
+
+       system("git tag -f -m $tag $tag $commit");
+}
+
+close(LOGS);
diff --git a/debian/scripts/misc/splitconfig.pl b/debian/scripts/misc/splitconfig.pl
new file mode 100755 (executable)
index 0000000..3270ede
--- /dev/null
@@ -0,0 +1,107 @@
+#!/usr/bin/perl -w
+
+%allconfigs = ();
+%common = ();
+
+print "Reading config's ...\n";
+
+for $config (@ARGV) {
+       # Only config.*
+       next if $config !~ /^config\..*/;
+       # Nothing that is disabled, or remnant
+       next if $config =~ /.*\.(default|disabled|stub)$/;
+
+       %{$allconfigs{$config}} = ();
+
+       print "  processing $config ... ";
+
+       open(CONFIG, "< $config");
+
+       while (<CONFIG>) {
+               # Skip comments
+               /^#*\s*CONFIG_(\w+)[\s=](.*)$/ or next;
+
+               ${$allconfigs{$config}}{$1} = $2;
+
+               $common{$1} = $2;
+       }
+
+       close(CONFIG);
+
+       print "done.\n";
+}
+
+print "\n";
+
+print "Merging lists ... \n";
+
+# %options - pointer to flavour config inside the allconfigs array
+for $config (keys(%allconfigs)) {
+       my %options = %{$allconfigs{$config}};
+
+       print "   processing $config ... ";
+
+       for $key (keys(%common)) {
+               next if not defined $common{$key};
+
+               # If we don't have the common option, then it isn't
+               # common. If we do have that option, it must have the same
+               # value.  EXCEPT where this file does not have a value at all
+               # which may safely be merged with any other value; the value
+               # will be elided during recombination of the parts.
+               if (!defined($options{$key})) {
+                       # Its ok really ... let it merge
+               } elsif (not defined($options{$key})) {
+                       undef $common{$key};
+               } elsif ($common{$key} ne $options{$key}) {
+                       undef $common{$key};
+               }
+       }
+
+       print "done.\n";
+}
+
+print "\n";
+
+print "Creating common config ... ";
+
+open(COMMON, "> config.common");
+print COMMON "#\n# Common config options automatically generated by splitconfig.pl\n#\n";
+
+for $key (sort(keys(%common))) {
+       if (not defined $common{$key}) {
+               print COMMON "# CONFIG_$key is UNMERGABLE\n";
+       } elsif ($common{$key} eq "is not set") {
+               print COMMON "# CONFIG_$key is not set\n";
+       } else {
+               print COMMON "CONFIG_$key=$common{$key}\n";
+       }
+}
+close(COMMON);
+
+print "done.\n\n";
+
+print "Creating stub configs ...\n";
+
+for $config (keys(%allconfigs)) {
+       my %options = %{$allconfigs{$config}};
+
+       print "  processing $config ... ";
+
+       open(STUB, "> $config");
+       print STUB "#\n# Config options for $config automatically generated by splitconfig.pl\n#\n";
+
+       for $key (sort(keys(%options))) {
+               next if defined $common{$key};
+
+               if ($options{$key} =~ /^is /) {
+                       print STUB "# CONFIG_$key $options{$key}\n";
+               } else {
+                       print STUB "CONFIG_$key=$options{$key}\n";
+               }
+       }
+
+       close(STUB);
+
+       print "done.\n";
+}
diff --git a/debian/scripts/misc/tristate.sh b/debian/scripts/misc/tristate.sh
new file mode 100755 (executable)
index 0000000..cc170c8
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+#
+# Find config variables that might be able to transition from =y to =m
+#
+# Example: debian/scripts/misc/tristate.sh debian.master/config/config.common.ubuntu
+#
+
+KC=Kconfig.tmp
+rm -f ${KC}
+find .|grep Kconfig | while read f
+do
+       cat $f >> ${KC}
+done
+
+grep =y $1 | sed -e 's/CONFIG_//' -e 's/=y//' | while read c
+do
+       cat <<EOF > tristate.awk
+BEGIN { tristate=0; }
+/^config ${c}\$/ { tristate=1; next; }
+/tristate/ { if (tristate == 1) printf("CONFIG_%s=m\n","${c}"); next; }
+{ if (tristate == 1) exit; }
+EOF
+
+       gawk -f tristate.awk ${KC}
+done
diff --git a/debian/scripts/misc/update-aufs.sh b/debian/scripts/misc/update-aufs.sh
new file mode 100755 (executable)
index 0000000..288b920
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+AUFS=aufs4-standalone
+
+#
+# Before you run this be sure you've removed or reverted the 'UBUNTU: SAUCE: AUFS" patch.
+#
+#
+# Make sure the current working directory is at the top of the
+# linux tree.
+#
+if ! grep PATCHLEVEL Makefile
+then
+       echo "You must run this script from the top of the linux tree"
+       exit 1
+fi
+
+clean=0
+if [ "$#" = 1 ]; then
+       AUFS="$1"
+else
+       clean=1
+       rm -rf ${AUFS}
+       git clone https://github.com/sfjro/aufs4-standalone.git ${AUFS}
+       (cd ${AUFS}; git checkout -b aufs4.x-rcN remotes/origin/aufs4.x-rcN)
+fi
+
+cp ${AUFS}/include/uapi/linux/aufs_type.h include/uapi/linux
+rsync -av ${AUFS}/fs/ fs/
+rsync -av ${AUFS}/Documentation/ Documentation/
+
+PATCHES="${PATCHES} aufs4-kbuild.patch"
+PATCHES="${PATCHES} aufs4-base.patch"
+PATCHES="${PATCHES} aufs4-mmap.patch"
+PATCHES="${PATCHES} aufs4-standalone.patch"
+PATCHES="${PATCHES} aufs4-loopback.patch"
+#PATCHES="${PATCHES} vfs-ino.patch"
+PATCHES="${PATCHES} tmpfs-idr.patch"
+
+for i in ${PATCHES}
+do
+       patch -p1 < ${AUFS}/$i
+done
+
+[ "$clean" = 1 ] && rm -rf ${AUFS}
+git add mm/prfile.c
+git add -u
+find . -name "*.orig" | xargs rm
+find . |grep aufs | xargs git add
+git commit -s -m"UBUNTU: SAUCE: AUFS"
diff --git a/debian/scripts/misc/update-zfs.sh b/debian/scripts/misc/update-zfs.sh
new file mode 100755 (executable)
index 0000000..b1a95cb
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+# Update spl/zfs from the Ubuntu archive. You will have to manually check
+# to see if the version has been updated.
+#
+SPL_MAJOR_VER=${_SPL_MAJOR_VER:-0.6.5.4}
+SPL_MINOR_VER=${_SPL_MINOR_VER:-0ubuntu1}
+SPL_DKMS=${_SPL_DKMS:-http://archive.ubuntu.com/ubuntu/pool/universe/s/spl-linux/spl-dkms_${SPL_MAJOR_VER}-${SPL_MINOR_VER}_amd64.deb}
+
+ZFS_MAJOR_VER=${_ZFS_MAJOR_VER:-0.6.5.4}
+ZFS_MINOR_VER=${_ZFS_MINOR_VER:-0ubuntu1}
+ZFS_DKMS=${_ZFS_DKMS:-http://archive.ubuntu.com/ubuntu/pool/universe/z/zfs-linux/zfs-dkms_${ZFS_MAJOR_VER}-${ZFS_MINOR_VER}_amd64.deb}
+
+function update_from_archive {
+
+       URL=$1
+       DEST_DIR=$2
+       VER=$3
+
+       rm -rf ${DEST_DIR}.tmp
+       wget -O ${DEST_DIR}.deb ${URL}
+       dpkg -x ${DEST_DIR}.deb ${DEST_DIR}.tmp
+       mkdir -p ${DEST_DIR}
+       rsync -aL --delete ${DEST_DIR}.tmp/usr/src/${DEST_DIR}-${VER}*/ ${DEST_DIR}/
+       rm -rf ${DEST_DIR}.deb ${DEST_DIR}.tmp
+       find ${DEST_DIR} -type f | while read f;do git add -f $f;done
+}
+
+update_from_archive ${SPL_DKMS} spl ${SPL_MAJOR_VER}
+update_from_archive ${ZFS_DKMS} zfs ${ZFS_MAJOR_VER}
+
+git add -u
+git commit -s -m"UBUNTU: SAUCE: (noup) Update spl to ${SPL_MAJOR_VER}-${SPL_MINOR_VER}, zfs to ${ZFS_MAJOR_VER}-${ZFS_MINOR_VER}"
diff --git a/debian/scripts/module-check b/debian/scripts/module-check
new file mode 100755 (executable)
index 0000000..c754ea3
--- /dev/null
@@ -0,0 +1,120 @@
+#!/usr/bin/perl -w
+
+$flavour = shift;
+$prev_abidir = shift;
+$abidir = shift;
+$skipmodule = shift;
+
+print "II: Checking modules for $flavour...";
+
+if (-f "$prev_abidir/ignore.modules"
+    or -f "$prev_abidir/$flavour.ignore.modules") {
+       print "explicitly ignoring modules\n";
+       exit(0);
+}
+
+if (not -f "$abidir/$flavour.modules" or not -f
+    "$prev_abidir/$flavour.modules") {
+       print "previous or current modules file missing!\n";
+       print "   $abidir/$flavour.modules\n";
+       print "   $prev_abidir/$flavour.modules\n";
+       if (defined($skipmodule)) {
+               exit(0);
+       } else {
+               exit(1);
+       }
+}
+
+print "\n";
+
+my %modules;
+my %modules_ignore;
+my $missing = 0;
+my $new = 0;
+my $errors = 0;
+
+# See if we have any ignores
+if (-f "$prev_abidir/../modules.ignore") {
+       my $ignore = 0;
+       open(IGNORE, "< $prev_abidir/../modules.ignore") or
+               die "Could not open $prev_abidir/../modules.ignore";
+       print "   reading modules to ignore...";
+       while (<IGNORE>) {
+               chomp;
+               next if /\s*#/;
+               $modules_ignore{$_} = 1;
+               $ignore++;
+       }
+       close(IGNORE);
+       print "read $ignore modules.\n";
+}
+
+# Read new modules first
+print "   reading new modules...";
+$new_count = 0;
+open(NEW, "< $abidir/$flavour.modules") or
+       die "Could not open $abidir/$flavour.modules";
+while (<NEW>) {
+       chomp;
+       $modules{$_} = 1;
+       $new_count++;
+}
+close(NEW);
+print "read $new_count modules.\n";
+
+# Now the old modules, checking for missing ones
+print "   reading old modules...";
+$old_count = 0;
+open(OLD, "< $prev_abidir/$flavour.modules") or
+       die "Could not open $prev_abidir/$flavour.modules";
+while (<OLD>) {
+       chomp;
+       if (not defined($modules{$_})) {
+               print "\n" if not $missing;
+               $missing++;
+               if (not defined($modules_ignore{$_})) {
+                       print "      MISS: $_\n";
+                       $errors++;
+               } else {
+                       print "      MISS: $_ (ignored)\n";
+               }
+       } else {
+               $modules{$_}++;
+       }
+       $old_count++;
+}
+close(OLD);
+# Check for new modules
+foreach $mod (keys(%modules)) {
+       if ($modules{$mod} < 2) {
+               print "\n" if not $missing and not $new;
+               print "      NEW : $mod\n";
+               $new++;
+       }
+}
+if ($new or $missing) {
+       print "      read $old_count modules : new($new)  missing($missing)\n";
+} else {
+       print "read $old_count modules.\n";
+}
+
+
+# Let's see where we stand...
+if ($errors) {
+       if (defined($skipmodule)) {
+               print "WW: Explicitly asked to ignore failures (probably not good)\n";
+       } else {
+               print "EE: Missing modules (start begging for mercy)\n";
+               exit 1
+       }
+}
+
+if ($new) {
+       print "II: New modules (you've been busy, wipe the poop off your nose)\n";
+} else {
+       print "II: No new modules (hope you're happy, slacker)\n";
+}
+
+print "II: Done\n";
+
+exit(0);
diff --git a/debian/scripts/module-inclusion b/debian/scripts/module-inclusion
new file mode 100755 (executable)
index 0000000..ccec0f2
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/bash
+
+#
+# Build a new directory of modules based on an inclusion list.
+# The includsion list format must be a bash regular expression.
+#
+# usage: $0 ROOT INCLUSION_LIST
+# example: $0 \
+#       debian/build/build-virtual-ALL debian/build/build-virtual \
+#      debian.master/control.d/virtual.inclusion-list \
+#      virtual.depmap
+master=0
+if [ "$1" = "--master" ]; then
+       master=1
+       shift
+fi
+
+ROOT=$1
+NROOT=$2
+ILIST=$3
+DEPMAP=$4
+
+tmp="/tmp/module-inclusion.$$"
+
+#
+# Prep a destination directory.
+#
+mkdir -p ${NROOT}
+
+{
+       # Copy over the framework into the master package.
+       if  [ "$master" -eq 1 ]; then
+               (cd ${ROOT}; find . ! -name "*.ko" -type f)
+       fi
+
+       # Copy over modules by name or pattern.
+       while read -r i
+       do
+               #
+               # 'find' blurts a warning if it cannot find any ko files.
+               #
+               case "$i" in
+               \!*)
+                       (cd ${ROOT}; ${i#!} || true)
+                       ;;
+               *\**)
+                       (cd ${ROOT}; eval find "${i}" -name "*.ko" || true)
+                       ;;
+               *)
+                       echo "$i"
+                       ;;
+               esac
+       done <"${ILIST}"
+} >"$tmp"
+
+# Copy over the listed modules.
+while read i
+do
+       # If this is already moved over, all is good.
+       if [ -f "${NROOT}/$i" ]; then
+               :
+
+       # If present in the source, moved it over.
+       elif [ -f "${ROOT}/$i" ]; then
+               mkdir -p "${NROOT}/`dirname $i`"
+               mv "${ROOT}/$i" "${NROOT}/$i"
+
+       # Otherwise, it is missing.
+       else
+               echo "Warning: Could not find ${ROOT}/$i" 1>&2
+       fi
+done <"$tmp"
+
+# Copy over any dependancies, note if those are missing
+# we know they are in a pre-requisite package as they must
+# have existed at depmap generation time, and can only have
+# moved into a package.
+let n=0 || true
+while [ -s "$tmp" ]
+do
+       let n="$n+1" || true
+       [ "$n" = "20" ] && break || true
+
+       echo "NOTE: pass $n: dependency scan" 1>&2
+
+       while read i
+       do
+               grep "^$i " "$DEPMAP" | \
+               while read m d
+               do
+                       if [ -f "${ROOT}/$d" ]; then
+                               echo "NOTE: pass $n: ${i} pulls in ${d}" 1>&2
+                               echo "$d"
+                               mkdir -p "${NROOT}/`dirname $d`"
+                               mv "${ROOT}/$d" "${NROOT}/$d"
+                       fi
+               done
+       done <"$tmp" >"$tmp.new"
+       mv -f "$tmp.new" "$tmp"
+done
+
+rm -f "$tmp"
+
+exit 0
diff --git a/debian/scripts/sub-flavour b/debian/scripts/sub-flavour
new file mode 100644 (file)
index 0000000..0100493
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+. debian/debian.env
+
+echo "SUB_PROCESS $FROM => $TO"
+
+export from_pkg="linux-image-$ABI_RELEASE-$FROM"
+export to_pkg="linux-image-$ABI_RELEASE-$TO"
+
+from_moddir="debian/$from_pkg/lib/modules/$ABI_RELEASE-$FROM"
+to_moddir="debian/$to_pkg/lib/modules/$ABI_RELEASE-$FROM"
+
+install -d "debian/$to_pkg/boot"
+install -m644 debian/$from_pkg/boot/config-$ABI_RELEASE-$FROM \
+       debian/$to_pkg/boot/
+install -m600 debian/$from_pkg/boot/{vmlinuz,System.map}-$ABI_RELEASE-$FROM \
+       debian/$to_pkg/boot/
+
+#
+# Print some warnings if there are files in the sub-flavours list
+# that do not actually exist.
+#
+cat ${DEBIAN}/sub-flavours/$TO.list | while read line
+do
+(
+       cd debian/$from_pkg/lib/modules/$ABI_RELEASE-$FROM/kernel;
+       #
+       # If its a wildcard, then check that there are files that match.
+       #
+       if echo "$line" | grep '\*' > /dev/null
+       then
+               if [ `eval find "$line" -name '*.ko' 2>/dev/null|wc -l` -lt 1 ]
+               then
+                       echo SUB_INST Warning - No files in $line
+               fi
+       #
+       # Else it should be a single file reference.
+       #
+       elif [ ! -f "$line" ]
+       then
+               echo SUB_INST Warning - could not find "$line"
+       fi
+)
+done
+
+cat ${DEBIAN}/sub-flavours/$TO.list | while read line; do
+       (
+       cd debian/$from_pkg/lib/modules/$ABI_RELEASE-$FROM/kernel;
+       if echo "$line" | grep '\*' > /dev/null
+       then
+               eval find "$line" -name '*.ko' 2>/dev/null || true
+       elif [ -f "$line" ]
+       then
+               echo "$line"
+       fi
+       );
+done | while read mod; do
+       echo "SUB_INST checking: $mod"
+       fromdir="/lib/modules/$ABI_RELEASE-$FROM/"
+       egrep "^($fromdir)?kernel/$mod:" \
+               $from_moddir/modules.dep | sed -e "s|^$fromdir||" -e 's/://' -e 's/ /\n/g' | \
+       while read m; do
+               m="${fromdir}$m"
+               test -f debian/$to_pkg/$m && continue
+               echo "SUB_INST installing: $m"
+               install -D -m644 debian/$from_pkg/$m \
+                       debian/$to_pkg/$m
+       done
+done
diff --git a/debian/snapcraft.mk b/debian/snapcraft.mk
new file mode 100644 (file)
index 0000000..49f8727
--- /dev/null
@@ -0,0 +1,11 @@
+ifeq ($(ARCH),)
+  arch := $(shell uname -m | sed -e s/i.86/i386/ -e s/x86_64/amd64/ \
+            -e s/arm.*/armhf/ -e s/s390/s390x/ -e s/ppc.*/powerpc/ \
+            -e s/aarch64.*/arm64/ )
+else ifeq ($(ARCH),arm)
+  arch := armhf
+else
+  arch := $(ARCH)
+endif
+config:
+       cat debian.$(branch)/config/config.common.ubuntu debian.$(branch)/config/$(arch)/config.common.$(arch) debian.$(branch)/config/$(arch)/config.flavour.$(flavour) >.config
diff --git a/debian/source/format b/debian/source/format
new file mode 100644 (file)
index 0000000..d3827e7
--- /dev/null
@@ -0,0 +1 @@
+1.0
diff --git a/debian/source/options b/debian/source/options
new file mode 100644 (file)
index 0000000..5810259
--- /dev/null
@@ -0,0 +1,14 @@
+# Ignore vbox symlinks, we will regenerate these at clean (LP:1426113)
+## autoreconstruct -- begin
+# Ignore any symlinks created since the orig which are rebuilt by reconstruct.
+extend-diff-ignore=ubuntu/vbox/vboxguest/include
+extend-diff-ignore=ubuntu/vbox/vboxguest/r0drv
+extend-diff-ignore=ubuntu/vbox/vboxsf/include
+extend-diff-ignore=ubuntu/vbox/vboxsf/r0drv
+extend-diff-ignore=ubuntu/vbox/vboxvideo/include
+extend-diff-ignore=ubuntu/vbox/vboxvideo/r0drv
+## autoreconstruct -- end
+
+# force "dpkg-source -I -i" behavior
+diff-ignore
+tar-ignore
diff --git a/debian/stamps/keep-dir b/debian/stamps/keep-dir
new file mode 100644 (file)
index 0000000..5c38d4a
--- /dev/null
@@ -0,0 +1 @@
+Place holder
diff --git a/debian/tests-build/README b/debian/tests-build/README
new file mode 100644 (file)
index 0000000..c74d1c4
--- /dev/null
@@ -0,0 +1,21 @@
+Scripts placed in this directory get called one at a time by run-parts(8).
+The scripts are expected to perform some sort of sanity checks on the
+finished build. Scripts will be called once for each flavour.
+
+Some environment variables are exported to make life a little easier:
+
+DPKG_ARCH     : The dpkg architecture (e.g. "amd64")
+KERN_ARCH     : The kernel architecture (e.g. "x86_64")
+FLAVOUR       : The specific flavour for this run (e.g. "generic")
+VERSION       : The full version of this build (e.g. 2.6.22-1)
+REVISION      : The exact revision of this build (e.g. 1.3)
+PREV_REVISION : The revision prior to this one
+ABI_NUM       : The specific ABI number for this build (e.g. 2)
+PREV_ABI_NUM  : The previous ABI number. Can be the same as ABI_NUM.
+BUILD_DIR     : The directory where this build took place
+INSTALL_DIR   : The directory where the package is prepared
+SOURCE_DIR    : Where the main kernel source is
+
+Scripts are expected to have a zero exit status when no problems occur,
+and non-zero when an error occurs that should stop the build. Scripts
+should print whatever info they deem needed to deduce the problem.
diff --git a/debian/tests-build/check-aliases b/debian/tests-build/check-aliases
new file mode 100755 (executable)
index 0000000..b85118f
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/perl -w
+
+my %map;
+
+print "Checking for dupe aliases in $ENV{'FLAVOUR'}...\n";
+
+$aliases =
+  "$ENV{'INSTALL_DIR'}/lib/modules/$ENV{'VERSION'}-$ENV{'FLAVOUR'}/modules.alias";
+
+open(ALIASES, "< $aliases") or die "Could not open $aliases";
+
+while (<ALIASES>) {
+       chomp;
+       my ($junk, $alias, $module) = split;
+
+       if (defined($map{$alias})) {
+               printf("%s %20s / %-20s : %s \n", ("$map{$alias}" eq "$module")
+                       ? "INT" : "   ", $map{$alias}, $module, $alias);
+       } else {
+               $map{$alias} = $module;
+       }
+}
+
+exit(0);
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644 (file)
index 0000000..d12087c
--- /dev/null
@@ -0,0 +1,7 @@
+Tests: rebuild
+Depends: @builddeps@, fakeroot
+Restrictions: allow-stderr
+
+Tests: ubuntu-regression-suite
+Depends: build-essential, gcc-multilib [amd64 arm64 armhf i386], gdb, git, bzr
+Restrictions: allow-stderr, isolation-machine, breaks-testbed
diff --git a/debian/tests/rebuild b/debian/tests/rebuild
new file mode 100644 (file)
index 0000000..6f73b36
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# If we are triggering for just linux or linux-meta we know we have
+# just built the kernel and there is no point in repeating that
+# build, it just wastes time.  (LP: #1498862)
+build_needed=0
+for trigger in ${ADT_TEST_TRIGGERS:-force}
+do
+       case "$trigger" in
+       linux/*|linux-lts-*/*|linux-meta*/*)            ;;
+       *)                                              build_needed=1 ;;
+       esac
+done
+if [ "$build_needed" -eq 0 ]; then
+       echo "rebuild: short circuiting build for '${ADT_TEST_TRIGGERS}'"
+       exit 0
+fi
+
+set -e
+dpkg-buildpackage -rfakeroot -us -uc -b
diff --git a/debian/tests/ubuntu-regression-suite b/debian/tests/ubuntu-regression-suite
new file mode 100755 (executable)
index 0000000..1de5ce6
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+set -e
+
+sver=`dpkg-parsechangelog -SVersion`
+read x rver x </proc/version_signature
+
+flavour=${rver#*-*-}
+rver=${rver%-$flavour}
+
+echo "Source Package Version: $sver"
+echo "Running Kernel Version: $rver"
+
+if [ "$sver" != "$rver" ]; then
+    echo "ERROR: running version does not match source package" 1>&2
+    exit 1
+fi
+
+git clone git://kernel.ubuntu.com/ubuntu/kernel-testing
+kernel-testing/run-dep8-tests
diff --git a/debian/tools/generic b/debian/tools/generic
new file mode 100644 (file)
index 0000000..ebc87fd
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/bash
+full_version=`uname -r`
+
+# First check for a fully qualified version.
+this="/usr/lib/linux-tools/$full_version/`basename $0`"
+if [ -f "$this" ]; then
+       exec "$this" "$@"
+fi
+
+# Removing flavour from version i.e. generic or server.
+flavour_abi=${full_version#*-}
+flavour=${flavour_abi#*-}
+version=${full_version%-$flavour}
+this="$0_$version"
+if [ -f "$this" ]; then
+       exec "$this" "$@"
+fi
+
+# Before saucy kernels we had no flavour linkage.
+if dpkg --compare-versions "$version" lt "3.11.0"; then
+       flavour=''
+else
+       flavour="-$flavour"
+fi
+# Hint at the cloud tools if they exist (trusty and later)
+if dpkg --compare-versions "$version" ge "3.13.0"; then
+       cld=""
+else
+       cld=":"
+fi
+# Work out if this is an LTS backport or not.
+codename=`lsb_release -cs`
+case "$codename" in
+precise)       base='3.2.0-9999' ;;
+trusty)                base='3.13.0-9999' ;;
+*)             base='' ;;
+esac
+std=""
+lts=":"
+if [ "$base" != "" ]; then
+       if dpkg --compare-versions "$version" gt "$base"; then
+               std=":"
+               lts=""
+       fi
+fi
+
+# Give them a hint as to what to install.
+               echo "WARNING: `basename $0` not found for kernel $version" >&2
+               echo "" >&2
+               echo "  You may need to install the following packages for this specific kernel:" >&2
+               echo "    linux-tools-$version$flavour" >&2
+$cld           echo "    linux-cloud-tools-$version$flavour" >&2
+               echo "" >&2
+               echo "  You may also want to install one of the following packages to keep up to date:" >&2
+$std           echo "    linux-tools$flavour" >&2
+$std $cld      echo "    linux-cloud-tools$flavour" >&2
+$lts           echo "    linux-tools$flavour-lts-<series>" >&2
+$lts $cld      echo "    linux-cloud-tools$flavour-lts-<series>" >&2
+
+exit 2
diff --git a/debian/zfs-modules.ignore b/debian/zfs-modules.ignore
new file mode 100644 (file)
index 0000000..9529d23
--- /dev/null
@@ -0,0 +1,8 @@
+spl
+splat
+zavl
+zcommon
+zfs
+znvpair
+zpios
+zunicode
diff --git a/drivers/staging/signature-inclusion b/drivers/staging/signature-inclusion
new file mode 100644 (file)
index 0000000..c34f191
--- /dev/null
@@ -0,0 +1,5 @@
+#
+# This file lists the staging drivers that are safe for signing
+# and loading in a secure boot environment with signed module enforcement.
+#
+
diff --git a/dropped.txt b/dropped.txt
new file mode 100644 (file)
index 0000000..4183196
--- /dev/null
@@ -0,0 +1,4 @@
+This is the list of patches/features which have been temporarily
+reverted or disabled for Q:
+
+UBUNTU: SAUCE: AppArmor: basic networking rules
index 51ca0244fc8ac4f8e2981fb9dbc9df3efe507861..1de17f21f4e04e4b55838e452e46e502b5f0a30e 100644 (file)
@@ -23,8 +23,12 @@ quiet_cmd_modules_install = INSTALL $@
     mkdir -p $(2) ; \
     cp $@ $(2) ; \
     $(mod_strip_cmd) $(2)/$(notdir $@) ; \
-    $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) && \
-    $(mod_compress_cmd) $(2)/$(notdir $@)
+    if (echo "$(2)/$(notdir $@)" | egrep -q "\/drivers\/staging\/") && \
+       [ -f $(CURDIR)/drivers/staging/signature-inclusion ] && \
+       (! egrep -x "$(2)/$(notdir $@)" $(CURDIR)/drivers/staging/signature-inclusion) ; \
+       then echo Not signing "$(2)/$(notdir $@)"; \
+       else $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) && \
+               $(mod_compress_cmd) $(2)/$(notdir $@); fi
 
 # Modules built outside the kernel source tree go into extra by default
 INSTALL_MOD_DIR ?= extra
diff --git a/ubuntu/Kconfig b/ubuntu/Kconfig
new file mode 100644 (file)
index 0000000..f15ccd8
--- /dev/null
@@ -0,0 +1,17 @@
+menu "Ubuntu Supplied Third-Party Device Drivers"
+
+#
+# NOTE: to allow drivers to be added and removed without causing merge
+# collisions you should add new entries in the middle of the six lines
+# of ## at the bottom of the list.  Always add three lines of ## above
+# your new entry and maintain the six lines below.
+#
+
+##
+##
+##
+##
+##
+##
+
+endmenu
diff --git a/ubuntu/Makefile b/ubuntu/Makefile
new file mode 100644 (file)
index 0000000..5823ca0
--- /dev/null
@@ -0,0 +1,20 @@
+#
+# Makefile for the Linux kernel ubuntu supplied third-party device drivers.
+#
+
+#
+# NOTE: to allow drivers to be added and removed without causing merge
+# collisions you should add new entries in the middle of the six lines
+# of ## at the bottom of the list.  Always add three lines of ## above
+# your new entry and maintain the six lines below.
+#
+
+##
+##
+##
+##
+##
+##
+
+# This is a stupid trick to get kbuild to create ubuntu/built-in.o
+obj- += foo.o
diff --git a/ubuntu/include/Kbuild b/ubuntu/include/Kbuild
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/ubuntu/include/README b/ubuntu/include/README
new file mode 100644 (file)
index 0000000..adc8d33
--- /dev/null
@@ -0,0 +1,4 @@
+Only use this directory for things which need to share their headers with
+other parts of the kernel or other modules in ubuntu/
+
+Otherwise, keep them local to the module directory.