core194: Fix cert name and change other check to ! -z

Message ID 20250430141746.44261-1-adolf.belka@ipfire.org
State Superseded
Headers
Series core194: Fix cert name and change other check to ! -z |

Commit Message

Adolf Belka April 30, 2025, 2:17 p.m. UTC
  - Error in hostcert extension
- -z gives true if not zero and we need true if it is zero so had to add not command.
- I thought I had tested the original patch of this change but obviously not because
   there was missing whitespace and filenames not quoted plus the fixes I have added
   in this patch.
- I definitely tested this out this time by copying it from the update.sh and applying
   it to my vm system.

Tested-by: Adolf Belka <adolf.belka@ipfire.org>
Signed-off-by: Adolf Belka <adolf.belka@ipfire.org>
---
 config/rootfiles/core/194/update.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Nick Howitt April 30, 2025, 2:53 p.m. UTC | #1
Can I ask what you are testing here with the "! -z"? Typically you would 
use "-n" rather than "! -z", but both are tests for strings and not 
files - https://tldp.org/LDP/abs/html/comparison-ops.html. "! -s" would 
test for a zero length file and if the file exists at all.

Nick

On 30/04/2025 15:17, Adolf Belka wrote:
> - Error in hostcert extension
> - -z gives true if not zero and we need true if it is zero so had to add not command.
> - I thought I had tested the original patch of this change but obviously not because
>     there was missing whitespace and filenames not quoted plus the fixes I have added
>     in this patch.
> - I definitely tested this out this time by copying it from the update.sh and applying
>     it to my vm system.
>
> Tested-by: Adolf Belka<adolf.belka@ipfire.org>
> Signed-off-by: Adolf Belka<adolf.belka@ipfire.org>
> ---
>   config/rootfiles/core/194/update.sh | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/config/rootfiles/core/194/update.sh b/config/rootfiles/core/194/update.sh
> index b758c7bf6..8fbf22750 100644
> --- a/config/rootfiles/core/194/update.sh
> +++ b/config/rootfiles/core/194/update.sh
> @@ -104,7 +104,7 @@ ldconfig
>   /usr/local/bin/filesystem-cleanup
>   
>   # Increment ipsec serial file if x509 certificates present and no content in index.txt
> -if [ -e "/var/ipfire/certs/hostcert.pm" ] && [ -z "/var/ipfire/certs/index.txt" ]; then
> +if [ -e "/var/ipfire/certs/hostcert.pem" ] && [ ! -z "/var/ipfire/certs/index.txt" ]; then
>       sed -i "s/01/02/" /var/ipfire/certs/serial
>   fi
>
  
Adolf Belka April 30, 2025, 4:29 p.m. UTC | #2
Hi Nick,

On 30/04/2025 16:53, Nick Howitt wrote:
> Can I ask what you are testing here with the "! -z"? Typically you would use "-n" rather than "! -z", but both are tests for strings and not files - https://tldp.org/LDP/abs/html/comparison-ops.html. "! -s" would test for a zero length file and if the file exists at all.

Thanks for the input. You are absolutely correct. I tested my script but only with index.txt empty. I just tried it with something in index.txt and it still detected it as empty because, as you point out -s is for the file test while -z is for the string test. So in my case it is checking if the string "/var/ipfire/certs/index.txt" is not empty, which of course it will never be empty.

Duuuh.

I just tried it with -z replaced by -s and that properly detects if the file is empty or not.


Hi Michael,

Could you please change the ! -z to ! -s in my last patch or should I send out a v2 patch?

Regards,

Adolf.

> 
> Nick
> 
> On 30/04/2025 15:17, Adolf Belka wrote:
>> - Error in hostcert extension
>> - -z gives true if not zero and we need true if it is zero so had to add not command.
>> - I thought I had tested the original patch of this change but obviously not because
>>     there was missing whitespace and filenames not quoted plus the fixes I have added
>>     in this patch.
>> - I definitely tested this out this time by copying it from the update.sh and applying
>>     it to my vm system.
>>
>> Tested-by: Adolf Belka<adolf.belka@ipfire.org>
>> Signed-off-by: Adolf Belka<adolf.belka@ipfire.org>
>> ---
>>   config/rootfiles/core/194/update.sh | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/config/rootfiles/core/194/update.sh b/config/rootfiles/core/194/update.sh
>> index b758c7bf6..8fbf22750 100644
>> --- a/config/rootfiles/core/194/update.sh
>> +++ b/config/rootfiles/core/194/update.sh
>> @@ -104,7 +104,7 @@ ldconfig
>>   /usr/local/bin/filesystem-cleanup
>>   
>>   # Increment ipsec serial file if x509 certificates present and no content in index.txt
>> -if [ -e "/var/ipfire/certs/hostcert.pm" ] && [ -z "/var/ipfire/certs/index.txt" ]; then
>> +if [ -e "/var/ipfire/certs/hostcert.pem" ] && [ ! -z "/var/ipfire/certs/index.txt" ]; then
>>       sed -i "s/01/02/" /var/ipfire/certs/serial
>>   fi
>>   
>
  

Patch

diff --git a/config/rootfiles/core/194/update.sh b/config/rootfiles/core/194/update.sh
index b758c7bf6..8fbf22750 100644
--- a/config/rootfiles/core/194/update.sh
+++ b/config/rootfiles/core/194/update.sh
@@ -104,7 +104,7 @@  ldconfig
 /usr/local/bin/filesystem-cleanup
 
 # Increment ipsec serial file if x509 certificates present and no content in index.txt
-if [ -e "/var/ipfire/certs/hostcert.pm" ] && [ -z "/var/ipfire/certs/index.txt" ]; then
+if [ -e "/var/ipfire/certs/hostcert.pem" ] && [ ! -z "/var/ipfire/certs/index.txt" ]; then
     sed -i "s/01/02/" /var/ipfire/certs/serial
 fi