|
3 | 3 | # Copy custom CA certificates to system trusted CA certificates folder
|
4 | 4 | # and run CA update utility
|
5 | 5 |
|
| 6 | +if [[ -e "/etc/debian_version" ]]; then |
| 7 | + ca_dst_path="/usr/local/share/ca-certificates" |
| 8 | + update_command="update-ca-certificates" |
| 9 | +elif [[ -e "/etc/redhat-release" ]]; then |
| 10 | + ca_dst_path="/etc/pki/ca-trust/source/anchors" |
| 11 | + update_command="update-ca-trust" |
| 12 | +else |
| 13 | + echo "Unsupported OS" |
| 14 | + exit 1 |
| 15 | +fi |
| 16 | + |
| 17 | +# Initialize update_needed variable |
| 18 | +update_needed="false" |
| 19 | + |
6 | 20 | # Remove old certificates
|
7 |
| -rm -f /usr/local/share/ca-certificates/kolla-customca-* \ |
8 |
| - /etc/pki/ca-trust/source/anchors/kolla-customca-* |
| 21 | +if find /etc/ssl/certs/ \ |
| 22 | + /usr/local/share/ca-certificates/ \ |
| 23 | + /etc/pki/ca-trust/source/anchors/ \ |
| 24 | + -name 'kolla*' -exec rm -f {} + 2>/dev/null; then |
| 25 | + update_needed="true" |
| 26 | +fi |
| 27 | + |
| 28 | +# Determine source path for CA certificates |
| 29 | +if grep -q '"source": "/var/lib/kolla/share/ca-certificates"' /etc/kolla/defaults/state; then |
| 30 | + ca_src_path="/var/lib/kolla/share/ca-certificates" |
| 31 | +else |
| 32 | + ca_src_path="/var/lib/kolla/config_files/ca-certificates" |
| 33 | +fi |
| 34 | + |
| 35 | +# Check if the source path exists and is not empty |
| 36 | +if [[ -d ${ca_src_path} && $(ls -A "${ca_src_path}" 2>/dev/null) ]]; then |
| 37 | + # Copy certificates and update CA |
| 38 | + for cert in "${ca_src_path}"/*; do |
| 39 | + file=$(basename "${cert}") |
| 40 | + cp ${cert} ${ca_dst_path}/kolla-customca-${file} |
| 41 | + update_needed="true" |
| 42 | + done |
| 43 | +fi |
9 | 44 |
|
10 |
| -if [[ -d /var/lib/kolla/config_files/ca-certificates ]] && \ |
11 |
| - [[ ! -z "$(ls -A /var/lib/kolla/config_files/ca-certificates/)" ]]; then |
12 |
| - if [[ -e /etc/debian_version ]]; then |
13 |
| - # Debian, Ubuntu |
14 |
| - for cert in /var/lib/kolla/config_files/ca-certificates/*; do |
15 |
| - file=$(basename "$cert") |
16 |
| - cp $cert "/usr/local/share/ca-certificates/kolla-customca-$file" |
17 |
| - done |
18 |
| - update-ca-certificates |
19 |
| - elif [[ -e /etc/redhat-release ]]; then |
20 |
| - # CentOS |
21 |
| - for cert in /var/lib/kolla/config_files/ca-certificates/*; do |
22 |
| - file=$(basename "$cert") |
23 |
| - cp $cert "/etc/pki/ca-trust/source/anchors/kolla-customca-$file" |
24 |
| - done |
25 |
| - update-ca-trust |
26 |
| - fi |
| 45 | +# Run the update command if needed |
| 46 | +if [[ "${update_needed}" == "true" ]]; then |
| 47 | + ${update_command} |
27 | 48 | fi
|
0 commit comments