Last active
August 5, 2023 13:43
-
-
Save darkato42/317c0e1a03c3cf8ee644a211be926549 to your computer and use it in GitHub Desktop.
Change proxy settings in Ubuntu
This file contains 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 | |
# Check if the proxy URL is passed as an argument | |
if [ -z "$1" ]; then | |
echo "Please provide the full proxy URL as an argument. E.g., ./update_proxy.sh http://192.168.1.3:3333" | |
exit 1 | |
fi | |
PROXY_URL="$1" | |
# Function to update /etc/profile.d/proxy.sh | |
update_profile_proxy() { | |
echo "# set proxy config via profie.d - should apply for all users" > /etc/profile.d/proxy.sh | |
echo "# http/https/ftp/no_proxy" >> /etc/profile.d/proxy.sh | |
echo "export http_proxy=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh | |
echo "export https_proxy=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh | |
echo "export ftp_proxy=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh | |
echo "export no_proxy=\"127.0.0.1,localhost\"" >> /etc/profile.d/proxy.sh | |
echo "" >> /etc/profile.d/proxy.sh | |
echo "# For curl" >> /etc/profile.d/proxy.sh | |
echo "export HTTP_PROXY=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh | |
echo "export HTTPS_PROXY=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh | |
echo "export FTP_PROXY=\"$PROXY_URL/\"" >> /etc/profile.d/proxy.sh | |
echo "export NO_PROXY=\"127.0.0.1,localhost\"" >> /etc/profile.d/proxy.sh | |
} | |
# Function to update ~/.wgetrc | |
update_wgetrc() { | |
echo "use_proxy = on" > ~/.wgetrc | |
echo "http_proxy = $PROXY_URL/" >> ~/.wgetrc | |
echo "https_proxy = $PROXY_URL/" >> ~/.wgetrc | |
echo "ftp_proxy = $PROXY_URL/" >> ~/.wgetrc | |
} | |
# Main function to update the proxy settings | |
update_proxy_settings() { | |
echo "Updating proxy settings..." | |
# Call the function to update profile proxy | |
update_profile_proxy | |
# Call the function to update wgetrc | |
update_wgetrc | |
echo "Proxy settings updated successfully!" | |
} | |
# Run the main function | |
update_proxy_settings |
Author
darkato42
commented
Aug 5, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment