#!/bin/sh

. /lib/functions.sh

CFG="certificates"
CONFIG_PATH="${UCI_CONFIG_DIR:-"/etc/config"}"

[ ! -e "$CONFIG_PATH/$CFG" ] && touch "$CONFIG_PATH/$CFG"

uci_show certificates | grep -q "certificates.*name='root_ca'" &&
    exit 0

uci_add certificates certificate

uci_set "$CFG" "$CONFIG_SECTION" datetime '-'
uci_set "$CFG" "$CONFIG_SECTION" type 'cert'
uci_set "$CFG" "$CONFIG_SECTION" name 'root_ca'
uci_set "$CFG" "$CONFIG_SECTION" cert_type 'root_ca'
uci_set "$CFG" "$CONFIG_SECTION" key_size '-'
uci_set "$CFG" "$CONFIG_SECTION" fullname 'ca-certificates.crt'
uci_set "$CFG" "$CONFIG_SECTION" path '/etc/ssl/certs/ca-certificates.crt'

uci_commit "$CFG"
exit 0
