#!/usr/bin/with-contenv bash
# shellcheck shell=bash

# #
#   @project        TVApp2
#   @usage          Automatic m3u and xml guide updater for TheTvApp, TVPass, and MoveOnJoy utilized within your IPTV client.
#   @file           run
#   @repo.1         https://github.com/TheBinaryNinja/tvapp2
#   @repo.2         https://git.binaryninja.net/BinaryNinja/tvapp2
#   @repo.3         https://github.com/aetherinox/docker-base-alpine
# #

SUBJECT="/C=NA/ST=NA/L=NA/O=BinaryNinja/OU=TVApp2 Docker Image/CN=*"
if [[ -f /config/keys/cert.key && -f /config/keys/cert.crt ]]; then
    echo -e " SSL          : Using existing keys found in /config/keys"
else
    echo -e " SSL          : Generating self-signed keys in folder/config/keys. Replace if needed."
    rm -f \
        /config/keys/cert.key \
        /config/keys/cert.crt || true

    mkdir -p /config/keys

    OUT=$(openssl req -new -x509 -days 3650 -nodes -out /config/keys/cert.crt -keyout /config/keys/cert.key -subj "$SUBJECT" 2>/dev/null)
fi
