proxy_settings.sh: modify parsing kernel cmdline for proxy options 55/23555/1
authorRafal Krypa <r.krypa@samsung.com>
Fri, 27 Jun 2014 09:46:14 +0000 (11:46 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Fri, 27 Jun 2014 09:46:14 +0000 (11:46 +0200)
This changes script's behavior when a proxy option appears more than once
in the kernel command line. Previously only the last occurrence was parsed.
But this creates problem with how Tizen qemu passes these options. Proxy
settings are appended to the kernel command line based on gconf settings in
the hosts environment. When there is no global proxy set, qemu will always
append empty "http_proxy=". If a user wants to set proxy only for qemu, but
not for the entire system, he may try to manually add settings to cmdline.
But Tizen emulator will append empty settings after user settings,
overriding it.

This patch changes parsing of proxy settings to get only the first
occurrence, not the last. It enables a user to give his own proxy only for
the emulator.

Change-Id: I15834841b115ccb66fb5d67795333e5dc227998b
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
filesystem/etc/profile.d/proxy_setting.sh

index 05970dac4cb7f1c64a0ab0bffd40bb0b7332a37d..762e9eea5e3de3cc265b44dfd15de2b1f0b3e9de 100755 (executable)
@@ -1,34 +1,20 @@
 #!/bin/sh
-if grep -q "http_proxy=" /proc/cmdline ; then
-        __proxy=`sed 's/^.*http_proxy=\([^, ]*\).*$/\1/g' /proc/cmdline`
-        if [ "x${__proxy}" = "x" ]; then
-            export "http_proxy="
-        else
-            export "http_proxy=http://${__proxy}/"
-        fi
-fi
-if grep -q "https_proxy=" /proc/cmdline ; then
-        __proxy=`sed 's/^.*https_proxy=\([^, ]*\).*$/\1/g' /proc/cmdline`
-        if [ "x${__proxy}" = "x" ]; then
-            export "https_proxy="
-        else
-            export "https_proxy=https://${__proxy}/"
-        fi
-fi
-if grep -q "ftp_proxy=" /proc/cmdline ; then
-        __proxy=`sed 's/^.*ftp_proxy=\([^, ]*\).*$/\1/g' /proc/cmdline`
-        if [ "x${__proxy}" = "x" ]; then
-            export "ftp_proxy="
-        else
-            export "ftp_proxy=ftp://${__proxy}/"
-        fi
-fi
-if grep -q "socks_proxy=" /proc/cmdline ; then
-        __proxy=`sed 's/^.*socks_proxy=\([^, ]*\).*$/\1/g' /proc/cmdline`
-        if [ "x${__proxy}" = "x" ]; then
-            export "socks_proxy="
-        else
-            export "socks_proxy=socks://${__proxy}/"
-        fi
-fi
+
+function cmd_get
+{
+       cat /proc/cmdline | tr -s [:space:] '\n' | grep -m1 "^$1=" | cut -d= -f2
+}
+
+__proxy=`cmd_get http_proxy`
+[ -n "${__proxy}" ] && export "http_proxy=http://${__proxy}/"
+
+__proxy=`cmd_get https_proxy`
+[ -n "${__proxy}" ] && export "https_proxy=https://${__proxy}/"
+
+__proxy=`cmd_get ftp_proxy`
+[ -n "${__proxy}" ] && "ftp_proxy=ftp://${__proxy}/"
+
+__proxy=`cmd_get socks_proxy`
+[ -n "${__proxy}" ] && "socks_proxy=socks://${__proxy}/"
+
 export "no_proxy=localhost,127.0.0.1/8,10.0.0.0/16"