jcnelson / vdev

A device-file manager for *nix
GNU General Public License v3.0
101 stars 13 forks source link

disk.sh eval error #88

Closed suedi closed 8 years ago

suedi commented 8 years ago

We discussed before the error in my logs saying.

/usr/lib/vdev/disk.sh: eval: line 530: syntax error near unexpected token `('
/usr/lib/vdev/disk.sh: eval: line 530: `APPLICATION_ID=GENISOIMAGE\ ISO\ 9660/HFS\ FILESYSTEM\ CREATOR\ (C)\ 1993\ E.YOUNGDALE\ (C)\ 1997-2006\ J.PEARSON/J.SCHILLING\ (C)\ 2006-2007\ CDRKIT\ TEAM'

Its origins is in disk.sh the line eval "$BLKID_DATA"

In my case BLKID_DATA contains

"DEVNAME=/dev/sda4
SYSTEM_ID=LINUX
UUID=2013-01-09-16-00-24-00
BOOT_SYSTEM_ID=EL\ TORITO\ SPECIFICATION
APPLICATION_ID=GENISOIMAGE\ ISO\ 9660/HFS\ FILESYSTEM\ CREATOR\ (C)\ 1993\ E.YOUNGDALE\ (C)\ 1997-2006\ J.PEARSON/J.SCHILLING\ (C)\ 2006-2007\ CDRKIT\ TEAM
LABEL=CDROM
TYPE=iso9660
USAGE=filesystem
PART_ENTRY_SCHEME=dos
PART_ENTRY_UUID=e3102a4b-04
PART_ENTRY_TYPE=0x0
PART_ENTRY_NUMBER=4
PART_ENTRY_OFFSET=72299720
PART_ENTRY_SIZE=160252
PART_ENTRY_DISK=8:0"

the APPLICATION_ID contains special unescaped characters in this case paranthesis

This probably could happen in other cases so you might wanna escape them.

From what I can tell you don't use all attributes so maybe can cut away those parts to avoid the problem.

What do you think?

suedi commented 8 years ago

I eyed the code in disk.sh and on line 498 and forwards I think you list the keys you are interested in and then BLKID_DATA could possibly cleaned by grep'ing them like

BLKID_DATA="$(echo "$BLKID_DATA" | /bin/egrep "^PART_ENTRY*|^WWN*|^USAGE*|^TYPE*|^PTTYPE*|^PTUUID*|^PARTLABEL*|^PARTUUID*|^LABEL*|^UUID*")"

This before eval "$BLKID_DATA" statement

This does work and bypasses the problem of '(' paranthesis in the APPLICATION_ID attribute however I dunnow how frequent there would be this kind of characters in blkid output.

so maybe just ignore? Maybe is just a very very special case?

What do you think?

jcnelson commented 8 years ago

At a high-level that's what needs to happen--the variable values need to be properly escaped to avoid the errors you were seeing.

Instead of removing variables, what if we did something like this?

BLKID_DATA="$(echo "$BLKID_DATA" | /bin/sed "s/^\([^=]\+\)=\(.*\)$/\1='\2'/g")"

This would literal-quote everything on the right-hand side of each variable assignment.

Example test:

$ cat /tmp/test.sh 
echo "DEVNAME=/dev/sda4
SYSTEM_ID=LINUX
UUID=2013-01-09-16-00-24-00
BOOT_SYSTEM_ID=EL\ TORITO\ SPECIFICATION
APPLICATION_ID=GENISOIMAGE\ ISO\ 9660/HFS\ FILESYSTEM\ CREATOR\ (C)\ 1993\ E.YOUNGDALE\ (C)\ 1997-2006\ J.PEARSON/J.SCHILLING\ (C)\ 2006-2007\ CDRKIT\ TEAM
LABEL=CDROM
TYPE=iso9660
USAGE=filesystem
PART_ENTRY_SCHEME=dos
PART_ENTRY_UUID=e3102a4b-04
PART_ENTRY_TYPE=0x0
PART_ENTRY_NUMBER=4
PART_ENTRY_OFFSET=72299720
PART_ENTRY_SIZE=160252
PART_ENTRY_DISK=8:0"

$ dash
$ eval "$(dash /tmp/test.sh | sed "s/^\([^=]\+\)=\(.*\)$/\1='\2'/g")"
$ echo $APPLICATION_ID
GENISOIMAGE\ ISO\ 9660/HFS\ FILESYSTEM\ CREATOR\ (C)\ 1993\ E.YOUNGDALE\ (C)\ 1997-2006\ J.PEARSON/J.SCHILLING\ (C)\ 2006-2007\ CDRKIT\ TEAM

It works for me in both bash and dash. Does that work for you in disk.sh?

suedi commented 8 years ago

That's a beautiful solution.

Tested it just now - Works!

Will close this issue when you committed the solution.

jcnelson commented 8 years ago

Just pushed to master :)

suedi commented 8 years ago

Thank you very much!

closing...