上QQ阅读APP看书,第一时间看更新
How to do it...
- Create a new file using nano as follows (if there is already some content in the file, you can add the code at the end):
sudo nano -c ~/.bash_profile
- To allow basic web browsing through programs such as Midori while using a proxy server, you can use the following script:
function proxyenable { # Define proxy settings PROXY_ADDR="proxy.address.com:port" # Login name (leave blank if not required): LOGIN_USER="login_name" # Login Password (leave blank to prompt): LOGIN_PWD= #If login specified - check for password if [[ -z $LOGIN_USER ]]; then #No login for proxy PROXY_FULL=$PROXY_ADDR else #Login needed for proxy Prompt for password -s option hides input if [[ -z $LOGIN_PWD ]]; then read -s -p "Provide proxy password (then Enter):" LOGIN_PWD echo fi PROXY_FULL=$LOGIN_USER:$LOGIN_PWD@$PROXY_ADDR fi #Web Proxy Enable: http_proxy or HTTP_PROXY environment variables export http_proxy="http://$PROXY_FULL/" export HTTP_PROXY=$http_proxy export https_proxy="https://$PROXY_FULL/" export HTTPS_PROXY=$https_proxy export ftp_proxy="ftp://$PROXY_FULL/" export FTP_PROXY=$ftp_proxy #Set proxy for apt-get sudo cat <<EOF | sudo tee /etc/apt/apt.conf.d/80proxy > /dev/null Acquire::http::proxy "http://$PROXY_FULL/"; Acquire::ftp::proxy "ftp://$PROXY_FULL/"; Acquire::https::proxy "https://$PROXY_FULL/"; EOF #Remove info no longer needed from environment unset LOGIN_USER LOGIN_PWD PROXY_ADDR PROXY_FULL echo Proxy Enabled } function proxydisable { #Disable proxy values, apt-get and git settings unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY unset ftp_proxy FTP_PROXY sudo rm /etc/apt/apt.conf.d/80proxy echo Proxy Disabled }
- Once done, save and exit by pressing Ctrl + X, Y, and Enter.
The script is added to the user's own .bash_profile file, which is run when that particular user logs in. This will ensure that the proxy settings are kept separately for each user. If you want all users to use the same settings, you can add the code to /etc/rc.local instead (this file must have exit 0 at the end).