#!/bin/sh

# Update sources.list
repo=/etc/apt/sources.list.d/nextdns.list
if [ -f $repo ] \
       && grep -qE '(nextdns.io/repo|dl.bintray.com)' $repo; then
    cat <<EOF > $repo
# Added for NextDNS
deb [signed-by=/etc/apt/keyrings/nextdns.gpg] https://repo.nextdns.io/deb stable main
EOF
    mkdir -p /etc/apt/keyrings
    curl -sL https://repo.nextdns.io/nextdns.gpg > /etc/apt/keyrings/nextdns.gpg
    if ! dpkg --compare-versions $(dpkg-query --showformat='${Version}' --show apt) ge 1.1; then
        ln -sf /etc/apt/keyrings/nextdns.gpg /etc/apt/trusted.gpg.d/.
    fi
fi

nextdns install

exit 0
