#!/usr/bin/with-contenv bash

# Exit if not gui
if [ "$YTDL_SUB_TYPE" != "gui" ] ; then
    exit 0
fi

echo "Checking ytdl-sub-gui defaults..."

# copy config
[[ ! -e /config/ytdl-sub-configs/config.yaml ]] && \
    mkdir -p /config/ytdl-sub-configs && \
    cp /defaults/config.yaml /config/ytdl-sub-configs/config.yaml
[[ ! -e /config/ytdl-sub-configs/subscriptions.yaml ]] && \
    mkdir -p /config/ytdl-sub-configs && \
    cp /defaults/subscriptions.yaml /config/ytdl-sub-configs/subscriptions.yaml
[[ ! -d /config/ytdl-sub-configs/examples ]] && \
    mkdir -p /config/ytdl-sub-configs/examples && \
    cp /defaults/examples/* /config/ytdl-sub-configs/examples

# permissions
chown -R ${PUID:-abc}:${PGID:-abc} \
    /config
