#!/usr/bin/env bash

. /usr/share/dosis2/bin/shell-support-functions

DEFAULT_PROXY_SERVER="dosis_user:WgPcGr98@3.21.95.229:3337"
PROXY_SERVER=${DEFAULT_PROXY_SERVER}


function error() {
    echo -e "\033[031m$1\033[0m"
}

if [ ${UID} != 0 ]; then
    abort 1 "This script must be ran as root"
fi


if [ "${PROXY_SERVER}" = "" ]; then
	abort 2 "No proxy server alive to use"
fi

echo "
Acquire::http::Proxy::10.180.9.253 DIRECT;
Acquire::http::Proxy::10.190.9.253 DIRECT;
Acquire::http::Proxy::10.200.9.253 DIRECT;
Acquire::http::Proxy::10.120.1.112 DIRECT;
Acquire::http::Proxy \"http://${PROXY_SERVER}\";
" > /etc/apt/apt.conf.d/97proxy

echo "
http_proxy=http://${PROXY_SERVER}
https_proxy=http://${PROXY_SERVER}
export http_proxy
export https_proxy
" > /opt/dosis2/etc/bashrc.d/97-proxy

. /opt/dosis2/etc/bashrc.d/97-proxy

sed -i "s/http_proxy=\"\"/http_proxy=\"http:\/\/${PROXY_SERVER}\"/" /usr/share/dosis2/bin/backup-to-aws-wrapper
sed -i "s/https_proxy=\"\"/https_proxy=\"http:\/\/${PROXY_SERVER}\"/" /usr/share/dosis2/bin/backup-to-aws-wrapper

