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

# check if config file exists in /config
if [[ ! -f /config/nzbget.conf ]]; then
    cp /app/nzbget/share/nzbget/nzbget.conf /config/nzbget.conf
fi

# delete lock file if found
if [[ -f /config/nzbget.lock ]]; then
    rm /config/nzbget.lock
fi

if [[ -z ${LSIO_NON_ROOT_USER} ]]; then
    if grep -qe ' /downloads ' /proc/mounts; then
        lsiown abc:abc \
            /downloads
    fi

    lsiown -R abc:abc \
        /config

    chmod u+rw \
        /config/nzbget.conf
fi
