eradicate bashisms in scripts/patch-kernel
Hello,
I was non-mildly horrified to find that the rather widely used patch-kernel script seems to rely on bash despite specifying the interpreter as #!/bin/sh, since my dash-using Debian install choked on it.
Thus I'm delivering a first, preliminary, non-reviewed change to make patch-kernel (a little bit more?) POSIX-compatible. It now survives both a dash and a bash run.
If this mail goes through relatively unscathed, then it might be a good idea to plant it into -mm via a follow-up mail.
Comments?
- replaced "==" by "="
- the "source" statement most likely needs the ./ prepended, as can be gathered from e.g. http://osdir.com/ml/colinux.devel/2005-12/msg00036.html
- the newly replaced sed expression below: is it ok? correct? strict enough?
Thanks,
Andreas Mohr
(who's strongly hoping that submitting a patch for this thingy doesn't automatically equal becoming "maintainer for life" for it ;)
scripts/patch-kernel.dash renamed from scripts/patch-kernel +7 -13
@@ -65,7 +65,7 @@ patchdir=${2-.} stopvers=${3-default} -if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then +if [ "$1" = "-h" -o "$1" = "--help" -o ! -r "$sourcedir/Makefile" ]; then cat << USAGE usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ] source directory defaults to /usr/src/linux,
@@ -185,7 +185,7 @@ TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE tr -d [:blank:] < $TMPFILE > $TMPFILE.1 -source $TMPFILE.1 +. ./$TMPFILE.1 rm -f $TMPFILE* if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ] then
@@ -202,13 +202,7 @@ EXTRAVER= if [ x$EXTRAVERSION != "x" ] then - if [ ${EXTRAVERSION:0:1} == "." ]; then - EXTRAVER=${EXTRAVERSION:1} - else - EXTRAVER=$EXTRAVERSION - fi - EXTRAVER=${EXTRAVER%%[[:punct:]]*} - #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER" + EXTRAVER=`echo $EXTRAVERSION|sed -s 's/^[\.]\?\([^[:punct:]]*\).*/\1/'` fi #echo "stopvers=$stopvers"
@@ -251,16 +245,16 @@ do CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER= - if [ $stopvers == $CURRENTFULLVERSION ]; then + if [ $stopvers = $CURRENTFULLVERSION ]; then echo "Stopping at $CURRENTFULLVERSION base as requested." break fi - SUBLEVEL=$((SUBLEVEL + 1)) + SUBLEVEL=$(( $SUBLEVEL + 1 )) FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" #echo "#___ trying $FULLVERSION ___" - if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then + if [ $SUBLEVEL -gt $STOPSUBLEVEL ]; then echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)" exit 1 fi
@@ -297,7 +291,7 @@ if [ x$gotac != x ]; then # Out great user wants the -ac patches # They could have done -ac (get latest) or -acxx where xx=version they want - if [ $gotac == "-ac" ]; then + if [ $gotac = "-ac" ]; then # They want the latest version HIGHESTPATCH=0 for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.*
Quoted 10 lines · Andreas Mohr
Hello,
I was non-mildly horrified to find that the rather widely used patch-kernel script seems to rely on bash despite specifying the interpreter as #!/bin/sh, since my dash-using Debian install choked on it.
Thus I'm delivering a first, preliminary, non-reviewed change to make patch-kernel (a little bit more?) POSIX-compatible. It now survives both a dash and a bash run.
Quoted 6 lines
If this mail goes through relatively unscathed, then it might be a good idea to plant it into -mm via a follow-up mail.
Comments?
- replaced "==" by "="
Those are OK.
Quoted 2 lines
- the "source" statement most likely needs the ./ prepended, as can be gathered from e.g. http://osdir.com/ml/colinux.devel/2005-12/msg00036.html
That email isn't very convincing to me.
http://www.opengroup.org/onlinepubs/009695399/utilities/dot.html just says that if <filename> does not contain a slash, the search PATH shall be used (searched). If you want to prevent that, it's OK to use ./, but at least say that in the patch description, please.
Quoted 8 lines
- the newly replaced sed expression below: is it ok? correct? strict enough?
Thanks,
Andreas Mohr
(who's strongly hoping that submitting a patch for this thingy doesn't automatically equal becoming "maintainer for life" for it ;)
Be careful.
Quoted 5 lines
scripts/patch-kernel.dash line 211
Quoted 10 lines
scripts/patch-kernel.dash renamed from scripts/patch-kernel +0
-7@@ -202,13 +202,7 @@ EXTRAVER= if [ x$EXTRAVERSION != "x" ] then - if [ ${EXTRAVERSION:0:1} == "." ]; then - EXTRAVER=${EXTRAVERSION:1} - else - EXTRAVER=$EXTRAVERSION - fi - EXTRAVER=${EXTRAVER%%[[:punct:]]*} - #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
What's the problem above?
scripts/patch-kernel.dash line 250
Quoted 12 lines
scripts/patch-kernel.dash renamed from scripts/patch-kernel +2
-1+ EXTRAVER=`echo $EXTRAVERSION|sed -s 's/^[\.]\?\([^[:punct:]]*\).*/\1/'` fi #echo "stopvers=$stopvers"@@ -251,16 +245,16 @@ do CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER= - SUBLEVEL=$((SUBLEVEL + 1)) + SUBLEVEL=$(( $SUBLEVEL + 1 ))
Why are the added spaces needed?
Did you look at
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html ?
scripts/patch-kernel.dash line 257
Quoted 5 lines
scripts/patch-kernel.dash renamed from scripts/patch-kernel +1
-1FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" #echo "#___ trying $FULLVERSION ___" - if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then + if [ $SUBLEVEL -gt $STOPSUBLEVEL ]; then
What's the problem here?
Quoted 3 lines
scripts/patch-kernel.dash renamed from scripts/patch-kernel +0
-0echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)" exit 1 fi
Signature · 1 line
~Randy
Quoted 5 lines · Randy Dunlap
Quoted 2 lines · Andreas Mohr
- the "source" statement most likely needs the ./ prepended, as can be gathered from e.g. http://osdir.com/ml/colinux.devel/2005-12/msg00036.html
That email isn't very convincing to me.
Actually that place simply was where I found how the
.: 188: .tmpver.eC4856.1: not found
dash error that happened when I replaced the bash-specific "source" statement with its "." counterpart could be ""fixed"".
Quoted 6 lines
http://www.opengroup.org/onlinepubs/009695399/utilities/dot.html just says that
if <filename> does not contain a slash, the search PATH shall be used (searched).
If you want to prevent that, it's OK to use ./, but at least say that in the patch description, please.
So this part seems to indicate that merely prepending ./ is problematic, since ./ implies relative path resolution whereas $TMPFILE.1 could theoretically be an absolute path already.
It would probably be best to add the ./ to mktemp already, to make sure we source *exactly* the filename expression we originally mktemp'd.
OTOH prepending ./ to mktemp by default would deny mktemp any "search for a temporary-capable directory and create the file there" capabilities. Hmm. I should investigate POSIX shell sourcing mechanisms more.
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0
-0@@ -202,13 +202,7 @@EXTRAVER=
if [ x$EXTRAVERSION != "x" ]
thenscripts/patch-kernel.dash renamed from scripts/patch-kernel +0
-1- if [ ${EXTRAVERSION:0:1} == "." ]; then
Quoted 8 lines
scripts/patch-kernel.dash line 211
Quoted 6 lines
scripts/patch-kernel.dash renamed from scripts/patch-kernel +0
-6- EXTRAVER=${EXTRAVERSION:1} - else - EXTRAVER=$EXTRAVERSION - fi - EXTRAVER=${EXTRAVER%%[[:punct:]]*} - #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"What's the problem above?
The variable manipulation seems bash-specific, the resulting dash error was:
linux-2.6.23/scripts/patch-kernel: 205: Syntax error: Bad substitution
which pointed at the
if [ ${EXTRAVERSION:0:1} == "." ]; thenline.
Quoted 5 lines
scripts/patch-kernel.dash line 253
Quoted 3 lines
scripts/patch-kernel.dash renamed from scripts/patch-kernel +1
-1- SUBLEVEL=$((SUBLEVEL + 1)) + SUBLEVEL=$(( $SUBLEVEL + 1 ))Why are the added spaces needed?
They weren't strictly needed, what was needed was to add the missing $ sign (you could perhaps say that I added the spaces to emphasize the $ sign). Maybe they're best removed.
Quoted 2 lines
Did you look at
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html ?
No. I should have started by looking at the opengroup.org site when looking for POSIX specs...
Quoted 8 lines
scripts/patch-kernel.dash line 257
Quoted 6 lines
FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" #echo "#___ trying $FULLVERSION ___"scripts/patch-kernel.dash renamed from scripts/patch-kernel +1
-1- if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then + if [ $SUBLEVEL -gt $STOPSUBLEVEL ]; thenWhat's the problem here?
I got
linux-2.6.23/scripts/patch-kernel: 270: arith: syntax error: "SUBLEVEL"
thus I simply removed braces since that "fixed" the issue. May be incorrect, though...
I'll think a bit more about these couple changed places (and whether this still truly works as intended) and mail a patch then.
(and a big NOTE: I'm no POSIX vs. non-POSIX shell guru at all, only a semi-versed shell script writer, thus these changes should be reviewed quite thoroughly)
Thanks for your very fast review,
Andreas Mohr
Quoted 27 lines · On Thu, 1 Nov 2007 13:11:33 +0100 Andreas Mohr wrote:
Quoted 5 lines · Randy Dunlap
Quoted 2 lines · Andreas Mohr
- the "source" statement most likely needs the ./ prepended, as can be gathered from e.g. http://osdir.com/ml/colinux.devel/2005-12/msg00036.html
That email isn't very convincing to me.
Actually that place simply was where I found how the
.: 188: .tmpver.eC4856.1: not found
dash error that happened when I replaced the bash-specific "source" statement with its "." counterpart could be ""fixed"".
Quoted 6 lines
http://www.opengroup.org/onlinepubs/009695399/utilities/dot.html just says that
if <filename> does not contain a slash, the search PATH shall be used (searched).
If you want to prevent that, it's OK to use ./, but at least say that in the patch description, please.So this part seems to indicate that merely prepending ./ is problematic, since ./ implies relative path resolution whereas $TMPFILE.1 could theoretically be an absolute path already.
It would probably be best to add the ./ to mktemp already, to make sure we source *exactly* the filename expression we originally mktemp'd.
Quoted 4 lines
OTOH prepending ./ to mktemp by default would deny mktemp any "search for a temporary-capable directory and create the file there" capabilities. Hmm. I should investigate POSIX shell sourcing mechanisms more.
As I indicated, I don't object to this part of the patch or to the s/==/=/ part either. The ./ just needs better patch description.
Quoted 57 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0
-0@@ -202,13 +202,7 @@EXTRAVER=
if [ x$EXTRAVERSION != "x" ]
thenscripts/patch-kernel.dash renamed from scripts/patch-kernel +0
-1- if [ ${EXTRAVERSION:0:1} == "." ]; thenQuoted 8 lines
scripts/patch-kernel.dash line 211
Quoted 6 lines
scripts/patch-kernel.dash renamed from scripts/patch-kernel +0
-6- EXTRAVER=${EXTRAVERSION:1} - else - EXTRAVER=$EXTRAVERSION - fi - EXTRAVER=${EXTRAVER%%[[:punct:]]*} - #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"What's the problem above?
The variable manipulation seems bash-specific, the resulting dash error was:
linux-2.6.23/scripts/patch-kernel: 205: Syntax error: Bad substitution
which pointed at the
if [ ${EXTRAVERSION:0:1} == "." ]; thenline.
Quoted 5 lines
scripts/patch-kernel.dash line 253
Quoted 3 lines
scripts/patch-kernel.dash renamed from scripts/patch-kernel +1
-1- SUBLEVEL=$((SUBLEVEL + 1)) + SUBLEVEL=$(( $SUBLEVEL + 1 ))Why are the added spaces needed?
They weren't strictly needed, what was needed was to add the missing $ sign (you could perhaps say that I added the spaces to emphasize the $ sign). Maybe they're best removed.
Quoted 2 lines
Did you look at
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html ?No. I should have started by looking at the opengroup.org site when looking for POSIX specs...
Quoted 8 lines
scripts/patch-kernel.dash line 257
Quoted 6 lines
FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" #echo "#___ trying $FULLVERSION ___"scripts/patch-kernel.dash renamed from scripts/patch-kernel +1
-1- if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then + if [ $SUBLEVEL -gt $STOPSUBLEVEL ]; thenWhat's the problem here?
I got
linux-2.6.23/scripts/patch-kernel: 270: arith: syntax error: "SUBLEVEL"
thus I simply removed braces since that "fixed" the issue. May be incorrect, though...
Quoted 6 lines
I'll think a bit more about these couple changed places (and whether this still truly works as intended) and mail a patch then.
(and a big NOTE: I'm no POSIX vs. non-POSIX shell guru at all, only a semi-versed shell script writer, thus these changes should be reviewed quite thoroughly)
Neither am I. I read those web pages quickly yesterday, so after you read them, we can discuss more and/or review more patches.
Thanks.
---
~Randy
Hi,
Quoted 10 lines · Randy Dunlap
Quoted 6 lines · On Thu, 1 Nov 2007 13:11:33 +0100 Andreas Mohr wrote:
I'll think a bit more about these couple changed places (and whether this still truly works as intended) and mail a patch then.
(and a big NOTE: I'm no POSIX vs. non-POSIX shell guru at all, only a semi-versed shell script writer, thus these changes should be reviewed quite thoroughly)
Neither am I. I read those web pages quickly yesterday, so after you read them, we can discuss more and/or review more patches.
OK, next iteration (v2).
Make the patch-kernel shell script sufficiently compatible with POSIX shells.
Changes since v1:
- don't actually change string quoting
- prepend ./ at mktemp step already
- remove added superfluous spaces in arithmetic expression
- don't remove double braces in STOPSUBLEVEL evaluation, since these are integer values to be compared
Full ChangeLog:
- replaced non-standard "==" by standard "="
- replaced non-standard "source" statement by POSIX "dot" statement
- POSIX shell local file lookup needs ./ prepended, thus have mktemp use this from the beginning and comment it properly
- replace non-standard bash string parsing by sed expression (is the sed syntax ok? correct? strict enough?)
- added missing $ signs to shell variable names
About the missing $ signs:
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_14
says:
"If the shell variable x contains a value that forms a valid integer constant, then the arithmetic expansions
"$((x))" and "$(($x))" shall return the same value."
Hmm, well, seems dash doesn't... (syntax error).
Thus I still needed to add the $ signs despite opengroup.org specifying it differently.
Updated version verified again to now work with both bash and dash on Debian stable.
Patch intended for inclusion in -mm, once it has survived some reviews.
Thanks.
scripts/patch-kernel renamed from scripts/patch-kernel.orig +10 -14
@@ -65,7 +65,7 @@ patchdir=${2-.} stopvers=${3-default} -if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then +if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then cat << USAGE usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ] source directory defaults to /usr/src/linux,
@@ -182,10 +182,12 @@ } # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION -TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } +# sourcing $TMPFILE.1 below needs lookup in local directory in a POSIX shell, +# thus prepend ./ to mktemp argument +TMPFILE=`mktemp ./.tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE tr -d [:blank:] < $TMPFILE > $TMPFILE.1 -source $TMPFILE.1 +. $TMPFILE.1 rm -f $TMPFILE* if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ] then
@@ -202,13 +204,7 @@ EXTRAVER= if [ x$EXTRAVERSION != "x" ] then - if [ ${EXTRAVERSION:0:1} == "." ]; then - EXTRAVER=${EXTRAVERSION:1} - else - EXTRAVER=$EXTRAVERSION - fi - EXTRAVER=${EXTRAVER%%[[:punct:]]*} - #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER" + EXTRAVER=`echo $EXTRAVERSION|sed -s 's/^[\.]\?\([^[:punct:]]*\).*/\1/'` fi #echo "stopvers=$stopvers"
@@ -251,16 +247,16 @@ do CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER= - if [ $stopvers == $CURRENTFULLVERSION ]; then + if [ $stopvers = $CURRENTFULLVERSION ]; then echo "Stopping at $CURRENTFULLVERSION base as requested." break fi - SUBLEVEL=$((SUBLEVEL + 1)) + SUBLEVEL=$(($SUBLEVEL + 1)) FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" #echo "#___ trying $FULLVERSION ___" - if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then + if [ $(($SUBLEVEL)) -gt $(($STOPSUBLEVEL)) ]; then echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)" exit 1 fi
@@ -297,7 +293,7 @@ if [ x$gotac != x ]; then # Out great user wants the -ac patches # They could have done -ac (get latest) or -acxx where xx=version they want - if [ $gotac == "-ac" ]; then + if [ $gotac = "-ac" ]; then # They want the latest version HIGHESTPATCH=0 for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.*
On Thu, 1 Nov 2007 23:16:06 +0100 Andreas Mohr wrote:
[add Herbert]
Quoted 27 lines
Hi,
Quoted 10 lines · Randy Dunlap
Quoted 6 lines · On Thu, 1 Nov 2007 13:11:33 +0100 Andreas Mohr wrote:
I'll think a bit more about these couple changed places (and whether this still truly works as intended) and mail a patch then.
(and a big NOTE: I'm no POSIX vs. non-POSIX shell guru at all, only a semi-versed shell script writer, thus these changes should be reviewed quite thoroughly)
Neither am I. I read those web pages quickly yesterday, so after you read them, we can discuss more and/or review more patches.
OK, next iteration (v2).
Make the patch-kernel shell script sufficiently compatible with POSIX shells.
Changes since v1:
- don't actually change string quoting
- prepend ./ at mktemp step already
- remove added superfluous spaces in arithmetic expression
- don't remove double braces in STOPSUBLEVEL evaluation, since these are integer values to be compared
Quoted 2 lines
Full ChangeLog:
- replaced non-standard "==" by standard "="
OK
Quoted 1 line
- replaced non-standard "source" statement by POSIX "dot" statement
OK
Quoted 2 lines
- POSIX shell local file lookup needs ./ prepended, thus have mktemp use this from the beginning and comment it properly
I would like the patch description to say something like:
Use ./ as a prefix on the TEMP filename so that the current search PATH will not be searched and thus another file with this same (pseudo random) name won't be used accidentally.
Quoted 2 lines
- replace non-standard bash string parsing by sed expression (is the sed syntax ok? correct? strict enough?)
I think that this is the part that bothers me. I can't find anything at
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html
that says that this:
EXTRAVER=${EXTRAVER%%[[:punct:]]*}is invalid or even optional syntax. OTOH, it does list such syntax, so why are we working around this syntax?
Please point out to me what I am missing...
Quoted 1 line
- added missing $ signs to shell variable names
OK
Quoted 10 lines
About the missing $ signs:
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_14
says:
"If the shell variable x contains a value that forms a valid integer constant, then the arithmetic expansions
"$((x))" and "$(($x))" shall return the same value."Hmm, well, seems dash doesn't... (syntax error).
Thus I still needed to add the $ signs despite opengroup.org specifying it differently.
Herbert?
Quoted 71 lines
Updated version verified again to now work with both bash and dash on Debian stable.
Patch intended for inclusion in -mm, once it has survived some reviews.
Thanks.
Signed-off-by Andreas Mohr <[email protected]>scripts/patch-kernel renamed from scripts/patch-kernel.orig +9
-13@@ -65,7 +65,7 @@ patchdir=${2-.} stopvers=${3-default} -if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then +if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then cat << USAGE usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ] source directory defaults to /usr/src/linux,@@ -182,10 +182,12 @@ } # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION -TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } +# sourcing $TMPFILE.1 below needs lookup in local directory in a POSIX shell, +# thus prepend ./ to mktemp argument +TMPFILE=`mktemp ./.tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE tr -d [:blank:] < $TMPFILE > $TMPFILE.1 -source $TMPFILE.1 +. $TMPFILE.1 rm -f $TMPFILE* if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ] then@@ -202,13 +204,7 @@ EXTRAVER= if [ x$EXTRAVERSION != "x" ] then - if [ ${EXTRAVERSION:0:1} == "." ]; then - EXTRAVER=${EXTRAVERSION:1} - else - EXTRAVER=$EXTRAVERSION - fi - EXTRAVER=${EXTRAVER%%[[:punct:]]*} - #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER" + EXTRAVER=`echo $EXTRAVERSION|sed -s 's/^[\.]\?\([^[:punct:]]*\).*/\1/'` fi #echo "stopvers=$stopvers"@@ -251,16 +247,16 @@ do CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER= - if [ $stopvers == $CURRENTFULLVERSION ]; then + if [ $stopvers = $CURRENTFULLVERSION ]; then echo "Stopping at $CURRENTFULLVERSION base as requested." break fi - SUBLEVEL=$((SUBLEVEL + 1)) + SUBLEVEL=$(($SUBLEVEL + 1)) FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" #echo "#___ trying $FULLVERSION ___" - if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then + if [ $(($SUBLEVEL)) -gt $(($STOPSUBLEVEL)) ]; then echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)" exit 1 fi
scripts/patch-kernel
Quoted 9 lines
scripts/patch-kernel renamed from scripts/patch-kernel.orig +1
-2@@ -297,7 +293,7 @@ if [ x$gotac != x ]; then # Out great user wants the -ac patches # They could have done -ac (get latest) or -acxx where xx=version they want - if [ $gotac == "-ac" ]; then + if [ $gotac = "-ac" ]; then # They want the latest version HIGHESTPATCH=0 for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.* -
Thanks,
---
~Randy
Quoted 11 lines · Randy Dunlap
Quoted 3 lines
- replace non-standard bash string parsing by sed expression (is the sed syntax ok? correct? strict enough?)
I think that this is the part that bothers me. I can't find anything at
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html
that says that this:EXTRAVER=${EXTRAVER%%[[:punct:]]*}is invalid or even optional syntax. OTOH, it does list such syntax,
This is POSIX-compliant and has worked with dash from the very start.
Quoted 7 lines
Quoted 7 lines
About the missing $ signs:
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_14
says:
"If the shell variable x contains a value that forms a valid integer constant, then the arithmetic expansions
"$((x))" and "$(($x))" shall return the same value."
Quoted 5 lines
Quoted 3 lines
Hmm, well, seems dash doesn't... (syntax error).
Thus I still needed to add the $ signs despite opengroup.org specifying it differently.Herbert?
Using variables without dollar signs in arithmetic expansion was only added to dash very recently. So please please talk to your distribution maker to update their dash packages and it will work correctly.
This usage is compliant with the most recent revision of POSIX while earlier ones did not specifically require this (due to the fact that assignment support was not required either).
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtHi,
Quoted 11 lines · Herbert Xu
Quoted 7 lines · Randy Dunlap
I think that this is the part that bothers me. I can't find anything at
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html
that says that this:EXTRAVER=${EXTRAVER%%[[:punct:]]*}is invalid or even optional syntax. OTOH, it does list such syntax,
This is POSIX-compliant and has worked with dash from the very start.
True (just verified again). But then I didn't actually say that this line is problematic. Since I had to replace the leading . replacement part already I decided to simply fold everything into one sed expression.
Quoted 4 lines
Using variables without dollar signs in arithmetic expansion was only added to dash very recently. So please please talk to your distribution maker to update their dash packages and it will work correctly.
"Debian stable.", aka "Update not an option.". Right?
Since the specs list both possibilities I'd simply go with the safe one, the one that works on older dash versions, too.
Unless adding a $ sign happens to break other equally important shells...
Quoted 3 lines
This usage is compliant with the most recent revision of POSIX while earlier ones did not specifically require this (due to the fact that assignment support was not required either).
This is where I'd think the problem is. If dash once upon a time decided to support the $ variant only and the specs didn't list both at that time, well...
The dash version on my system is 0.5.3-5, BTW. Even Debian testing has 0.5.3-7 only.
I'm now quite certain on which side to tweak things ;)
Thanks a lot for your review,
Andreas Mohr
Quoted 3 lines · On Fri, 2 Nov 2007 21:09:35 +0100 Andreas Mohr wrote:
Hi,
I'm now quite certain on which side to tweak things ;)
The other parts of your patch should probably be merged IMO.
Would you resend a trimmed-down patch?
or should I do it?
Thanks,
---
~Randy
Hi,
Quoted 7 lines · Randy Dunlap
Quoted 3 lines · On Fri, 2 Nov 2007 21:09:35 +0100 Andreas Mohr wrote:
Hi,
I'm now quite certain on which side to tweak things ;)
The other parts of your patch should probably be merged IMO.
Hmm, that particular part consists of _two_ transformations:
- removing the leading dot
- keep everything before [:punct:]
and the first transformation doesn't work on certain dash versions the way it's currently coded.
Quoted 2 lines
Would you resend a trimmed-down patch?
or should I do it?
Feel free to go ahead, otherwise I'll try another patch sometime soon. All I care about is that the result works on (at least)
one shell implementation _more_ than the current status ;)
Thanks a lot,
Andreas Mohr
Quoted 6 lines · On Mon, 5 Nov 2007 20:58:27 +0100 Andreas Mohr wrote:
Quoted 2 lines
Would you resend a trimmed-down patch?
or should I do it?Feel free to go ahead, otherwise I'll try another patch sometime soon. All I care about is that the result works on (at least)
one shell implementation _more_ than the current status ;)
Hi Andreas,
Can you comment on (or test) whether this patch is sufficient for your needs? And if so, is the Signed-off-by: A.M. OK?
Thanks.
---
Make the patch-kernel shell script sufficiently compatible with POSIX shells, i.e., remove bashisms from scripts/patch-kernel.
Full changelog:
- replaced non-standard "==" by standard "="
- replaced non-standard "source" statement by POSIX "dot" command
- use leading ./ on mktemp filename to force the tempfile to a local directory, so that the search path is not used
- added missing (optional/not required) $ signs to shell variable names
scripts/patch-kernel renamed from scripts/patch-kernel.orig +9 -7
@@ -65,7 +65,7 @@ patchdir=${2-.} stopvers=${3-default} -if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then +if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then cat << USAGE usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ] source directory defaults to /usr/src/linux,
@@ -182,10 +182,12 @@ } # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION -TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } +# force $TMPFILEs below to be in local directory: a slash character prevents +# the dot command from using the search path. +TMPFILE=`mktemp ./.tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE tr -d [:blank:] < $TMPFILE > $TMPFILE.1 -source $TMPFILE.1 +. $TMPFILE.1 rm -f $TMPFILE* if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ] then
@@ -251,16 +247,16 @@ do CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER= - if [ $stopvers == $CURRENTFULLVERSION ]; then + if [ $stopvers = $CURRENTFULLVERSION ]; then echo "Stopping at $CURRENTFULLVERSION base as requested." break fi - SUBLEVEL=$((SUBLEVEL + 1)) + SUBLEVEL=$(($SUBLEVEL + 1)) FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" #echo "#___ trying $FULLVERSION ___" - if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then + if [ $(($SUBLEVEL)) -gt $(($STOPSUBLEVEL)) ]; then echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)" exit 1 fi
@@ -297,7 +293,7 @@ if [ x$gotac != x ]; then # Out great user wants the -ac patches # They could have done -ac (get latest) or -acxx where xx=version they want - if [ $gotac == "-ac" ]; then + if [ $gotac = "-ac" ]; then # They want the latest version HIGHESTPATCH=0 for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.*
-
Hi,
Quoted 9 lines · Randy Dunlap
Quoted 3 lines · On Mon, 5 Nov 2007 20:58:27 +0100 Andreas Mohr wrote:
Feel free to go ahead, otherwise I'll try another patch sometime soon. All I care about is that the result works on (at least)
one shell implementation _more_ than the current status ;)Hi Andreas,
Can you comment on (or test) whether this patch is sufficient for your needs? And if so, is the Signed-off-by: A.M. OK?
Sorry, no, using dash (0.5.3-5) there's still a remaining
$ linux-2.6.22/scripts/patch-kernel linux-2.6.22 /usr/src/patch-2.6 Current kernel version is 2.6.22 ( Holy Dancing Manatees, Batman!) linux-2.6.22/scripts/patch-kernel: 207: Syntax error: Bad substitution
error in the
# strip EXTRAVERSION to just a number (drop leading '.' and trailing additions) EXTRAVER= if [ x$EXTRAVERSION != "x" ] then
Quoted 1 line
Quoted 1 line
Quoted 1 line
[l.207] if [ ${EXTRAVERSION:0:1} == "." ]; then
EXTRAVER=${EXTRAVERSION:1}
else
EXTRAVER=$EXTRAVERSION
fi
EXTRAVER=${EXTRAVER%%[[:punct:]]*}
#echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"fi
part, which the sed expression (moderately successfully) tried to take care of.
The good part of the story is that the current corrected almost fully working version still works with bash (3.1dfsg-8), just like the original patch-kernel version.
Signed-off-by would be fine by me.
Thanks,
Andreas Mohr
Quoted 12 lines · Andreas Mohr
# strip EXTRAVERSION to just a number (drop leading '.' and trailing additions) EXTRAVER= if [ x$EXTRAVERSION != "x" ] thenQuoted 1 line
Quoted 1 line
Quoted 1 line
[l.207] if [ ${EXTRAVERSION:0:1} == "." ]; then
EXTRAVER=${EXTRAVERSION:1} else EXTRAVER=$EXTRAVERSION fi EXTRAVER=${EXTRAVER%%[[:punct:]]*} #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
Quoted 4 lines
fi
part, which the sed expression (moderately successfully) tried to take care of.
You don't need a sed expression for that. In fact the inner if clause can be replaced by the following line:
EXTRAVER=${EXTRAVERSION#.}Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 32 lines · Andreas Mohr
Hi,
Quoted 9 lines · Randy Dunlap
Quoted 3 lines · On Mon, 5 Nov 2007 20:58:27 +0100 Andreas Mohr wrote:
Feel free to go ahead, otherwise I'll try another patch sometime soon. All I care about is that the result works on (at least)
one shell implementation _more_ than the current status ;)Hi Andreas,
Can you comment on (or test) whether this patch is sufficient for your needs? And if so, is the Signed-off-by: A.M. OK?
Sorry, no, using dash (0.5.3-5) there's still a remaining
$ linux-2.6.22/scripts/patch-kernel linux-2.6.22 /usr/src/patch-2.6 Current kernel version is 2.6.22 ( Holy Dancing Manatees, Batman!) linux-2.6.22/scripts/patch-kernel: 207: Syntax error: Bad substitutionerror in the
# strip EXTRAVERSION to just a number (drop leading '.' and trailing additions) EXTRAVER= if [ x$EXTRAVERSION != "x" ] thenQuoted 1 line
Quoted 1 line
Quoted 1 line
[l.207] if [ ${EXTRAVERSION:0:1} == "." ]; then
EXTRAVER=${EXTRAVERSION:1} else EXTRAVER=$EXTRAVERSION fi EXTRAVER=${EXTRAVER%%[[:punct:]]*} #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
Quoted 8 lines
fi
part, which the sed expression (moderately successfully) tried to take care of.
The good part of the story is that the current corrected almost fully working version still works with bash (3.1dfsg-8), just like the original patch-kernel version.
Could you (or Randy) fix it up with the comment from Herbert and submit the final version to me (with proper changelog and s-o-b).
Thanks,
Sam
PATCH 1/1 eradicate bashisms in scripts/patch-kernel
Make the patch-kernel shell script sufficiently compatible with POSIX shells,
i.e., remove bashisms from scripts/patch-kernel.
This means that it now also works on dash 0.5.3-5
and still works on bash 3.1dfsg-8.
Full changelog:
- replaced non-standard "==" by standard "="
- replaced non-standard "source" statement by POSIX "dot" command
- use leading ./ on mktemp filename to force the tempfile to a local directory, so that the search path is not used
- replace bash syntax to remove leading dot by similar POSIX syntax
- added missing (optional/not required) $ signs to shell variable names
---
Thanks for all comments! I might want to make sure to read more specs next time...
Cowardly didn't dare to pre-add Randy's line, feel free to ack ;)
scripts/patch-kernel renamed from scripts/patch-kernel.orig +10 -12
@@ -65,7 +65,7 @@ patchdir=${2-.} stopvers=${3-default} -if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then +if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then cat << USAGE usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ] source directory defaults to /usr/src/linux,
@@ -182,10 +182,12 @@ } # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION -TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } +# force $TMPFILEs below to be in local directory: a slash character prevents +# the dot command from using the search path. +TMPFILE=`mktemp ./.tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE tr -d [:blank:] < $TMPFILE > $TMPFILE.1 -source $TMPFILE.1 +. $TMPFILE.1 rm -f $TMPFILE* if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ] then
@@ -202,11 +204,7 @@ EXTRAVER= if [ x$EXTRAVERSION != "x" ] then - if [ ${EXTRAVERSION:0:1} == "." ]; then - EXTRAVER=${EXTRAVERSION:1} - else - EXTRAVER=$EXTRAVERSION - fi + EXTRAVER=${EXTRAVERSION#.} EXTRAVER=${EXTRAVER%%[[:punct:]]*} #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER" fi
@@ -251,16 +249,16 @@ do CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER= - if [ $stopvers == $CURRENTFULLVERSION ]; then + if [ $stopvers = $CURRENTFULLVERSION ]; then echo "Stopping at $CURRENTFULLVERSION base as requested." break fi - SUBLEVEL=$((SUBLEVEL + 1)) + SUBLEVEL=$(($SUBLEVEL + 1)) FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" #echo "#___ trying $FULLVERSION ___" - if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then + if [ $(($SUBLEVEL)) -gt $(($STOPSUBLEVEL)) ]; then echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)" exit 1 fi
@@ -297,7 +295,7 @@ if [ x$gotac != x ]; then # Out great user wants the -ac patches # They could have done -ac (get latest) or -acxx where xx=version they want - if [ $gotac == "-ac" ]; then + if [ $gotac = "-ac" ]; then # They want the latest version HIGHESTPATCH=0 for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.*
Quoted 6 lines · On Sat, 17 Nov 2007 21:51:25 +0100 Andreas Mohr wrote:
Make the patch-kernel shell script sufficiently compatible with POSIX shells,
i.e., remove bashisms fromscripts/patch-kernel.
This means that it now also works on dash 0.5.3-5
and still works on bash 3.1dfsg-8.
Quoted 7 lines
Full changelog:
- replaced non-standard "==" by standard "="
- replaced non-standard "source" statement by POSIX "dot" command
- use leading ./ on mktemp filename to force the tempfile to a local directory, so that the search path is not used
- replace bash syntax to remove leading dot by similar POSIX syntax
- added missing (optional/not required) $ signs to shell variable names
The use of $(($x)) should not be needed with latest dash.... anyway, Acked-by: Randy Dunlap <[email protected]>
Quoted 66 lines
Signed-off-by Andreas Mohr <[email protected]>---
Thanks for all comments! I might want to make sure to read more specs next time...
Cowardly didn't dare to pre-add Randy's line, feel free to ack ;)scripts/patch-kernel renamed from scripts/patch-kernel.orig +9
-11@@ -65,7 +65,7 @@ patchdir=${2-.} stopvers=${3-default} -if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then +if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then cat << USAGE usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ] source directory defaults to /usr/src/linux,@@ -182,10 +182,12 @@ } # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION -TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } +# force $TMPFILEs below to be in local directory: a slash character prevents +# the dot command from using the search path. +TMPFILE=`mktemp ./.tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE tr -d [:blank:] < $TMPFILE > $TMPFILE.1 -source $TMPFILE.1 +. $TMPFILE.1 rm -f $TMPFILE* if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ] then@@ -202,11 +204,7 @@ EXTRAVER= if [ x$EXTRAVERSION != "x" ] then - if [ ${EXTRAVERSION:0:1} == "." ]; then - EXTRAVER=${EXTRAVERSION:1} - else - EXTRAVER=$EXTRAVERSION - fi + EXTRAVER=${EXTRAVERSION#.} EXTRAVER=${EXTRAVER%%[[:punct:]]*} #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER" fi@@ -251,16 +249,16 @@ do CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER= - if [ $stopvers == $CURRENTFULLVERSION ]; then + if [ $stopvers = $CURRENTFULLVERSION ]; then echo "Stopping at $CURRENTFULLVERSION base as requested." break fi - SUBLEVEL=$((SUBLEVEL + 1)) + SUBLEVEL=$(($SUBLEVEL + 1)) FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" #echo "#___ trying $FULLVERSION ___" - if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then + if [ $(($SUBLEVEL)) -gt $(($STOPSUBLEVEL)) ]; then echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)" exit 1 fi
scripts/patch-kernel
Quoted 9 lines
scripts/patch-kernel renamed from scripts/patch-kernel.orig +1
-2@@ -297,7 +295,7 @@ if [ x$gotac != x ]; then # Out great user wants the -ac patches # They could have done -ac (get latest) or -acxx where xx=version they want - if [ $gotac == "-ac" ]; then + if [ $gotac = "-ac" ]; then # They want the latest version HIGHESTPATCH=0 for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.* -
---
~Randy
desserts: http://www.xenotime.net/linux/recipes/
Silence a remaining annoying (or worse, irritating - "is my entire patched tree broken now!?") bashism-related message that occurs when /bin/sh is configured to instead deploy dash, a POSIX-compliant shell, as is the pretty much standard case on e.g. Debian.
# linux-2.6.38.patch-kernel_test/scripts/patch-kernel linux-2.6.38.patch-kernel_test patch-2.6 Current kernel version is 2.6.38 ( Flesh-Eating Bats with Fangs) ===> linux-2.6.38.patch-kernel_test/scripts/patch-kernel: line 253: [: =: unary operator expected <=== cannot find patch file: patch-2.6.39 ---
Debug log of uncorrected script:
# sh -x linux-2.6.38.patch-kernel_test/scripts/patch-kernel linux-2.6.38.patch-kernel_test patch-2.6 + PNAME=patch-kernel + sourcedir=linux-2.6.38.patch-kernel_test + patchdir=patch-2.6 + stopvers=default + '[' linux-2.6.38.patch-kernel_test = -h -o linux-2.6.38.patch-kernel_test = --help -o '!' -r linux-2.6.38.patch-kernel_test/Makefile ']' + for PARM in '$*' + case $PARM in + for PARM in '$*' + case $PARM in ++ mktemp ./.tmpver.XXXXXX + TMPFILE=./.tmpver.2Yv11Y + grep -E '^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)' linux-2.6.38.patch-kernel_test/Makefile + tr -d '[:blank:]' + . ./.tmpver.2Yv11Y.1 ++ VERSION=2 ++ PATCHLEVEL=6 ++ SUBLEVEL=38 ++ EXTRAVERSION= + rm -f ./.tmpver.2Yv11Y ./.tmpver.2Yv11Y.1 + '[' -z 2 -o -z 6 -o -z 38 ']' ++ grep '^NAME' linux-2.6.38.patch-kernel_test/Makefile + NAME='NAME = Flesh-Eating Bats with Fangs' + NAME=' Flesh-Eating Bats with Fangs' + echo 'Current kernel version is 2.6.38 ( Flesh-Eating Bats with Fangs)' Current kernel version is 2.6.38 ( Flesh-Eating Bats with Fangs) + EXTRAVER= + '[' x '!=' x ']' + '[' default '!=' default ']' + STOPSUBLEVEL=9999 + STOPEXTRA=9999 + '[' 9999 -lt 38 ']' + '[' x '!=' x ']' + CURRENTFULLVERSION=2.6.38 + '[' x '!=' x ']' + '[' 9999 -gt 38 ']' + : + CURRENTFULLVERSION=2.6.38 + EXTRAVER= + '[' = 2.6.38 ']' linux-2.6.38.patch-kernel_test/scripts/patch-kernel: line 253: [: =: unary operator expected + SUBLEVEL=39 + FULLVERSION=2.6.39 + '[' 39 -gt 9999 ']' + patch=patch-2.6.39 + findFile patch-2.6/patch-2.6.39 + filebase=patch-2.6/patch-2.6.39 + '[' -r patch-2.6/patch-2.6.39.gz ']' + '[' -r patch-2.6/patch-2.6.39.bz ']' + '[' -r patch-2.6/patch-2.6.39.bz2 ']' + '[' -r patch-2.6/patch-2.6.39.zip ']' + '[' -r patch-2.6/patch-2.6.39.Z ']' + '[' -r patch-2.6/patch-2.6.39 ']' + return 1 + noFile patch-2.6.39 + echo 'cannot find patch file: patch-2.6.39' cannot find patch file: patch-2.6.39 + exit 1
Debug log of patched script (condensed to relevant parts):
+ STOPSUBLEVEL=9999
+ STOPEXTRA=9999
+ '[' 9999 -lt 38 ']'
+ '[' x '!=' x ']'
+ CURRENTFULLVERSION=2.6.38
+ '[' x '!=' x ']'
+ '[' 9999 -gt 38 ']'
+ :
+ CURRENTFULLVERSION=2.6.38
+ EXTRAVER=
+ '[' x = x2.6.38 ']'
+ SUBLEVEL=39
+ FULLVERSION=2.6.39
Since my last patch (the parent mail) happened to modify the very same line, I'm slightly wondering why last time it didn't exhibit this issue (IIRC this occurred for the first time a couple months later, perhaps in newer shell versions).
Patch has been created on git 2.6.39-rc1,
run through checkpatch.pl,
tested to work on dash and still work on bash,
and tested to apply cleanly to 2.6.37, too.
IMHO this is a low-priority item,
certainly not requiring service within current -rc handling, and neither at -stable (I assume that only point versions could make good use of this patch anyway).
IOW standard patch circulation.
I'm assuming that Sam would be the one to queue it up, just like last time.
Thanks!
scripts/patch-kernel +1 -1
@@ -250,7 +250,7 @@ while : # incrementing SUBLEVEL (s in v.p.s) do CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER= - if [ $STOPFULLVERSION = $CURRENTFULLVERSION ]; then + if [ x$STOPFULLVERSION = x$CURRENTFULLVERSION ]; then echo "Stopping at $CURRENTFULLVERSION base as requested." break fi
Quoted 9 lines · On Sun, 3 Apr 2011 20:58:28 +0200 Andreas Mohr wrote:
Silence a remaining annoying (or worse, irritating - "is my entire patched tree broken now!?") bashism-related message that occurs when
/bin/shis configured to instead deploy dash, a POSIX-compliant shell, as is the pretty much standard case on e.g. Debian.# linux-2.6.38.patch-kernel_test/scripts/patch-kernel linux-2.6.38.patch-kernel_test patch-2.6 Current kernel version is 2.6.38 ( Flesh-Eating Bats with Fangs) ===> linux-2.6.38.patch-kernel_test/scripts/patch-kernel: line 253: [: =: unary operator expected <=== cannot find patch file: patch-2.6.39
Hi,
Are you trying to update a 2.6.38 kernel directory to 2.6.39?
I'm a little confused since the command line does not say anything about 2.6.39.
Quoted 83 lines
---
Debug log of uncorrected script:
# sh -x linux-2.6.38.patch-kernel_test/scripts/patch-kernel linux-2.6.38.patch-kernel_test patch-2.6 + PNAME=patch-kernel + sourcedir=linux-2.6.38.patch-kernel_test + patchdir=patch-2.6 + stopvers=default + '[' linux-2.6.38.patch-kernel_test = -h -o linux-2.6.38.patch-kernel_test = --help -o '!' -r linux-2.6.38.patch-kernel_test/Makefile ']' + for PARM in '$*' + case $PARM in + for PARM in '$*' + case $PARM in ++ mktemp ./.tmpver.XXXXXX + TMPFILE=./.tmpver.2Yv11Y + grep -E '^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)' linux-2.6.38.patch-kernel_test/Makefile + tr -d '[:blank:]' + . ./.tmpver.2Yv11Y.1 ++ VERSION=2 ++ PATCHLEVEL=6 ++ SUBLEVEL=38 ++ EXTRAVERSION= + rm -f ./.tmpver.2Yv11Y ./.tmpver.2Yv11Y.1 + '[' -z 2 -o -z 6 -o -z 38 ']' ++ grep '^NAME' linux-2.6.38.patch-kernel_test/Makefile + NAME='NAME = Flesh-Eating Bats with Fangs' + NAME=' Flesh-Eating Bats with Fangs' + echo 'Current kernel version is 2.6.38 ( Flesh-Eating Bats with Fangs)' Current kernel version is 2.6.38 ( Flesh-Eating Bats with Fangs) + EXTRAVER= + '[' x '!=' x ']' + '[' default '!=' default ']' + STOPSUBLEVEL=9999 + STOPEXTRA=9999 + '[' 9999 -lt 38 ']' + '[' x '!=' x ']' + CURRENTFULLVERSION=2.6.38 + '[' x '!=' x ']' + '[' 9999 -gt 38 ']' + : + CURRENTFULLVERSION=2.6.38 + EXTRAVER= + '[' = 2.6.38 ']' linux-2.6.38.patch-kernel_test/scripts/patch-kernel: line 253: [: =: unary operator expected + SUBLEVEL=39 + FULLVERSION=2.6.39 + '[' 39 -gt 9999 ']' + patch=patch-2.6.39 + findFile patch-2.6/patch-2.6.39 + filebase=patch-2.6/patch-2.6.39 + '[' -r patch-2.6/patch-2.6.39.gz ']' + '[' -r patch-2.6/patch-2.6.39.bz ']' + '[' -r patch-2.6/patch-2.6.39.bz2 ']' + '[' -r patch-2.6/patch-2.6.39.zip ']' + '[' -r patch-2.6/patch-2.6.39.Z ']' + '[' -r patch-2.6/patch-2.6.39 ']' + return 1 + noFile patch-2.6.39 + echo 'cannot find patch file: patch-2.6.39' cannot find patch file: patch-2.6.39 + exit 1Debug log of patched script (condensed to relevant parts):
+ STOPSUBLEVEL=9999
+ STOPEXTRA=9999
+ '[' 9999 -lt 38 ']'
+ '[' x '!=' x ']'
+ CURRENTFULLVERSION=2.6.38
+ '[' x '!=' x ']'
+ '[' 9999 -gt 38 ']'
+ :
+ CURRENTFULLVERSION=2.6.38
+ EXTRAVER=
+ '[' x = x2.6.38 ']'
+ SUBLEVEL=39
+ FULLVERSION=2.6.39
Quoted 1 line
Since my last patch (the parent mail) happened to modify the very same line,
Parent email from 2007??? wow. :)
Why doesn't the debug/trace info show the value of STOPFULLVERSION? Is it empty?
Quoted 9 lines
I'm slightly wondering why last time it didn't exhibit this issue (IIRC this occurred for the first time a couple months later, perhaps in newer shell versions).
Patch has been created on git 2.6.39-rc1,
run through checkpatch.pl,
tested to work on dash and still work on bash,
and tested to apply cleanly to 2.6.37, too.
Quoted 7 lines
IMHO this is a low-priority item,
certainly not requiring service within current -rc handling, and neither at -stable (I assume that only point versions could make good use of this patch anyway).
IOW standard patch circulation.
I'm assuming that Sam would be the one to queue it up, just like last time.
Michal is the new kbuild maintainer, so he could queue it, or I can.
Quoted 10 lines
Thanks!
Signed-off-by Andreas Mohr <[email protected]>scripts/patch-kernel +0
-0
scripts/patch-kernel while : # incrementing SUBLEVEL (s in v.p.s) · line 256
Quoted 8 lines
scripts/patch-kernel +1
-1@@ -250,7 +250,7 @@ while : # incrementing SUBLEVEL (s in v.p.s) do CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER= - if [ $STOPFULLVERSION = $CURRENTFULLVERSION ]; then + if [ x$STOPFULLVERSION = x$CURRENTFULLVERSION ]; then echo "Stopping at $CURRENTFULLVERSION base as requested." break fi
Patch is OK, but I still wonder about the value of $STOPFULLVERSION.
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
Hi,
sorry for the delay. Didn't have a suitable environment at that time, then it got buried...
Quoted 10 lines · Randy Dunlap
Quoted 4 lines · On Sun, 3 Apr 2011 20:58:28 +0200 Andreas Mohr wrote:
# linux-2.6.38.patch-kernel_test/scripts/patch-kernel linux-2.6.38.patch-kernel_test patch-2.6 Current kernel version is 2.6.38 ( Flesh-Eating Bats with Fangs) ===> linux-2.6.38.patch-kernel_test/scripts/patch-kernel: line 253: [: =: unary operator expected <=== cannot find patch file: patch-2.6.39Hi,
Are you trying to update a 2.6.38 kernel directory to 2.6.39?
I'm a little confused since the command line does not say anything about 2.6.39.
Well, that virtual setup was just for the sake of having a problem test case. I should have described it in more detail.
It simply tries to increment to the next patch version, which in case of 2.6.38 input would be 2.6.39 (which... obviously isn't available yet).
Quoted 3 lines
Quoted 1 line
Since my last patch (the parent mail) happened to modify the very same line,
Parent email from 2007??? wow. :)
Yup - why not simply reply on the original patch?
For suitable tracking, I'd rather have one reference too many than......
Perhaps I should have replied on some ~1995 mail? ;-P
Quoted 2 lines
Why doesn't the debug/trace info show the value of STOPFULLVERSION? Is it empty?
Augmented version:
do
CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" EXTRAVER=
echo "STOPFULLVERSION is $STOPFULLVERSION"
if [ $STOPFULLVERSION = $CURRENTFULLVERSION ]; then
echo "Stopping at $CURRENTFULLVERSION base as requested." break
fi
# linux-2.6.30/scripts/patch-kernel linux-2.6.30 patch-2.6 Current kernel version is 2.6.30 ( Man-Eating Seals of Antiquity) STOPFULLVERSION is [: 276: =: unexpected operator Applying patch-2.6.31 (bzip2)... done. STOPFULLVERSION is [: 276: =: unexpected operator Applying patch-2.6.32 (bzip2)... done. STOPFULLVERSION is [: 276: =: unexpected operator Applying patch-2.6.33 (bzip2)... done. STOPFULLVERSION is [: 276: =: unexpected operator Applying patch-2.6.34 (bzip2)... done. STOPFULLVERSION is [: 276: =: unexpected operator cannot find patch file: patch-2.6.35
--> seems so.
Quoted 1 line
Michal is the new kbuild maintainer, so he could queue it, or I can.
He's been queueing it immediately, thus everything went fine (--> thanks!).
Thanks,
Andreas Mohr
Quoted 11 lines · Andreas Mohr
Silence a remaining annoying (or worse, irritating - "is my entire patched tree broken now!?") bashism-related message that occurs when
/bin/shis configured to instead deploy dash, a POSIX-compliant shell, as is the pretty much standard case on e.g. Debian.# linux-2.6.38.patch-kernel_test/scripts/patch-kernel linux-2.6.38.patch-kernel_test patch-2.6 Current kernel version is 2.6.38 ( Flesh-Eating Bats with Fangs) ===> linux-2.6.38.patch-kernel_test/scripts/patch-kernel: line 253: [: =: unary operator expected <=== cannot find patch file: patch-2.6.39Signed-off-by Andreas Mohr <[email protected]>
Applied to kbuild-2.6.git#misc, thanks.
Michal
Quoted 1 line · Andreas Mohr
Hello,
Hi Andreas,
Quoted 10 lines
I was non-mildly horrified to find that the rather widely used patch-kernel script seems to rely on bash despite specifying the interpreter as #!/bin/sh, since my dash-using Debian install choked on it.
Thus I'm delivering a first, preliminary, non-reviewed change to make patch-kernel (a little bit more?) POSIX-compatible. It now survives both a dash and a bash run.
...
Comments?
...
if that's easyly possible it's OK.
But if it becomes possible I'd strongly favour simply changing the interpreter to #!/bin/bash which would also fix this problem.
Quoted 4 lines
Thanks,
Andreas Mohr
...
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed