Last active
January 31, 2019 15:53
-
-
Save Kaylebor/493a5bf027e4ad3b129683e2a3992127 to your computer and use it in GitHub Desktop.
Settings for a user behind a corporate MITM-style proxy on a Debian-based system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# | |
# setup_proxy_script.sh | |
# Copyright (C) 2019 Ender Veiga Bueno <[email protected]> | |
# | |
# Distributed under terms of the MIT license. | |
# | |
# Check that the script is being run as root (sudo ./setup_proxy_script.sh) | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
#### SCRIPT VARIABLES #### | |
# Get the current user's home folder | |
user_home=$(getent passwd "$SUDO_USER" | cut -d: -f6) | |
# Check if .zshrc exists; if not, use default .bashrc | |
if [ -f "$USER_HOME/.zshrc" ]; then | |
script_conf_file="$user_home/.zshrc | |
else | |
script_conf_file="$user_home/.bashrc" | |
fi | |
# Apt's configuration file | |
apt_conf_file="/etc/apt/apt.conf" | |
# The proxy URL | |
proxy="INSERT PROXY URL HERE" # TODO | |
#### SCRIPT VARIABLES #### | |
# Copy all certificates to the folder where update-ca-certificates searches | |
for filename in certs/*; do | |
if [ ! -f "/usr/local/share/ca-certificates/{$filename##*/}" ]; then | |
cp "$filename" "/usr/local/share/ca-certificates/${filename##*/}" | |
chmod 644 "/usr/local/share/ca-certificates/${filename##*/}" | |
fi | |
done | |
# Update certificates | |
# Necessary for curl/wget to work properly | |
update-ca-certificates | |
# Proxy settings for apt-get | |
echo "Acquire::http::proxy \"$proxy\";" >> "$apt_conf_file" | |
if [ "$HTTP_PROXY" == "" ]; then | |
# Proxy settings system-wide | |
{ | |
echo "export http_proxy=\"$proxy\"" | |
echo "export https_proxy=\"\$http_proxy\"" | |
echo "export ftp_proxy=\"\$http_proxy\"" | |
echo "export HTTP_PROXY=\"\$http_proxy\"" | |
echo "export HTTPS_PROXY=\"\$https_proxy\"" | |
echo "export FTP_PROXY=\"\$ftp_proxy\"" | |
} >> "$script_conf_file" | |
fi | |
source "$user_home/.bashrc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script should be run besides a "certs" folder, containing the proxy certificates.
Also, the "PROXY" variable should be set to the proxy URL.
It needs root permissions to setup certificates and Apt's proxy settings.
Certificates and apt should work system-wide after this script runs, but the proxy environment variables will only be set for the current user.