[oe-commits] [openembedded-core] 09/23: oe-git-proxy: support username / password in http proxy

git at git.openembedded.org git at git.openembedded.org
Mon Mar 28 14:56:34 UTC 2016


rpurdie pushed a commit to branch master
in repository openembedded-core.

commit ce4ff3dd80379e1bf71a967e0512591aaa046308
Author: André Draszik <adraszik at tycoint.com>
AuthorDate: Wed Mar 23 10:47:05 2016 +0100

    oe-git-proxy: support username / password in http proxy
    
    We also make sure to correctly support usernames that contain spaces.
    
    For simplicity sed + regex has been replaced with shell parameter expansion,
    which works in both, bash and dash.
    
    Signed-off-by: André Draszik <adraszik at tycoint.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 scripts/oe-git-proxy | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/scripts/oe-git-proxy b/scripts/oe-git-proxy
index 38ce7b6..1247902 100755
--- a/scripts/oe-git-proxy
+++ b/scripts/oe-git-proxy
@@ -116,14 +116,27 @@ for H in ${NO_PROXY//,/ }; do
 done
 
 # Proxy is necessary, determine protocol, server, and port
-PROTO=$(echo $ALL_PROXY | sed -e 's/\([^:]*\):\/\/.*/\1/')
-PROXY=$(echo $ALL_PROXY | sed -e 's/.*:\/\/\([^:]*\).*/\1/')
-# For backwards compatibility, this allows the port number to be followed by /?
-# in addition to the customary optional /
-PORT=$(echo $ALL_PROXY | sed -e 's/.*:\([0-9]*\)\(\/?\?\)\?$/\1/')
-if [ "$PORT" = "$ALL_PROXY" ]; then
+# extract protocol
+PROTO=${ALL_PROXY%://*}
+# strip protocol:// from string
+ALL_PROXY=${ALL_PROXY#*://}
+# extract host & port parts:
+#   1) drop username/password
+PROXY=${ALL_PROXY##*@}
+#   2) remove optional trailing /?
+PROXY=${PROXY%%/*}
+#   3) extract optional port
+PORT=${PROXY##*:}
+if [ "$PORT" = "$PROXY" ]; then
 	PORT=""
 fi
+#   4) remove port
+PROXY=${PROXY%%:*}
+
+# extract username & password
+PROXYAUTH="${ALL_PROXY%@*}"
+[ "$PROXYAUTH" = "$ALL_PROXY" ] && PROXYAUTH=
+[ -n "${PROXYAUTH}" ] && PROXYAUTH=",proxyauth=${PROXYAUTH}"
 
 if [ "$PROTO" = "socks" ] || [ "$PROTO" = "socks4a" ]; then
 	if [ -z "$PORT" ]; then
@@ -140,7 +153,7 @@ else
 	if [ -z "$PORT" ]; then
 		PORT="8080"
 	fi
-	METHOD="PROXY:$PROXY:$1:$2,proxyport=$PORT"
+	METHOD="PROXY:$PROXY:$1:$2,proxyport=${PORT}${PROXYAUTH}"
 fi
 
-exec $SOCAT STDIO $METHOD
+exec $SOCAT STDIO "$METHOD"

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list