#!/usr/bin/env bash
sudo apt-get install apt-proxy-ng

proxy_port="3142"
apt_proxy="http://127.0.0.1:${proxy_port}"

# Check for exist proxy before adding the local one.
if [ -f /etc/apt/apt.conf.d/02proxy ]; then
  if grep -q "${proxy_port}" /etc/apt/apt.conf.d/02proxy; then
    echo "Listener on port 3142 already exists."
  fi
else
  echo "Acquire::https::Proxy { \"${apt_proxy}\" DIRECT; };" | sudo tee -a /etc/apt/apt.conf.d/02proxy
fi
