Skip to contentSkip to conversation

sdcard_image-rpi.bbclass: Fix error in conditional test

PATCH Applied seth bollinger 4 participants 7 messages Apr 25, 2013 – May 3, 2013 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sdcard_image-rpi.bbclass: Fix error in conditional test

When the shell tests for rootfs type I was seeing "[[: not found". I use echo and egrep to test for the xz rootfs type to work around this error.

---
 classes/sdcard_image-rpi.bbclass |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
classes/sdcard_image-rpi.bbclass +0 -0
index 421f561..7fe7c35 100644
@@ -99,7 +99,7 @@ IMAGE_CMD_rpi-sdimg () {
     # Burn Partitions
     dd if=${WORKDIR}/boot.img of=${SDIMG} conv=notrunc seek=1 

bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
# If SDIMG_ROOTFS_TYPE is a .xz file use xzcat
- if [[ "$SDIMG_ROOTFS_TYPE" == *.xz ]]
+ if echo "${SDIMG_ROOTFS_TYPE}" | egrep -q "*\.xz"

     then
         xzcat ${SDIMG_ROOTFS} | dd of=${SDIMG} conv=notrunc seek=1 

bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
else

Signature · 1 line
1.7.2.5

From 26b0b8b79376eea69aeaf91daf43bc6807a09dd0 Mon Sep 17 00:00:00 2001
From: Seth Bollinger <[email protected]>
Date: Mon, 22 Apr 2013 07:23:45 -0500
Subject: [PATCH 1/2] sdcard_image-rpi.bbclass: Fix error in conditional test

When the shell tests for rootfs type I was seeing "[[: not found". I use echo and egrep to test for the xz rootfs type to work around this error.

---
 classes/sdcard_image-rpi.bbclass |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
classes/sdcard_image-rpi.bbclass +1 -1
index 421f561..7fe7c35 100644
@@ -99,7 +99,7 @@ IMAGE_CMD_rpi-sdimg () {
 	# Burn Partitions
 	dd if=${WORKDIR}/boot.img of=${SDIMG} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
 	# If SDIMG_ROOTFS_TYPE is a .xz file use xzcat
-	if [[ "$SDIMG_ROOTFS_TYPE" == *.xz ]]
+	if echo "${SDIMG_ROOTFS_TYPE}" | egrep -q "*\.xz"
 	then
 		xzcat ${SDIMG_ROOTFS} | dd of=${SDIMG} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
 	else
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 4 lines · seth bollinger

When the shell tests for rootfs type I was seeing "[[: not found". I use echo and egrep to test for the xz rootfs type to work around this error.

'[[' should be a bash builtin. What host OS are you using for the build?

Also what's the exact error message? I'm wondering if this is somehow being ran in a shell that isn't bash. With an unknown command 'abcd', bash gives me "abcd: command not found" and dash gives me "dash: 1:
abcd: not found".

Using egrep for a test like this seems less readable to me.

--
Paul Barker

Email: [email protected]
http://www.paulbarker.me.uk

#2 lore raw

2013/4/25 Paul Barker <[email protected]>:

Quoted 7 lines · seth bollinger
Quoted 4 lines

When the shell tests for rootfs type I was seeing "[[: not found". I use echo and egrep to test for the xz rootfs type to work around this error.

'[[' should be a bash builtin. What host OS are you using for the build?

It sounds like Ubuntu / dash to me:

samuel@s-stirtzel-linux:~$ dash
$ [[
dash: 1: [[: not found

Or at least dash will produce this error too.

--
Regards
Samuel

A message that is not in the archive (sent off-list or not yet received): CA+JN8xMvcoaLKufSeCLO21ozH542OG-uZSn8fDS0OVMGXkUNbw@mail.gmail.com

#4 lore raw
Quoted 7 lines · Seth Bollinger
Quoted 2 lines · Paul Barker

'[[' should be a bash builtin. What host OS are you using for the build?

I'm using debian. I'll check what the default shell is. You're right, it's probably dash.

Try 'sudo dpkg-reconfigure dash'.

Quoted 4 lines

However, should this fail silently then? In this instance I only saw the error with debug enabled. Otherwise it silently tried to dd a compressed image to the sd card. Of course this didn't run. :)

I assume that 'if' tries to run the command, gets a non-zero return value as the command doesn't run and just interprets this as the command running but returning non-zero.

--
Paul Barker

Email: [email protected]
http://www.paulbarker.me.uk

#5 lore raw
Quoted 13 lines · Paul Barker
Quoted 1 line · Seth Bollinger

On Thu, Apr 25, 2013 at 7:38 AM, Paul Barker <[email protected]>

Quoted 4 lines · wrote:
Quoted 2 lines

'[[' should be a bash builtin. What host OS are you using for the build?

I'm using debian. I'll check what the default shell is. You're right,

it's

Quoted 2 lines

probably dash.

Try 'sudo dpkg-reconfigure dash'.

Quoted 10 lines
Quoted 4 lines

However, should this fail silently then? In this instance I only saw the error with debug enabled. Otherwise it silently tried to dd a compressed image to the sd card. Of course this didn't run. :)

I assume that 'if' tries to run the command, gets a non-zero return value as the command doesn't run and just interprets this as the command running but returning non-zero.

I think I asked Seth a while ago and he confirmed that bash was his shell. I thought about dash as well. But as a matter of fact we should remove bashisms and make things as usable as possible. So maybe his patch makes sense after all.

Signature · 2 lines
*Andrei Gherzan*
m: +40.744.478.414 |  f: +40.31.816.28.12
#6 lore raw
Quoted 5 lines · Andrei Gherzan

I think I asked Seth a while ago and he confirmed that bash was his shell. I thought about dash as well. But as a matter of fact we should remove bashisms and make things as usable as possible. So maybe his patch makes sense after all.

Based on Paul Eggleton's reply elsewhere:

Quoted 5 lines · Paul Eggleton
Quoted 2 lines · On Wednesday 01 May 2013 19:13:19 seth bollinger wrote:

2. I couldn't find a wildcard string search in dash. Can anyone suggest a more shell agnostic way to do this?

AFAIK grep or awk is the only way.

I think this patch probably does make sense.

--
Paul Barker

Email: [email protected]
http://www.paulbarker.me.uk

#7 lore raw

Merged to master.

Thanks a lot.

Quoted 25 lines · Paul Barker
Quoted 1 line · Andrei Gherzan

I think I asked Seth a while ago and he confirmed that bash was his

shell. I

Quoted 4 lines

thought about dash as well. But as a matter of fact we should remove bashisms and make things as usable as possible. So maybe his patch makes sense after all.

Based on Paul Eggleton's reply elsewhere:

Quoted 5 lines · Paul Eggleton
Quoted 2 lines · On Wednesday 01 May 2013 19:13:19 seth bollinger wrote:

2. I couldn't find a wildcard string search in dash. Can anyone suggest a more shell agnostic way to do this?

AFAIK grep or awk is the only way.

I think this patch probably does make sense.

--
Paul Barker

Email: [email protected]
http://www.paulbarker.me.uk

Signature · 2 lines
*Andrei Gherzan*
m: +40.744.478.414 |  f: +40.31.816.28.12