#!/usr/bin/sudo /bin/bash
##### Configuration #####
netAptProxy='192.168.1.251';
netAptProxyPort='3142';
##### / Configuration #####
tempfile=$(mktemp);
isProxy=$(wget -O ${tempfile} http://${netAptProxy}:${netAptProxyPort} 2>&1 | grep '406 Usage Information' | wc -l);
rm ${tempfile};
if [ 1 -eq ${isProxy} ]; then
echo "Acquire::http { 'Proxy ${netAptProxy}:${netAptProxyPort};' };" | tee /etc/apt/apt.conf.d/02proxy;
else
echo "#Acquire::http { 'Proxy ${netAptProxy}:${netAptProxyPort};' };" | tee /etc/apt/apt.conf.d/02proxy;
fi
chmod 664 /etc/apt/apt.conf.d/02proxy