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.

(From OE-Core rev: ce4ff3dd80379e1bf71a967e0512591aaa046308)

Signed-off-by: André Draszik <adraszik@tycoint.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
André Draszik 2016-03-23 10:47:05 +01:00 committed by Richard Purdie
parent a15541dc27
commit 9ac1b6fc39

View File

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