Proxy environment variables not set for apps launched by .desktop files
Feature summary
Proxy settings defined by gsettings are not propagated through environment variables HTTP_PROXY and HTTPS_PROXY on applications launched by .desktop files.
How would you like it to work
It would be nice and practical if GNOME shell initiates/propagates the environment variables HTTP_PROXY and HTTPS_PROXY automatically on applications launched by .desktop files, as many applications don't look into dconf settings but follow the environment variables HTTP_PROXY and HTTPS_PROXY. Note that when launching such applications from GNOME terminal (and not .desktop files), these variables are propagated into the application.
Details
- Consider the following proxy settings defined by dconf:
gsettings list-recursively org.gnome.system.proxy
org.gnome.system.proxy ignore-hosts ['localhost', '127.0.0.0/8', '::1']
org.gnome.system.proxy use-same-proxy false
org.gnome.system.proxy mode 'manual'
org.gnome.system.proxy autoconfig-url ''
org.gnome.system.proxy.http use-authentication false
org.gnome.system.proxy.http enabled false
org.gnome.system.proxy.http authentication-password ''
org.gnome.system.proxy.http port 8080
org.gnome.system.proxy.http host 'proxy.example.com'
org.gnome.system.proxy.http authentication-user ''
org.gnome.system.proxy.https port 8080
org.gnome.system.proxy.https host 'proxy.example.com'
org.gnome.system.proxy.ftp port 0
org.gnome.system.proxy.ftp host ''
org.gnome.system.proxy.socks port 0
org.gnome.system.proxy.socks host ''
-
When launching some applications (like GNOME terminal) from its .desktop file, the environment variables HTTP_PROXY and HTTPS_PROXY are defined in the terminal. It seems GNOME terminal is looking into dconf and initiate the corresponding environments variables.
-
However, when launching other applications (like xterm) from its .desktop file, the environment variables HTTP_PROXY and HTTPS_PROXY are not defined.
Related issue
https://github.com/telegramdesktop/tdesktop/issues/2777
Dirty workaround
Inspired by https://gist.github.com/JPvRiel/4e3f6f055b4ac9c31a302450bfdf0758, put the following file in /etc/profile.d/
#!/bin/sh
# Deal with some proxy pain for Linux apps! Note:
# - Default is let desktop env manage proxy env
# - However, GNOME does't always set the proxy enviroment when an application is
# executed via a .desktop file
# - This tries to help pull org.gnome.proxy settings into http_proxy, etc
# - `gsettings list-recursively org.gnome.system.proxy`
un_single_quote() {
s="$1"
s=${s%\'}
s=${s#\'}
echo "$s"
}
proxy_on() {
# http org.gnome.system.proxy.http
http_host="$(un_single_quote "$(gsettings get org.gnome.system.proxy.http host)")"
http_port="$(un_single_quote "$(gsettings get org.gnome.system.proxy.http port)")"
if [ ! -z "$http_host" ]; then
export http_proxy="http://$http_host:$http_port"
export HTTP_PROXY=$http_proxy
fi
# org.gnome.system.proxy.https
https_host="$(un_single_quote "$(gsettings get org.gnome.system.proxy.https host)")"
https_port="$(un_single_quote "$(gsettings get org.gnome.system.proxy.https port)")"
if [ ! -z "$https_host" ]; then
export https_proxy="http://$https_host:$https_port"
export HTTPS_PROXY=$https_proxy
fi
# org.gnome.system.proxy.ftp
ftp_host="$(un_single_quote "$(gsettings get org.gnome.system.proxy.ftp host)")"
ftp_port="$(un_single_quote "$(gsettings get org.gnome.system.proxy.ftp port)")"
if [ ! -z "$ftp_host" ]; then
export ftp_proxy="ftp://$ftp_host:$ftp_port"
export FTP_PROXY=$ftp_proxy
fi
# socks org.gnome.system.proxy.socks
# TODO: not proccessed for now
# org.gnome.system.proxy ignore-hosts
ignore_hosts="$(gsettings get org.gnome.system.proxy ignore-hosts)"
empty_list='[]'
no_proxy="${ignore_hosts:1:-1}"
no_proxy="${no_proxy// /}"
no_proxy="${no_proxy//\'/}"
if [ ! -z "${ignore_hosts##*$empty_list*}" ]; then
export no_proxy
export NO_PROXY=$no_proxy
fi
}
proxy_off() {
unset no_proxy
unset NO_PROXY
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
unset ftp_proxy
unset FTP_PROXY
}
# check for unsupported settings
case "$(un_single_quote "$(gsettings get org.gnome.system.proxy mode)")" in
manual)
proxy_on
;;
auto)
echo "ERROR: Auto, autoconfig-url (PAC) is not yet supported" >&2
exit 1
;;
none)
proxy_off
;;
*)
echo "ERROR: org.gnome.system.proxy mode unknown" >&2
exit 1
;;
esac
if [[ "$(gsettings get org.gnome.system.proxy.http use-authentication)" == 'true' ]]; then
echo "ERROR: HTTP proxy authentication is not yet supported" >&2
exit 1
fi