#!/usr/bin/env bash

URL=couchdb.apache.org/repo
LIST_NAME=couchdb.list
#RELEASE=stretch
#RELEASE=buster
RELEASE=bullseye

# Add the public key:
curl https://${URL}/keys.asc | gpg --dearmor | sudo tee /usr/share/keyrings/couchdb-archive-keyring.gpg >/dev/null 2>&1

sudo sh -c "echo "deb [signed-by=/usr/share/keyrings/couchdb-archive-keyring.gpg] https://apache.jfrog.io/artifactory/couchdb-deb/ ${RELEASE} main" \
    | sudo tee /etc/apt/sources.list.d/${LIST_NAME} >/dev/null"

sudo ln -s /etc/apt/sources.list-available/${LIST_NAME} /etc/apt/sources.list.d/${LIST_NAME}

# Bypass apt-proxy 
#if [ -d /etc/apt/apt.conf.d/02proxy ]; then
#	if [ ! -z $(grep ${URL}) ]; then
#		echo "Acquire::http::Proxy { \"${URL}\" DIRECT; };" >> /etc/apt/apt.conf.d/02proxy
#	fi
#else
#		echo "Acquire::http::Proxy { \"${URL}\" DIRECT; };" >> /etc/apt/apt.conf.d/02proxy
#fi

apt-get update && apt-get install -y couchdb

