r3254 - branches/kernel-image-2.6.11/debian/bin

Jurij Smakov jurij-guest@costa.debian.org
Sat, 28 May 2005 18:59:28 +0000


Author: jurij-guest
Date: 2005-05-28 18:59:27 +0000 (Sat, 28 May 2005)
New Revision: 3254

Added:
   branches/kernel-image-2.6.11/debian/bin/apply
   branches/kernel-image-2.6.11/debian/bin/prune-non-free
Log:
Added prune-non-free and apply scripts.


Added: branches/kernel-image-2.6.11/debian/bin/apply
===================================================================
--- branches/kernel-image-2.6.11/debian/bin/apply	2005-05-28 16:45:07 UTC (rev 3253)
+++ branches/kernel-image-2.6.11/debian/bin/apply	2005-05-28 18:59:27 UTC (rev 3254)
@@ -0,0 +1,251 @@
+#!/bin/sh 
+# $Id: apply,v 1.4 2003/06/30 12:49:09 herbert Exp $
+
+set -e
+
+length=50
+
+die() {
+	echo "E: $@" >&2
+	exit 1
+}
+
+warn() {
+	echo "W: $@" >&2
+}
+
+uncompress_patch() {
+	patch=$1
+	case "$patch" in
+		*.bz2) bzcat $patch ;;
+		*.gz) zcat $patch ;;
+		*) cat $patch ;;
+	esac
+}
+
+find_patch() {
+	patch=$1
+
+	if [ -f "$patch" ]; then
+		echo "$patch"
+	elif [ -f "$patch.bz2" ]; then
+		echo "$patch.bz2"
+	elif [ -f "$patch.gz" ]; then
+		echo "$patch.gz"
+	else
+		die "$patch is in the series, but doesn't exist!"
+	fi
+}
+		
+apply_patch() {
+	patch=$(find_patch $home/$1)
+	base=$1
+	if uncompress_patch "$patch" | patch -p1 -f -s -t --no-backup-if-mismatch; then
+		printf "%-${length}s\tOK (+)\n" "$base"
+	else
+		printf "%-${length}s\tFAIL (+)\n" "$base"
+		exit 1
+	fi
+}
+
+deapply_patch() {
+	patch=$(find_patch $home/$1)
+	base=$1
+	if uncompress_patch "$patch" | patch -p1 -f -s -t -R --no-backup-if-mismatch; then
+		printf "%-${length}s\tOK (-)\n" "$base"
+	else
+		printf "%-${length}s\tFAIL (-)\n" "$base"
+		exit 1
+	fi
+}
+
+unpatch_series() {
+	series=$1
+	[ -f "$series" ] || die "I wasn't passed a series: $series"
+
+	tac $series | while read action patch; do
+		case "$action" in
+			+) deapply_patch $patch ;;
+			-) apply_patch $patch ;;
+			X)
+				bakfile="$(dirname $patch)/.$(basename $patch).bak"
+				if [ -f "$bakfile" ]; then
+					mv -f "$bakfile" "$patch"
+					printf "%-${length}s\tRESTORED (X)\n" "$patch"
+				else
+					printf "%-${length}s\tNO BACKUP (X)\n" "$patch"
+				fi
+			;;
+		esac
+	done 
+	echo "--> $(basename $series) fully unapplied."
+}
+
+patch_series() {
+	series=$1
+	[ -f "$series" ] || die "I wasn't passed a series: $series"
+
+	while read action patch; do
+		case "$action" in
+			+) apply_patch $patch ;;
+			-) deapply_patch $patch ;;
+			X)
+				bakfile="$(dirname $patch)/.$(basename $patch).bak"
+				if [ -f "$patch" ]; then
+					mv -f "$patch" "$bakfile"
+					printf "%-${length}s\tREMOVED (X)\n" "$patch"
+				else
+					printf "%-${length}s\tNO FILE (X)\n" "$patch"
+				fi
+			;;
+		esac
+	done < $series
+	echo "--> $(basename $series) fully applied."
+}
+
+bubble_sort ()
+{
+	DIR=$1
+	shift
+	SORTED=$@
+
+	SWAPED=1
+	while [ $SWAPED = 1 ]; do
+		X=0
+		A=""
+		SWAPED=0
+		NEW=""
+		for i in $SORTED; do
+			if [ -z "$A" ]; then
+				A="$i"
+				continue
+			fi
+			B="$i"
+		
+			if dpkg --compare-versions "$A" "$DIR" "$B"; then
+				SWAPED=1
+				NEW="$NEW $B"
+			else
+				NEW="$NEW $A"
+				A="$B"
+			fi
+
+			X=$(($X + 1))
+		done
+		SORTED="$NEW $A"
+	done
+
+	echo $SORTED
+}
+
+bubble_sort_fwd ()
+{
+	bubble_sort "lt" $@
+}
+
+bubble_sort_rev ()
+{
+	bubble_sort "gt" $@
+}
+
+
+if ! [ -d Documentation ] || ! [ -d kernel ]; then
+	die 'Not in kernel top level directory.  Exiting'
+	exit 1
+fi
+
+# for THIS particular version of the source package
+version=${override_version:-@version@}
+upstream=${version%-*}
+revision=${version#*-}
+
+home=${home:-/usr/src/kernel-patches/all/$upstream/debian}
+
+if [ -f version.Debian ]; then
+	current=$(cat version.Debian)
+	current_rev=${current#*-}
+	current_up=${current%-*}
+
+	if [ "$current" = "$upstream" ]; then
+		current_rev=0
+	fi
+else
+	warn "No version.Debian file, assuming pristine Linux $upstream"
+	current=$upstream
+	current_rev=0
+fi
+
+target=${1:-$version}
+
+target_rev=${target#*-}
+target_up=${target%-*}
+
+# Sanity checks
+if dpkg --compare-versions "$target_up" ne "$upstream"; then
+	die "Upstream $target_up doesn't match $upstream!"
+# We don't have that version out yet!
+elif [ ! -n "$target_rev" ] || 
+		( dpkg --compare-versions "$target_rev" ne "$target" && 
+			dpkg --compare-versions "$target_rev" gt "$revision" ); then
+	year=$(($(date +%Y) + 1))
+	die "Can't patch to nonexistent revision $target_rev (wait until $year)"
+fi
+
+# At this point, we must handle three cases.
+# 1. $target_rev is greater than $current_rev. We must patch forward for this.
+# 2. $target_rev is less than $current_rev. We must reverse the list of series,
+#    reverse each used series (tac) and unapply applied patches and vice versa.
+# 3. $target_rev is undefined, and $target is $upstream.
+
+# Revert to upstream.
+if [ "$target_rev" = "$target" ]; then
+	# already reverted
+	if [ "$current" = "$target" ]; then 
+		echo "Nothing to do, exiting."
+		exit 0
+	fi
+
+	for base in $(cd $home/series/ && bubble_sort_fwd $(ls -d *)); do
+		srev=${base#*-}
+		if [ -n "$srev" ]; then
+			if dpkg --compare-versions $srev "<=" $current_rev; then
+				unpatch_series $home/series/$base
+			fi
+		else
+			die "Series doesn't have a revision!"
+		fi
+	done
+elif dpkg --compare-versions "$current_rev" eq "$upstream" ||
+              dpkg --compare-versions "$target_rev" gt "$current_rev"; then
+	for base in $(cd $home/series/ && bubble_sort_rev $(ls -d *)); do
+		srev=${base#*-}
+		if [ -n "$srev" ]; then
+		    if dpkg --compare-versions "$srev" gt "$current_rev" && 
+			            dpkg --compare-versions "$srev" le "$target_rev"; then
+				patch_series $home/series/$base
+			fi
+		else
+			die "Series doesn't have a revision!"
+		fi
+	done
+elif dpkg --compare-versions "$target_rev" eq "$current_rev"; then
+	echo "Nothing to do, exiting."
+	exit 0
+elif dpkg --compare-versions "$target_rev" lt "$current_rev"; then
+	for base in $(cd $home/series/ && bubble_sort_fwd $(ls -d *)); do
+		srev=${base#*-}
+		if [ -n "$srev" ]; then
+			# -gt because you don't want to unapply the target series
+			if dpkg --compare-versions "$srev" le "$current_rev" && 
+			            dpkg --compare-versions "$srev" gt "$target_rev"; then
+				unpatch_series $home/series/$base
+			fi
+		else
+			die "Series doesn't have a revision!"
+		fi
+	done
+fi
+
+echo $target > version.Debian
+
+# vim:noet:ai:ts=4


Property changes on: branches/kernel-image-2.6.11/debian/bin/apply
___________________________________________________________________
Name: svn:executable
   + *

Added: branches/kernel-image-2.6.11/debian/bin/prune-non-free
===================================================================
--- branches/kernel-image-2.6.11/debian/bin/prune-non-free	2005-05-28 16:45:07 UTC (rev 3253)
+++ branches/kernel-image-2.6.11/debian/bin/prune-non-free	2005-05-28 18:59:27 UTC (rev 3254)
@@ -0,0 +1,312 @@
+#!/usr/bin/ruby -w
+# prune-non-free - split out non-free drivers, and generate kernel-source tarball.
+#
+#    Copyright (C) 2005  Andres Salomon <dilinger@debian.org>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+FILES = %w{
+	drivers/net/tg3.c
+	drivers/net/tg3.h
+
+	drivers/net/acenic.c
+	drivers/net/acenic.h
+	drivers/net/acenic_firmware.h
+
+	drivers/net/dgrs.c
+	drivers/net/dgrs.h
+	drivers/net/dgrs_es4h.h
+	drivers/net/dgrs_plx9060.h
+	drivers/net/dgrs_i82596.h
+	drivers/net/dgrs_ether.h
+	drivers/net/dgrs_asstruct.h
+	drivers/net/dgrs_bcomm.h
+	drivers/net/dgrs_firmware.c
+
+	drivers/net/tokenring/smctr.c
+	drivers/net/tokenring/smctr.h
+	drivers/net/tokenring/smctr_firmware.h
+
+	drivers/scsi/qla2xxx/qla_def.h
+	drivers/scsi/qla2xxx/qla_settings.h
+	drivers/scsi/qla2xxx/qla_version.h
+	drivers/scsi/qla2xxx/qla_gbl.h
+	drivers/scsi/qla2xxx/qla_dbg.h
+	drivers/scsi/qla2xxx/qla_inline.h
+	drivers/scsi/qla2xxx/qla_listops.h
+	drivers/scsi/qla2xxx/qla_devtbl.h
+	drivers/scsi/qla2xxx/qla_os.c
+	drivers/scsi/qla2xxx/qla_init.c
+	drivers/scsi/qla2xxx/qla_mbx.c
+	drivers/scsi/qla2xxx/qla_iocb.c
+	drivers/scsi/qla2xxx/qla_isr.c
+	drivers/scsi/qla2xxx/qla_gs.c
+	drivers/scsi/qla2xxx/qla_dbg.c
+	drivers/scsi/qla2xxx/qla_sup.c
+	drivers/scsi/qla2xxx/qla_rscn.c
+	drivers/scsi/qla2xxx/ql2100.c
+	drivers/scsi/qla2xxx/ql2100_fw.c
+	drivers/scsi/qla2xxx/ql2200.c
+	drivers/scsi/qla2xxx/ql2200_fw.c
+	drivers/scsi/qla2xxx/ql2300.c
+	drivers/scsi/qla2xxx/ql2300_fw.c
+	drivers/scsi/qla2xxx/ql2322.c
+	drivers/scsi/qla2xxx/ql2322_fw.c
+	drivers/scsi/qla2xxx/ql6312.c
+	drivers/scsi/qla2xxx/ql6312_fw.c
+
+	drivers/usb/media/dabusb.c
+	drivers/usb/media/dabusb.h
+	drivers/usb/media/dabfirmware.h
+
+	drivers/usb/misc/emi62.c
+	drivers/usb/misc/emi62_fw_m.h
+	drivers/usb/misc/emi62_fw_s.h
+
+	drivers/usb/serial/keyspan.c
+	drivers/usb/serial/keyspan.h
+	-drivers/usb/serial/usb-serial.h
+	drivers/usb/serial/keyspan_mpr_fw.h
+	drivers/usb/serial/keyspan_usa18x_fw.h
+	drivers/usb/serial/keyspan_usa19_fw.h
+	drivers/usb/serial/keyspan_usa19qi_fw.h
+	drivers/usb/serial/keyspan_usa19qw_fw.h
+	drivers/usb/serial/keyspan_usa19w_fw.h
+	drivers/usb/serial/keyspan_usa28_fw.h
+	drivers/usb/serial/keyspan_usa28x_fw.h
+	drivers/usb/serial/keyspan_usa28xa_fw.h
+	drivers/usb/serial/keyspan_usa28xb_fw.h
+	drivers/usb/serial/keyspan_usa49w_fw.h
+	drivers/usb/serial/keyspan_usa49wlc_fw.h
+	drivers/usb/serial/keyspan_usa26msg.h
+	drivers/usb/serial/keyspan_usa28msg.h
+	drivers/usb/serial/keyspan_usa49msg.h
+	drivers/usb/serial/keyspan_usa90msg.h
+}
+
+require 'tempfile'
+require 'fileutils'
+require 'open3'
+
+class Shell
+	def Shell.quote(s)
+		"'" + s.gsub("'") { |i| "'\\''" } + "'"
+	end
+
+	def Shell.quote!(s)
+		s.replace(quote(s))
+	end
+
+	def Shell.command(cmd)
+		if cmd.class == Array
+			s = cmd.shift
+			cmd.each { |arg|
+				s += ' ' + Shell.quote(arg)
+			}
+			cmd = s
+		end
+
+		ret = Open3.popen3(cmd + ';echo $?') { |si,so,se|
+			[ so.readlines, se.readlines ]
+		}
+		errno = ret[0].pop.to_i
+		raise "Error: cannot execute command #{cmd}: #{ret[1].join('')}" if errno != 0
+		ret
+	end
+end
+
+def tmpdir
+	tf = Tempfile.new('prune','.')
+	FileUtils.rm_f(tf.path)
+	FileUtils.mkdir_p(tf.path)
+	tf.path
+end
+
+def kversion(file)
+	tarball = File.basename(file)
+	unless tarball =~ /^linux-([0-9\.]+)\.tar.*$/
+		raise "cannot determine kernel version from '#{tarball}'!"
+	end
+	$1
+end
+
+def zip_type(tarball)
+	if tarball =~ /\.gz$/
+		'z'
+	elsif tarball =~ /\.bz2/
+		'j'
+	else
+		''
+	end
+end
+
+def unpack(tarball, targetdir)
+	unless File.exists?(tarball)
+		raise "file '#{tarball}' doesn't exist!"
+	end
+	FileUtils.rm_rf(targetdir)
+
+	zipped = zip_type(tarball)
+	dir = Shell.command("tar #{zipped}tf " + Shell.quote(tarball) + " | head -n1")
+	dir = dir[0][0].chomp
+
+	tmp = tmpdir()
+	Shell.command("tar #{zipped}xCf #{tmp} " + Shell.quote(tarball))
+	FileUtils.mv("#{tmp}/#{dir}", targetdir)
+	FileUtils.rm_rf(tmp)
+end
+
+def pack(tarball, srcdir)
+	unless File.directory?(srcdir)
+		raise "directory '#{srcdir}' doesn't exist!"
+	end
+	FileUtils.rm_f(tarball)
+
+	zipped = zip_type(tarball)
+	Shell.command("tar #{zipped}cf " + Shell.quote(tarball) + ' ' + Shell.quote(srcdir))
+end
+
+def rm_config_from_kconfig(mf, option)
+	option = option.sub(/^CONFIG_/, '')
+	kconfig = File.dirname(mf) + '/Kconfig'
+	new_kconfig = File.open(kconfig + '.new', 'w')
+	deleting = false
+	File.open(kconfig).each { |line|
+		if line.include?(option) && line =~ /^config\s+/
+			deleting = true
+		elsif line =~ /^(config|endmenu|comment)/
+			deleting = false
+		end
+		new_kconfig << line unless deleting
+	}
+	new_kconfig.close
+	FileUtils.mv(kconfig + '.new', kconfig)
+end
+
+def rm_config_from_makefile(mf, objects)
+	new_mf = File.open(mf + '.new', 'w')
+	File.open(mf).each { |line|
+		objects.each { |o|
+			line.gsub!(o, '')
+		}
+
+		if line !~ /=[\s\\]*$/
+			new_mf << line
+		end
+	}
+	new_mf.close
+	FileUtils.mv(mf + '.new', mf)
+end
+
+def scan_frag(src_mf, dst_mf, objects)
+	deferred = []
+	File.open(src_mf).each { |line|
+		if objects.find { |o| line.include?(o) } || line.include?('EXTRA_CFLAGS')
+			if line =~ /\$\((CONFIG_[A-Z0-9_]+)\)/
+				rm_config_from_kconfig(src_mf, $1)
+				dst_mf << "EXTRA_CFLAGS += -D#{$1}=1\n"
+				line.gsub!(/\$\(CONFIG_[A-Z0-9_]+\)/, 'm')
+			end
+			dst_mf << line
+
+			# Work around more complex Makefile builds
+			if line !~ /^\s*obj-/ && line =~ /^\s*([\w\d]+)-/
+				deferred << "#{$1}.o"
+			end
+
+			# Finally, delete object
+			rm_config_from_makefile(src_mf, objects)
+		end
+	}
+	deferred
+end
+
+def mk_makefile(name, dst_dir, fragments)
+	mf = File.open(name, 'w')
+	mf << "DIR ?= /usr/src/linux\n\n"
+	fragments.each { |key, val|
+		objects = val
+#		objects << 'EXTRA_CFLAGS' # make sure these don't get missed
+		while objects.length > 0
+			objects = scan_frag("#{dst_dir}/#{key}/Makefile", mf, objects)
+		end
+	}
+	mf << "\nall:\n\t$(MAKE) -C $(DIR) M=$(CURDIR) modules\n\n"
+	mf << "install:\n\t$(MAKE) -C $(DIR) M=$(CURDIR) modules_install\n\n"
+	mf << "clean:\n\t$(MAKE) -C $(DIR) M=$(CURDIR) clean\n\n"
+	mf.close
+end
+
+def dont_nuke_debian_dir(free_dir)
+	name = free_dir + '/scripts/package/Makefile'
+	mf = File.open(name + '.new', 'w')
+	File.open(name).each { |line|
+		if line !~ /\/debian\//
+			mf << line
+		end
+	}
+	mf.close
+	FileUtils.mv(name + '.new', name)
+end
+
+raise "Usage: #{$0} <kernel tarball>" unless ARGV.length == 1
+
+# Create source directories
+version = kversion(ARGV[0])
+free_dir = "kernel-source-#{version}-#{version}"
+nonfree_dir = "kernel-source-nonfree-#{version}-#{version}"
+unpack(ARGV[0], free_dir)
+FileUtils.mkdir_p(nonfree_dir)
+
+# Move or copy non-free and support files into non-free directory
+makefiles = {}
+FILES.each { |f|
+	copy = false
+	if f =~ /^-/
+		f.sub!(/^-/, '')
+		copy = true
+	end
+
+	file = File.basename(f)
+	dir = File.dirname(f)
+
+	# Move or copy file into non-free
+	if copy
+		FileUtils.cp("#{free_dir}/#{f}", nonfree_dir)
+	else
+		FileUtils.mv("#{free_dir}/#{f}", nonfree_dir)
+	end
+
+	# Add makefile fragment
+	if file =~ /\.c$/
+		obj = file.sub(/\.c$/, '.o')
+		makefiles[dir] ||= []
+		makefiles[dir] << obj unless makefiles[dir].index(obj)
+	end
+}
+# Generate non-free driver's makefile
+mk_makefile("#{nonfree_dir}/Makefile", free_dir, makefiles)
+
+dont_nuke_debian_dir(free_dir)
+
+# Tar up the kernel source trees
+pack("kernel-source-#{version}_#{version}.orig.tar.gz", free_dir)
+FileUtils.rm_rf(free_dir) 
+pack("kernel-source-nonfree-#{version}_#{version}.orig.tar.gz", nonfree_dir)
+FileUtils.rm_rf(nonfree_dir)
+
+
+exit(0)


Property changes on: branches/kernel-image-2.6.11/debian/bin/prune-non-free
___________________________________________________________________
Name: svn:executable
   + *