fixes to the service file; + former stub /etc/init.d/plc becomes /usr/bin/plc-ctl
[myplc.git] / plc.d / ssl
index ab64a80..f09294a 100755 (executable)
--- a/plc.d/ssl
+++ b/plc.d/ssl
@@ -1,6 +1,4 @@
 #!/bin/bash
-# $Id$
-# $URL$
 #
 # priority: 300
 #
@@ -21,7 +19,7 @@ set -x
 ssl_cname ()
 {
     openssl x509 -noout -in $1 -subject | \
-       sed -n -e 's@.*/CN=\([^/]*\).*@\1@p' | \
+       sed -e 's|.*CN *= *\([-_a-zA-Z0-9.]*\).*|\1|' | \
        lower
 }
 
@@ -49,9 +47,8 @@ verify_or_generate_certificate() {
 
     if [ -f $crt ] ; then
        # Check if certificate is valid
-       verify=$(openssl verify -CAfile $ca $crt)
        # Backup if invalid or if the subject has changed
-       if grep -q "error" <<<$verify || \
+       if openssl verify -CAfile $ca $crt | grep -q "error" || \
            [ "$(ssl_cname $crt)" != "$cname" ] ; then
             backup_file $crt
             backup_file $ca