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

Re: Debian Kernel Patch Script



On Sun, Feb 13, 2005 at 12:55:35PM +0100, Jörg Hänsel wrote:
> Hello,
> I found a problem, building the Kernel-Source Package 
> "kernel-source-2.4.27_2.4.27-8_all.deb":
> 
> --> 2.4.27-8 fully applied.
> debian/kernel-patch-debian-2.4.27/usr/src/kernel-patches/all/2.4.27/apply/debian: 
> line 176: [: 8.mine: integer expression expected
> debian/kernel-patch-debian-2.4.27/usr/src/kernel-patches/all/2.4.27/apply/debian: 
> line 176: [: 8.r2289: integer expression expected
> debian/kernel-patch-debian-2.4.27/usr/src/kernel-patches/all/2.4.27/apply/debian: 
> line 176: [: 8.r2298: integer expression expected
> 
> I think line 176 in the debian patch scipt should be:
> 
> if [ $srev > $current_rev ] && [ $srev <= $target_rev ]; then
> 
> instead of
> 
> if [ $srev -gt $current_rev ] && [ $srev -le $target_rev ]; then
> 
> But then I will probably only work for 2.4.27-1 to 2.4.27-9. Perhaps you could 
> compare the part of the strings that are left of the "." numerically und the 
> rest lexicographically.

The attached patch, which makes use of dpkg --compare-versions, has
been working well for me. I will get it into svn for the next version.

-- 
Horms
Index: apply
===================================================================
--- apply	(revision 2482)
+++ apply	(working copy)
@@ -103,6 +103,39 @@
 	echo "--> $(basename $series) fully applied."
 }
 
+bubble_sort ()
+{
+	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 "lt" $B; then
+				SWAPED=1
+				NEW="$NEW $B"
+			else
+				NEW="$NEW $A"
+				A="$B"
+			fi
+
+			X=$(($X + 1))
+		done
+		SORTED="$NEW $A"
+	done
+
+	echo $SORTED
+}
+
 if ! [ -d Documentation ] || ! [ -d kernel ]; then
 	die 'Not in kernel top level directory.  Exiting'
 	exit 1
@@ -135,10 +168,12 @@
 target_up=${target%-*}
 
 # Sanity checks
-if [ "$target_up" != "$upstream" ]; then
+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" ] || ( [ "$target_rev" != "$target" ] && [ $target_rev -gt $revision ] ); then
+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
@@ -157,39 +192,42 @@
 		exit 0
 	fi
 
-	for sver in $(ls -d $home/series/* | sort -r); do
+	for sver in $(bubble_sort $(ls -d $home/series/*) ); do
 		base=$(basename "$sver")
 		srev=${base#*-}
 		if [ -n "$srev" ]; then
-			if [ $srev -le $current_rev ]; then
+			if dpkg --compare-versions $srev "<=" $current_rev; then
 				unpatch_series $sver
 			fi
 		else
 			die "Series doesn't have a revision!"
 		fi
 	done
-elif [ "$current_rev" = "$upstream" ] || [ $target_rev -gt $current_rev ]; then
+elif dpkg --compare-versions "$current_rev" eq "$upstream" ||
+		dpkg --compare-versions "$target_rev" gt "$current_rev"; then
 	for sver in $home/series/*; do
 		base=$(basename "$sver")
 		srev=${base#*-}
 		if [ -n "$srev" ]; then
-			if [ $srev -gt $current_rev ] && [ $srev -le $target_rev ]; then
+			if dpkg --compare-versions "$srev" gt "$current_rev" && 
+						dpkg --compare-versions "$srev" le "$target_rev"; then
 				patch_series $sver
 			fi
 		else
 			die "Series doesn't have a revision!"
 		fi
 	done
-elif [ $target_rev -eq $current_rev ]; then
+elif dpkg --compare-versions "$target_rev" eq "$current_rev"; then
 	echo "Nothing to do, exiting."
 	exit 0
-elif [ $target_rev -lt $current_rev ]; then
-	for sver in $(ls -d $home/series/* | sort -r); do
+elif dpkg --compare-versions "$target_rev" lt "$current_rev"; then
+	for sver in $(bubble_sort $(ls -d $home/series/*) ); do
 		base=$(basename "$sver")
 		srev=${base#*-}
 		if [ -n "$srev" ]; then
-			# -gt because you don't want to unapply the target series
-			if [ $srev -le $current_rev ] && [ $srev -gt $target_rev ]; 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 $sver
 			fi
 		else

Reply to: