#!/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/iFlip721/tvapp2
#   @repo.2         https://github.com/Aetherinox/tvapp2
#   @repo.3         https://git.binaryninja.net/BinaryNinja/tvapp2
#   @repo.alpine    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
    openssl req -new -x509 -days 3650 -nodes -out /config/keys/cert.crt -keyout /config/keys/cert.key -subj "$SUBJECT"
fi
