title: Bash script to update path to ssl certificate file in ssl.conf
body: <p>I am creating a reusable script for automating the setup of new SSLs on server setups. I have a few different lines that need to get the file paths updated.</p>
  
  <p>The defaults in the ssl.conf file look like this (One has leading # tag):</p>
  
  <pre><code>SSLCertificateFile /etc/pki/tls/certs/localhost.crt
  </code></pre>
  
  <p>I need it to be dynamically set in the bash script, to end up like this:</p>
  
  <pre><code>SSLCertificateFile /etc/pki/tls/certs/example.crt
  </code></pre>
  
  <p>So far I started out with this, but i'm not sure what I'm doing.</p>
  
  <pre><code>~/update_ssl_conf.sh
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>#!/bin/bash
  SSL_CONFIG_PATH="/etc/httpd/conf.d/ssl.conf"
  
  SSL_DEFAULT_CERT_PATH="SSLCertificateFile /etc/pki/tls/certs/localhost.crt"
  SSL_CERT_PATH="SSLCertificateFile /etc/pki/tls/certs/example.crt"
  sed "s/.*\b$SSL_DEFAULT_CERT_PATH\b.*/$SSL_CERT_PATH/" $SSL_CONFIG_PATH
  </code></pre>
  
  <p>***UPDATED AREA, Also need sed command to update lines that begin with #.</p>
  
  <p>The defaults in the ssl.conf file look like this (Has leading # tag):</p>
  
  <pre><code>#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
  </code></pre>
  
  <p>I need it to be dynamically set in the bash script, to end up like this:</p>
  
  <pre><code> SSLCACertificateFile /etc/pki/tls/certs/example-ca-bundle.crt
  </code></pre>
  
  <p>So far I started out with this, but i'm not sure what I'm doing.</p>
  
  <pre><code>~/update_ssl_conf.sh
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>#!/bin/bash
  SSL_CONFIG_PATH="/etc/httpd/conf.d/ssl.conf"
  
  SSL_DEFAULT_CA_CERT_PATH="#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt" 
  SSL_CA_CERT_PATH="SSLCACertificateFile /etc/pki/tls/certs/example-ca-bundle.crt"
  </code></pre>
  
  <p>I tried from the accepted solution for the </p>
  
  <pre><code>sed -i "s|.*\b#$SSL_DEFAULT_CA_CERT_PATH\b.*|$SSL_CA_CERT_PATH|" SSL_CONFIG_PATH
  </code></pre>
  
  <p>and </p>
  
  <pre><code>sed -i "s|(?s).*(?&lt;!\\w)$SSL_DEFAULT_CA_CERT_PATH(?!\\w).*|$SSL_CA_‌​CERT_PATH|" $SSL_CONFIG_PATH
  </code></pre>
  
  <p>neither are working because the regular expression is not correct. </p>