#!/usr/bin/env basho

URL=packages.element.io
RELEASE=default

sudo sh -c "echo 'deb https://${URL}/debian/ ${RELEASE} main' > /etc/apt/sources.list-available/element-io.list"

echo "deb [signed-by=/usr/share/keyrings/element-io-archive-keyring.gpg] https://${URL}/debian/ ${RELEASE} main" | sudo tee /etc/apt/sources.list.d/element-io.list

sudo ln -sf /etc/apt/sources.list-available/element-io.list /etc/apt/sources.list.d/element-io.list

# Add the public key:
sudo wget -O /usr/share/keyrings/element-io-archive-keyring.gpg https://packages.element.io/debian/element-io-archive-keyring.gpg

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

sudo apt update && apt install -y element-nightly


