dataset/seed/host-systemd-machined/templates/tls-script

48 lines
1.4 KiB
Text
Raw Normal View History

2023-06-23 08:12:05 +02:00
#!/bin/bash
2023-02-14 14:24:16 +01:00
set -e
2023-06-23 08:12:05 +02:00
{% set ns = namespace(tls_dir=None) %}
{% for machine in machined.machines %}
{% if not ns.tls_dir %}
{% set nor_machine = machine|normalize_family %}
{% set ns.tls_dir = machined['machine_' + nor_machine]['tls_dir_' + nor_machine] %}
{% endif %}
{% endfor %}
{% if ns.tls_dir %}
{% set dst_dir = machined['machine_' + rougail_variable|normalize_family]['config_dir_' + rougail_variable|normalize_family] %}
{% set src_dir = ns.tls_dir + "/machines/" + rougail_variable %}
{% if 'certificates' in extra_variables and rougail_variable in extra_variables['certificates'] %}
if [ -d "{{ dst_dir }}" ] && [ -d "{{ src_dir }}" ]; then
{% for certificate in extra_variables['certificates'][rougail_variable] %}
{% set files = [certificate.name] %}
2023-08-02 09:26:54 +02:00
{% if certificate.provider == 'self-signed' %}
2023-06-23 08:12:05 +02:00
{{ files.append(certificate.authority) }}
{% endif %}
{% if 'private' in certificate %}
{{ files.append(certificate.private) }}
{% endif %}
{% for file in files %}
src_file="{{ src_dir }}{{ file}}"
dst_file="{{dst_dir}}{{ file }}"
2023-02-14 14:24:16 +01:00
dst_dir=$(dirname "$dst_file")
mkdir -p "$dst_dir"
# ne fonctionne pas avec revprox :/
# a=1
# while [ ! -f "$src_file" ]; do
# a=$((a+1));
# if [ $a = 120 ]; then
# break
# fi
# sleep 1
# done
cp -f "$src_file" "$dst_file"
chown root: "$dst_file"
chmod 700 "$dst_file"
2023-06-23 08:12:05 +02:00
{% endfor %}
{% endfor %}
2023-02-14 14:24:16 +01:00
fi
2023-06-23 08:12:05 +02:00
{% endif %}
{% endif %}
2023-02-14 14:24:16 +01:00
exit 0