]> code.ossystems Code Review - openembedded-core.git/commitdiff
oe-git-proxy: support username / password in http proxy
authorAndré Draszik <adraszik@tycoint.com>
Wed, 23 Mar 2016 09:47:05 +0000 (10:47 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 28 Mar 2016 14:54:51 +0000 (15:54 +0100)
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@tycoint.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/oe-git-proxy

index 38ce7b66fd39c5a897445da0bb13592ed870de30..12479024062828818266f0ebaf6173efe87d92c1 100755 (executable)
@@ -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"