Skip to content

Commit 22d6a6a

Browse files
andim2sravnborg
authored andcommitted
kbuild: 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 Signed-off-by: Andreas Mohr <[email protected]> Acked-by: Randy Dunlap <[email protected]> Signed-off-by: Sam Ravnborg <[email protected]>
1 parent 7491a76 commit 22d6a6a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

scripts/patch-kernel

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ sourcedir=${1-/usr/src/linux}
6565
patchdir=${2-.}
6666
stopvers=${3-default}
6767

68-
if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then
68+
if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then
6969
cat << USAGE
7070
usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
7171
source directory defaults to /usr/src/linux,
@@ -182,10 +182,12 @@ reversePatch () {
182182
}
183183

184184
# set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
185-
TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; }
185+
# force $TMPFILEs below to be in local directory: a slash character prevents
186+
# the dot command from using the search path.
187+
TMPFILE=`mktemp ./.tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; }
186188
grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE
187189
tr -d [:blank:] < $TMPFILE > $TMPFILE.1
188-
source $TMPFILE.1
190+
. $TMPFILE.1
189191
rm -f $TMPFILE*
190192
if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ]
191193
then
@@ -202,11 +204,7 @@ echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION} ($
202204
EXTRAVER=
203205
if [ x$EXTRAVERSION != "x" ]
204206
then
205-
if [ ${EXTRAVERSION:0:1} == "." ]; then
206-
EXTRAVER=${EXTRAVERSION:1}
207-
else
208-
EXTRAVER=$EXTRAVERSION
209-
fi
207+
EXTRAVER=${EXTRAVERSION#.}
210208
EXTRAVER=${EXTRAVER%%[[:punct:]]*}
211209
#echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
212210
fi
@@ -251,16 +249,16 @@ while : # incrementing SUBLEVEL (s in v.p.s)
251249
do
252250
CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
253251
EXTRAVER=
254-
if [ $stopvers == $CURRENTFULLVERSION ]; then
252+
if [ $stopvers = $CURRENTFULLVERSION ]; then
255253
echo "Stopping at $CURRENTFULLVERSION base as requested."
256254
break
257255
fi
258256

259-
SUBLEVEL=$((SUBLEVEL + 1))
257+
SUBLEVEL=$(($SUBLEVEL + 1))
260258
FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
261259
#echo "#___ trying $FULLVERSION ___"
262260

263-
if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then
261+
if [ $(($SUBLEVEL)) -gt $(($STOPSUBLEVEL)) ]; then
264262
echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)"
265263
exit 1
266264
fi
@@ -297,7 +295,7 @@ fi
297295
if [ x$gotac != x ]; then
298296
# Out great user wants the -ac patches
299297
# They could have done -ac (get latest) or -acxx where xx=version they want
300-
if [ $gotac == "-ac" ]; then
298+
if [ $gotac = "-ac" ]; then
301299
# They want the latest version
302300
HIGHESTPATCH=0
303301
for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.*

0 commit comments

Comments
 (0)