summaryrefslogtreecommitdiffstats
path: root/scripts/oe-git-proxy
diff options
context:
space:
mode:
authorDarren Hart <dvhart@linux.intel.com>2013-02-08 14:27:25 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-02-11 22:54:04 +0000
commit9902eb341a31ad3e42ab857793914e09caec81c7 (patch)
tree7f13d4b6306cfd88b83c92f7880309c9d7a7220f /scripts/oe-git-proxy
parent0c988bfbb295c3f1e21ad30fab56c9d9fd7513c1 (diff)
downloadpoky-9902eb341a31ad3e42ab857793914e09caec81c7.tar.gz
oe-git-proxy: Use socat instead of BSD nc
BSD nc was commonly available on the current distros until Fedora 18 appears to have dropped it. socat appears to be a reasonable replacement with availability on Fedora and Ubuntu and going back some time as well. Update the script to use the socat syntax. Simplify the logic a bit by using exec for the no-proxy-needed cases. (From OE-Core rev: 795b1ea370b8a1d9152c171a50e80bd0b4b8dc60) Signed-off-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/oe-git-proxy')
-rwxr-xr-xscripts/oe-git-proxy59
1 files changed, 27 insertions, 32 deletions
diff --git a/scripts/oe-git-proxy b/scripts/oe-git-proxy
index 4c2f17903b..98191faadd 100755
--- a/scripts/oe-git-proxy
+++ b/scripts/oe-git-proxy
@@ -1,13 +1,11 @@
1#!/bin/bash 1#!/bin/bash
2 2
3# oe-git-proxy is a simple tool to be via GIT_PROXY_COMMAND. It uses BSD netcat 3# oe-git-proxy is a simple tool to be via GIT_PROXY_COMMAND. It uses socat
4# to make SOCKS5 or HTTPS proxy connections. It uses ALL_PROXY to determine the 4# to make SOCKS5 or HTTPS proxy connections. It uses ALL_PROXY to determine the
5# proxy server, protocol, and port. It uses NO_PROXY to skip using the proxy for 5# proxy server, protocol, and port. It uses NO_PROXY to skip using the proxy for
6# a comma delimited list of hosts, host globs (*.example.com), IPs, or CIDR 6# a comma delimited list of hosts, host globs (*.example.com), IPs, or CIDR
7# masks (192.168.1.0/24). It is known to work with both bash and dash shells. 7# masks (192.168.1.0/24). It is known to work with both bash and dash shells.
8# 8#
9# BSD netcat is provided by netcat-openbsd on Ubuntu and nc on Fedora.
10#
11# Example ALL_PROXY values: 9# Example ALL_PROXY values:
12# ALL_PROXY=socks://socks.example.com:1080 10# ALL_PROXY=socks://socks.example.com:1080
13# ALL_PROXY=https://proxy.example.com:8080 11# ALL_PROXY=https://proxy.example.com:8080
@@ -15,27 +13,13 @@
15# Copyright (c) 2013, Intel Corporation. 13# Copyright (c) 2013, Intel Corporation.
16# All rights reserved. 14# All rights reserved.
17# 15#
18# This program is free software; you can redistribute it and/or modify
19# it under the terms of the GNU General Public License as published by
20# the Free Software Foundation; either version 2 of the License, or
21# (at your option) any later version.
22#
23# This program is distributed in the hope that it will be useful,
24# but WITHOUT ANY WARRANTY; without even the implied warranty of
25# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26# GNU General Public License for more details.
27#
28# You should have received a copy of the GNU General Public License
29# along with this program; if not, write to the Free Software
30# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31#
32# AUTHORS 16# AUTHORS
33# Darren Hart <dvhart@linux.intel.com> 17# Darren Hart <dvhart@linux.intel.com>
34 18
35# Locate the netcat binary 19# Locate the netcat binary
36NC=$(which nc 2>/dev/null) 20SOCAT=$(which socat 2>/dev/null)
37if [ $? -ne 0 ]; then 21if [ $? -ne 0 ]; then
38 echo "ERROR: nc binary not in PATH" 22 echo "ERROR: socat binary not in PATH"
39 exit 1 23 exit 1
40fi 24fi
41METHOD="" 25METHOD=""
@@ -111,28 +95,39 @@ match_host() {
111 return 1 95 return 1
112} 96}
113 97
114# If no proxy is set, just connect directly 98# If no proxy is set or needed, just connect directly
99METHOD="TCP:$1:$2"
100
115if [ -z "$ALL_PROXY" ]; then 101if [ -z "$ALL_PROXY" ]; then
116 exec $NC -X connect "$@" 102 exec $SOCAT STDIO $METHOD
117fi 103fi
118 104
119# Connect directly to hosts in NO_PROXY 105# Connect directly to hosts in NO_PROXY
120for H in ${NO_PROXY//,/ }; do 106for H in ${NO_PROXY//,/ }; do
121 if match_host $1 $H; then 107 if match_host $1 $H; then
122 METHOD="-X connect" 108 exec $SOCAT STDIO $METHOD
123 break
124 fi 109 fi
125done 110done
126 111
127if [ -z "$METHOD" ]; then 112# Proxy is necessary, determine protocol, server, and port
128 # strip the protocol and the trailing slash 113PROTO=$(echo $ALL_PROXY | sed -e 's/\([^:]*\):\/\/.*/\1/')
129 PROTO=$(echo $ALL_PROXY | sed -e 's/\([^:]*\):\/\/.*/\1/') 114PROXY=$(echo $ALL_PROXY | sed -e 's/.*:\/\/\([^:]*\).*/\1/')
130 PROXY=$(echo $ALL_PROXY | sed -e 's/.*:\/\/\([^:]*:[0-9]*\).*/\1/') 115PORT=$(echo $ALL_PROXY | sed -e 's/.*:\([0-9]*\)\/?$/\1/')
131 if [ "$PROTO" = "socks" ]; then 116if [ "$PORT" = "$ALL_PROXY" ]; then
132 METHOD="-X 5 -x $PROXY" 117 PORT=""
133 elif [ "$PROTO" = "https" ]; then 118fi
134 METHOD="-X connect -x $PROXY" 119
120if [ "$PROTO" = "socks" ]; then
121 if [ -z "$PORT" ]; then
122 PORT="1080"
123 fi
124 METHOD="SOCKS4:$PROXY:$1:$2,socksport=$PORT"
125else
126 # Assume PROXY (http, https, etc)
127 if [ -z "$PORT" ]; then
128 PORT="8080"
135 fi 129 fi
130 METHOD="PROXY:$PROXY:$1:$2,proxyport=$PORT"
136fi 131fi
137 132
138exec $NC $METHOD "$@" 133exec $SOCAT STDIO $METHOD