open-power/sb-signing-utils

crtSignedContainer.sh issue with ini file parsing

cjengel opened this issue · 6 comments

The version of bash on some build machines doesn't support the -g option on declare that is used in the ini file parsing.

-bash-4.1$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)

-bash-4.1$ cat /etc/redhat-release
Red Hat Enterprise Linux Workstation release 6.4 (Santiago)

According to Pam openpower builds are done on RH7 but FIPS builds are done on RH6

[cengel@fatcat sb-signing-utils]$ ./crtSignedContainer.sh -m production -l ../sb-signing-framework/src/client/opPubKey -L "OP KEY" -i KeySig --sign-project-config ./setup.ini
--> crtSignedContainer.sh: Parsing INI file: ./setup.ini
./crtSignedContainer.sh: line 143: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
./crtSignedContainer.sh: line 143: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
crtSignedContainer.sh: Production mode selected but no signer userid provided

Looks like "declare -g" is not as universally implemented as I hoped. I'm using that to allow variables to be declared within the parseIni(), that may be accessed by the calling code. Without that, parseIni() can't be in its own function.
There should be a way to implement it that way that does not require -g. I will address it.

It looks like I can use "eval" here in place of "declare", as long as I quote it properly. I am testing a patch now, just to make sure it handles all the required cases. (properly handles spaces, etc., in the INI file)

Please test the following patch on the system where it's failing. Be sure to test with some values in the INI file that have spaces in the pathname, to make sure it handles them properly. Like the path to the SF pkey and epwd, or the path to the file containing the hash to verify against.

In testing, I found I has some additional issues in the path handling, which should now be fixed with the latest commit (a132b99). So please test against this commit or later. Thx -Dave

diff --git a/crtSignedContainer.sh b/crtSignedContainer.sh
index 8551e02..e762f48 100755
--- a/crtSignedContainer.sh
+++ b/crtSignedContainer.sh
@@ -139,9 +139,9 @@ parseIni () {
             section=$(echo $property | tr -d [] )
         elif test -n "$value"
         then
             # This is a property, set it
-            declare -g "${section}_${property}=$value"
+            eval "${section}_${property}=\"$value\""
         fi
     done < "$1"
 }

The suggested patch resolves the issue on RHEL6

Checked in as commit e928550.

Fixed, closing.