Rework a little bit of the LAN mirror and proxy settings.
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Aug 01 09:23:58 2008 +0000 (2008-08-01)
changeset 754b13657cd64b3
parent 753 53a577cbd9d4
child 755 c2212f59e1cf
Rework a little bit of the LAN mirror and proxy settings.

/trunk/scripts/crosstool.sh | 105 4 101 0 +------------------------
/trunk/scripts/functions | 151 129 22 0 +++++++++++++++++++++++++++++++-----
/trunk/config/global/download.in | 193 99 94 0 ++++++++++++++++++++++++----------------------
3 files changed, 232 insertions(+), 217 deletions(-)
config/global/download.in
scripts/crosstool.sh
scripts/functions
     1.1 --- a/config/global/download.in	Fri Aug 01 08:23:29 2008 +0000
     1.2 +++ b/config/global/download.in	Fri Aug 01 09:23:58 2008 +0000
     1.3 @@ -11,93 +11,14 @@
     1.4        
     1.5        Usefull if you suspect a tarball to be damaged.
     1.6  
     1.7 -menuconfig USE_LAN_MIRROR
     1.8 -    bool
     1.9 -    prompt "Use LAN mirror"
    1.10 -    default n
    1.11 -    help
    1.12 -      If you have a machine on your LAN that mirrors some of the needed
    1.13 -      tarballs, you can say 'Y' here, and configure adequate values in
    1.14 -      the following options.
    1.15 -      
    1.16 -      Tarballs will be be preferably fetched from the LAN mirror, and if
    1.17 -      not found there, standard places will be searched for.
    1.18 -
    1.19 -if USE_LAN_MIRROR
    1.20 -
    1.21 -choice
    1.22 -    bool
    1.23 -    prompt "Server type:"
    1.24 -
    1.25 -config LAN_MIRROR_HTTP
    1.26 -    bool
    1.27 -    prompt "http"
    1.28 -
    1.29 -config LAN_MIRROR_FTP
    1.30 -    bool
    1.31 -    prompt "ftp"
    1.32 -
    1.33 -endchoice # Server type
    1.34 -
    1.35 -config LAN_MIRROR_SCHEME
    1.36 -    string
    1.37 -    default "http"  if LAN_MIRROR_HTTP
    1.38 -    default "ftp"   if LAN_MIRROR_FTP
    1.39 -
    1.40 -config LAN_MIRROR_HOSTNAME
    1.41 -    string
    1.42 -    prompt "hostname"
    1.43 -    depends on EXPERIMENTAL
    1.44 -    default  "localhost"
    1.45 -    help
    1.46 -      Enter here the hostname on your LAN mirror.
    1.47 -
    1.48 -config LAN_MIRROR_PATTERNS
    1.49 -    string
    1.50 -    prompt "locations patterns (READ HELP!)"
    1.51 -    default "/downloads /downloads/%pkg /downloads/%pkg/%ver /downloads/%pkg-%ver"
    1.52 -    help
    1.53 -      A space-separated list of patterns to find the tarballs on the
    1.54 -      LAN mirror.
    1.55 -
    1.56 -      You can use the following 'variables', and they'll get replaced by
    1.57 -      adequate values:
    1.58 -        %pkg : name of the package
    1.59 -        %ver : version of the package
    1.60 -
    1.61 -      Thus for gcc-4.2.4, %pkg will be replaced with 'gcc', and %ver with
    1.62 -      '4.2.4' (both without quotes). Thus if you entered the default
    1.63 -      pattern: "/downloads/%pkg/ /downloads/%pkg/%ver /downloads/%pkg-%ver"
    1.64 -      the tarball for gcc-4.2.4 would be searched for in:
    1.65 -        /downloads/gcc/
    1.66 -        /downloads/gcc/4.2.4/
    1.67 -        /downloads/gcc-4.2.4/
    1.68 -
    1.69 -      Of course, if the files on the LAN mirror are really arranged in weird
    1.70 -      ways, entering a list of patterns will be tedious... But see below.
    1.71 -
    1.72 -config LAN_MIRROR_LS_R
    1.73 -    bool
    1.74 -    prompt "Use ls-lr.gz et al."
    1.75 -    default n
    1.76 -    help
    1.77 -      If the tarball was not found at any of the above locations, see if the
    1.78 -      server has a ls-lr.gz (or similar) file, and use that file to see if
    1.79 -      the tarball is listed somewhere in that file.
    1.80 -
    1.81 -      Common file names looked for are:
    1.82 -        ls-lrRt.txt     (used at ftp.gnu.org)
    1.83 -        find.txt        (ditto)
    1.84 -        ls-lR
    1.85 -
    1.86 -endif # USE_LAN_MIRROR
    1.87 -
    1.88  menuconfig USE_PROXY
    1.89      bool
    1.90 -    prompt "Proxy settings"
    1.91 +    prompt "Use a proxy"
    1.92      default n
    1.93      help
    1.94        Say 'Y' here if you need to use a proxy to connect to the internet.
    1.95 +      
    1.96 +      You can then choose between an HTTP or a SOCKS 4/5 proxy.
    1.97  
    1.98  if USE_PROXY
    1.99  
   1.100 @@ -112,7 +33,7 @@
   1.101        Use an HTTP proxy to connect to to the internet.
   1.102        Only the http and ftp protocols will be tunneled through this
   1.103        proxy.
   1.104 -
   1.105 +      
   1.106        Alternatively to setting this option, you can set and export the
   1.107        following variables in your environment:
   1.108          ftp_proxy=http://user:passwd@proxy.server:port/
   1.109 @@ -150,18 +71,18 @@
   1.110      prompt "SOCKS 4/5 proxy"
   1.111      help
   1.112        Use a Socks 4/5 proxy to connect to the internet.
   1.113 -      All protocols can get tunneled through this kind of proxy (depending
   1.114 -      on your proxy configuration, some do not allow all protocols, but
   1.115 -      chances are that protocols needed by crosstool-NG are allowed).
   1.116 -
   1.117 +      All protocols can get tunneled through this kind of proxy (your
   1.118 +      proxy configuration may not allow all protocols, but chances are
   1.119 +      that protocols needed by crosstool-NG are allowed).
   1.120 +      
   1.121        Alternatively to setting this option, you can configure tsocks
   1.122        system-wide, and set and export the following variable in your
   1.123        environment:
   1.124          LD_PRELOAD=/path/to/your/tsocks-library.so
   1.125 -
   1.126 +      
   1.127        This option makes use of the tsocks library. You will have to have tsocks
   1.128        installed on your system, of course.
   1.129 -
   1.130 +      
   1.131        If you think you do not know what tsocks is, or how to configure it,
   1.132        chances are that you do not need to set this option.
   1.133  
   1.134 @@ -220,7 +141,7 @@
   1.135  
   1.136  endchoice
   1.137  
   1.138 -endif # Proxy settings
   1.139 +endif # USE_PROXY
   1.140  
   1.141  config PROXY_TYPE
   1.142      string
   1.143 @@ -231,6 +152,90 @@
   1.144      default "socks4"    if PROXY_TYPE_SOCKS_4
   1.145      default "socks5"    if PROXY_TYPE_SOCKS_5
   1.146  
   1.147 +menuconfig USE_LAN_MIRROR
   1.148 +    bool
   1.149 +    prompt "Use LAN mirror"
   1.150 +    default n
   1.151 +    help
   1.152 +      If you have a machine on your LAN that mirrors some of the needed
   1.153 +      tarballs, you can say 'Y' here, and configure adequate values in
   1.154 +      the following options.
   1.155 +      
   1.156 +      Tarballs will be be preferably fetched from the LAN mirror, and if
   1.157 +      not found there, standard places will be searched for.
   1.158 +      
   1.159 +      Obviously, nothing prevents you from using a mirror that is in fact
   1.160 +      *not* on your LAN, for example on another subnet of your company's
   1.161 +      network, or a mirror on the Internet.
   1.162 +
   1.163 +if USE_LAN_MIRROR
   1.164 +
   1.165 +config LAN_MIRROR_USE_PROXY
   1.166 +    bool
   1.167 +    prompt "Use the proxy"
   1.168 +    default n
   1.169 +    depends on USE_PROXY
   1.170 +    help
   1.171 +      Say 'Y' here if you need to use the proxy to connect to the LAN mirror.
   1.172 +      
   1.173 +      You'll need to say 'Y' if the LAN mirror is not really on your LAN.
   1.174 +
   1.175 +choice
   1.176 +    bool
   1.177 +    prompt "Server type:"
   1.178 +
   1.179 +config LAN_MIRROR_HTTP
   1.180 +    bool
   1.181 +    prompt "http"
   1.182 +
   1.183 +config LAN_MIRROR_FTP
   1.184 +    bool
   1.185 +    prompt "ftp"
   1.186 +
   1.187 +endchoice # Server type
   1.188 +
   1.189 +config LAN_MIRROR_SCHEME
   1.190 +    string
   1.191 +    default "http"  if LAN_MIRROR_HTTP
   1.192 +    default "ftp"   if LAN_MIRROR_FTP
   1.193 +
   1.194 +config LAN_MIRROR_HOSTNAME
   1.195 +    string
   1.196 +    prompt "hostname"
   1.197 +    default ""
   1.198 +    help
   1.199 +      Enter here the hostname on your LAN mirror.
   1.200 +
   1.201 +config LAN_MIRROR_BASE
   1.202 +    string
   1.203 +    prompt "Base directory"
   1.204 +    default ""
   1.205 +    help
   1.206 +      This is the base directory searched for for tarballs. If you enter
   1.207 +      /mirror, then the search is performed in the following directories
   1.208 +      on the server:
   1.209 +        /mirror/<name>/
   1.210 +        /mirror/
   1.211 +      
   1.212 +      where <name> is replaced with the actual package name.
   1.213 +
   1.214 +config LAN_MIRROR_LS_R
   1.215 +    bool
   1.216 +#    prompt "Use ls-lR et al."
   1.217 +    depends on EXPERIMENTAL
   1.218 +    default n
   1.219 +    help
   1.220 +      If the tarball was not found at the above location, see if the server
   1.221 +      has a ls-lr.gz (or similar) file, and use that file to see if the
   1.222 +      tarball is listed somewhere in that file.
   1.223 +      
   1.224 +      Common file names looked for are:
   1.225 +        ls-lrRt.txt     (used at ftp.gnu.org)
   1.226 +        find.txt        (ditto)
   1.227 +        ls-lR
   1.228 +
   1.229 +endif # USE_LAN_MIRROR
   1.230 +
   1.231  config CONNECT_TIMEOUT
   1.232      int
   1.233      prompt "connection timeout"
   1.234 @@ -238,7 +243,7 @@
   1.235      help
   1.236        From the curl manual:
   1.237          Maximum time in seconds that you allow the connection to the server to take.
   1.238 -
   1.239 +      
   1.240        The scenario is as follows;
   1.241          - some enterprise networks have firewalls that prohibit FTP traffic, while
   1.242            still allowing HTTP
   1.243 @@ -246,13 +251,13 @@
   1.244          - after this number of seconds, it is considered that the connection could
   1.245            not be established, and the next URL in the list is tried, until we reach
   1.246            an URL that will go through the firewall, most probably an http:// URL.
   1.247 -
   1.248 +      
   1.249        If you have a slow network, you'd better set this value higher than the default
   1.250        10s. If you know a firewall is blocking connections, but your network is globally
   1.251        fast, you can try to lower this value to jump more quickly to allowed URLs. YMMV.
   1.252 -
   1.253 +      
   1.254        Note that this value applies equally to wget if you have that installed.
   1.255 -
   1.256 +      
   1.257        Of course, you'd be better off to use a proxy, as offered by the previous
   1.258        option.
   1.259  
     2.1 --- a/scripts/crosstool.sh	Fri Aug 01 08:23:29 2008 +0000
     2.2 +++ b/scripts/crosstool.sh	Fri Aug 01 09:23:58 2008 +0000
     2.3 @@ -101,8 +101,10 @@
     2.4      CT_Abort "I will stop here to avoid any carnage"
     2.5  fi
     2.6  
     2.7 -# Make all path absolute, it so much easier!
     2.8 -CT_LOCAL_TARBALLS_DIR=$(CT_MakeAbsolutePath "${CT_LOCAL_TARBALLS_DIR}")
     2.9 +if [ -n "${CT_LOCAL_TARBALLS_DIR}" ]; then
    2.10 +    # Make absolute path, it so much easier!
    2.11 +    CT_LOCAL_TARBALLS_DIR=$(CT_MakeAbsolutePath "${CT_LOCAL_TARBALLS_DIR}")
    2.12 +fi
    2.13  
    2.14  # If the local tarball directory does not exist, say so, and don't try to save there!
    2.15  if [ ! -d "${CT_LOCAL_TARBALLS_DIR}" ]; then
    2.16 @@ -211,105 +213,6 @@
    2.17          ;;
    2.18  esac
    2.19  
    2.20 -# Set environment for proxy access
    2.21 -# This has to be done even if we are restarting, as they don't get
    2.22 -# saved in the step snapshot.
    2.23 -case "${CT_PROXY_TYPE}" in
    2.24 -  none) ;;
    2.25 -  http)
    2.26 -    http_proxy="http://"
    2.27 -    case  "${CT_PROXY_USER}:${CT_PROXY_PASS}" in
    2.28 -      :)      ;;
    2.29 -      :*)     http_proxy="${http_proxy}:${CT_PROXY_PASS}@";;
    2.30 -      *:)     http_proxy="${http_proxy}${CT_PROXY_USER}@";;
    2.31 -      *:*)    http_proxy="${http_proxy}${CT_PROXY_USER}:${CT_PROXY_PASS}@";;
    2.32 -    esac
    2.33 -    export http_proxy="${http_proxy}${CT_PROXY_HOST}:${CT_PROXY_PORT}/"
    2.34 -    export https_proxy="${http_proxy}"
    2.35 -    export ftp_proxy="${http_proxy}"
    2.36 -    CT_DoLog DEBUG "http_proxy='${http_proxy}'"
    2.37 -    ;;
    2.38 -  sockssys)
    2.39 -    # Force not using HTTP proxy
    2.40 -    unset http_proxy ftp_proxy https_proxy
    2.41 -    CT_HasOrAbort tsocks
    2.42 -    . tsocks -on
    2.43 -    ;;
    2.44 -  socks*)
    2.45 -    # Force not using HTTP proxy
    2.46 -    unset http_proxy ftp_proxy https_proxy
    2.47 -    # Remove any lingering config file from any previous run
    2.48 -    rm -f "${CT_BUILD_DIR}/tsocks.conf"
    2.49 -    # Find all interfaces and build locally accessible networks
    2.50 -    server_ip=$(ping -c 1 -W 2 "${CT_PROXY_HOST}" |head -n 1 |sed -r -e 's/^[^\(]+\(([^\)]+)\).*$/\1/;' || true)
    2.51 -    CT_TestOrAbort "SOCKS proxy '${CT_PROXY_HOST}' has no IP." -n "${server_ip}"
    2.52 -    /sbin/ifconfig |awk -v server_ip="${server_ip}" '
    2.53 -      BEGIN {
    2.54 -        split( server_ip, tmp, "\\." );
    2.55 -        server_ip_num = tmp[1] * 2^24 + tmp[2] * 2^16 + tmp[3] * 2^8 + tmp[4] * 2^0;
    2.56 -        pairs = 0;
    2.57 -      }
    2.58 -
    2.59 -      $0 ~ /^[[:space:]]*inet addr:/ {
    2.60 -        split( $2, tmp, ":|\\." );
    2.61 -        if( ( tmp[2] == 127 ) && ( tmp[3] == 0 ) && ( tmp[4] == 0 ) && ( tmp[5] == 1 ) ) {
    2.62 -          /* Skip 127.0.0.1, it'\''s taken care of by tsocks itself */
    2.63 -          next;
    2.64 -        }
    2.65 -        ip_num = tmp[2] * 2^24 + tmp[3] * 2^16 + tmp[4] * 2 ^8 + tmp[5] * 2^0;
    2.66 -        i = 32;
    2.67 -        do {
    2.68 -          i--;
    2.69 -          mask = 2^32 - 2^i;
    2.70 -        } while( (i!=0) && ( and( server_ip_num, mask ) == and( ip_num, mask ) ) );
    2.71 -        mask = and( 0xFFFFFFFF, lshift( mask, 1 ) );
    2.72 -        if( (i!=0) && (mask!=0) ) {
    2.73 -          masked_ip = and( ip_num, mask );
    2.74 -          for( i=0; i<pairs; i++ ) {
    2.75 -            if( ( masked_ip == ips[i] ) && ( mask == masks[i] ) ) {
    2.76 -              next;
    2.77 -            }
    2.78 -          }
    2.79 -          ips[pairs] = masked_ip;
    2.80 -          masks[pairs] = mask;
    2.81 -          pairs++;
    2.82 -          printf( "local = %d.%d.%d.%d/%d.%d.%d.%d\n",
    2.83 -                  and( 0xFF, masked_ip / 2^24 ),
    2.84 -                  and( 0xFF, masked_ip / 2^16 ),
    2.85 -                  and( 0xFF, masked_ip / 2^8 ),
    2.86 -                  and( 0xFF, masked_ip / 2^0 ),
    2.87 -                  and( 0xFF, mask / 2^24 ),
    2.88 -                  and( 0xFF, mask / 2^16 ),
    2.89 -                  and( 0xFF, mask / 2^8 ),
    2.90 -                  and( 0xFF, mask / 2^0 ) );
    2.91 -        }
    2.92 -      }
    2.93 -    ' >"${CT_BUILD_DIR}/tsocks.conf"
    2.94 -    ( echo "server = ${server_ip}";
    2.95 -      echo "server_port = ${CT_PROXY_PORT}";
    2.96 -      [ -n "${CT_PROXY_USER}"   ] && echo "default_user=${CT_PROXY_USER}";
    2.97 -      [ -n "${CT_PROXY_PASS}" ] && echo "default_pass=${CT_PROXY_PASS}";
    2.98 -    ) >>"${CT_BUILD_DIR}/tsocks.conf"
    2.99 -    case "${CT_PROXY_TYPE/socks}" in
   2.100 -      4|5) proxy_type="${CT_PROXY_TYPE/socks}";;
   2.101 -      auto)
   2.102 -        reply=$(inspectsocks "${server_ip}" "${CT_PROXY_PORT}" 2>&1 || true)
   2.103 -        case "${reply}" in
   2.104 -          *"server is a version 4 socks server") proxy_type=4;;
   2.105 -          *"server is a version 5 socks server") proxy_type=5;;
   2.106 -          *) CT_Abort "Unable to determine SOCKS proxy type for '${CT_PROXY_HOST}:${CT_PROXY_PORT}'"
   2.107 -        esac
   2.108 -      ;;
   2.109 -    esac
   2.110 -    echo "server_type = ${proxy_type}" >> "${CT_BUILD_DIR}/tsocks.conf"
   2.111 -    CT_HasOrAbort tsocks
   2.112 -    # If tsocks was found, then validateconf is present (distributed with tsocks).
   2.113 -    CT_DoExecLog DEBUG validateconf -f "${CT_BUILD_DIR}/tsocks.conf"
   2.114 -    export TSOCKS_CONF_FILE="${CT_BUILD_DIR}/tsocks.conf"
   2.115 -    . tsocks -on
   2.116 -    ;;
   2.117 -esac
   2.118 -
   2.119  # Setting up the rest of the environment only if not restarting
   2.120  if [ -z "${CT_RESTART}" ]; then
   2.121      # Determine build system if not set by the user
     3.1 --- a/scripts/functions	Fri Aug 01 08:23:29 2008 +0000
     3.2 +++ b/scripts/functions	Fri Aug 01 09:23:58 2008 +0000
     3.3 @@ -288,6 +288,106 @@
     3.4      return 0
     3.5  }
     3.6  
     3.7 +# Set environment for proxy access
     3.8 +# Usage: CT_DoSetProxy <proxy_type>
     3.9 +# where proxy_type is one of 'none', 'http', 'sockssys', 'socks4' or 'socks5'
    3.10 +CT_DoSetProxy() {
    3.11 +    case "${CT_PROXY_TYPE}" in
    3.12 +        http)
    3.13 +            http_proxy="http://"
    3.14 +            case  "${CT_PROXY_USER}:${CT_PROXY_PASS}" in
    3.15 +                :)      ;;
    3.16 +                :*)     http_proxy="${http_proxy}:${CT_PROXY_PASS}@";;
    3.17 +                *:)     http_proxy="${http_proxy}${CT_PROXY_USER}@";;
    3.18 +                *:*)    http_proxy="${http_proxy}${CT_PROXY_USER}:${CT_PROXY_PASS}@";;
    3.19 +            esac
    3.20 +            export http_proxy="${http_proxy}${CT_PROXY_HOST}:${CT_PROXY_PORT}/"
    3.21 +            export https_proxy="${http_proxy}"
    3.22 +            export ftp_proxy="${http_proxy}"
    3.23 +            CT_DoLog DEBUG "http_proxy='${http_proxy}'"
    3.24 +            ;;
    3.25 +        sockssys)
    3.26 +            # Force not using HTTP proxy
    3.27 +            unset http_proxy ftp_proxy https_proxy
    3.28 +            CT_HasOrAbort tsocks
    3.29 +            . tsocks -on
    3.30 +            ;;
    3.31 +        socks*)
    3.32 +            # Force not using HTTP proxy
    3.33 +            unset http_proxy ftp_proxy https_proxy
    3.34 +            # Remove any lingering config file from any previous run
    3.35 +            rm -f "${CT_BUILD_DIR}/tsocks.conf"
    3.36 +            # Find all interfaces and build locally accessible networks
    3.37 +            server_ip=$(ping -c 1 -W 2 "${CT_PROXY_HOST}" |head -n 1 |sed -r -e 's/^[^\(]+\(([^\)]+)\).*$/\1/;' || true)
    3.38 +            CT_TestOrAbort "SOCKS proxy '${CT_PROXY_HOST}' has no IP." -n "${server_ip}"
    3.39 +            /sbin/ifconfig |awk -v server_ip="${server_ip}" '
    3.40 +                BEGIN {
    3.41 +                    split( server_ip, tmp, "\\." );
    3.42 +                    server_ip_num = tmp[1] * 2^24 + tmp[2] * 2^16 + tmp[3] * 2^8 + tmp[4] * 2^0;
    3.43 +                    pairs = 0;
    3.44 +                }
    3.45 +
    3.46 +                $0 ~ /^[[:space:]]*inet addr:/ {
    3.47 +                    split( $2, tmp, ":|\\." );
    3.48 +                    if( ( tmp[2] == 127 ) && ( tmp[3] == 0 ) && ( tmp[4] == 0 ) && ( tmp[5] == 1 ) ) {
    3.49 +                        /* Skip 127.0.0.1, it'\''s taken care of by tsocks itself */
    3.50 +                        next;
    3.51 +                    }
    3.52 +                    ip_num = tmp[2] * 2^24 + tmp[3] * 2^16 + tmp[4] * 2 ^8 + tmp[5] * 2^0;
    3.53 +                    i = 32;
    3.54 +                    do {
    3.55 +                        i--;
    3.56 +                        mask = 2^32 - 2^i;
    3.57 +                    } while( (i!=0) && ( and( server_ip_num, mask ) == and( ip_num, mask ) ) );
    3.58 +                    mask = and( 0xFFFFFFFF, lshift( mask, 1 ) );
    3.59 +                    if( (i!=0) && (mask!=0) ) {
    3.60 +                        masked_ip = and( ip_num, mask );
    3.61 +                        for( i=0; i<pairs; i++ ) {
    3.62 +                            if( ( masked_ip == ips[i] ) && ( mask == masks[i] ) ) {
    3.63 +                                next;
    3.64 +                            }
    3.65 +                        }
    3.66 +                        ips[pairs] = masked_ip;
    3.67 +                        masks[pairs] = mask;
    3.68 +                        pairs++;
    3.69 +                        printf( "local = %d.%d.%d.%d/%d.%d.%d.%d\n",
    3.70 +                                and( 0xFF, masked_ip / 2^24 ),
    3.71 +                                and( 0xFF, masked_ip / 2^16 ),
    3.72 +                                and( 0xFF, masked_ip / 2^8 ),
    3.73 +                                and( 0xFF, masked_ip / 2^0 ),
    3.74 +                                and( 0xFF, mask / 2^24 ),
    3.75 +                                and( 0xFF, mask / 2^16 ),
    3.76 +                                and( 0xFF, mask / 2^8 ),
    3.77 +                                and( 0xFF, mask / 2^0 ) );
    3.78 +                    }
    3.79 +                }
    3.80 +            ' >"${CT_BUILD_DIR}/tsocks.conf"
    3.81 +            ( echo "server = ${server_ip}";
    3.82 +              echo "server_port = ${CT_PROXY_PORT}";
    3.83 +              [ -n "${CT_PROXY_USER}"   ] && echo "default_user=${CT_PROXY_USER}";
    3.84 +              [ -n "${CT_PROXY_PASS}" ] && echo "default_pass=${CT_PROXY_PASS}";
    3.85 +            ) >>"${CT_BUILD_DIR}/tsocks.conf"
    3.86 +            case "${CT_PROXY_TYPE/socks}" in
    3.87 +                4|5) proxy_type="${CT_PROXY_TYPE/socks}";;
    3.88 +                auto)
    3.89 +                    reply=$(inspectsocks "${server_ip}" "${CT_PROXY_PORT}" 2>&1 || true)
    3.90 +                    case "${reply}" in
    3.91 +                        *"server is a version 4 socks server") proxy_type=4;;
    3.92 +                        *"server is a version 5 socks server") proxy_type=5;;
    3.93 +                        *) CT_Abort "Unable to determine SOCKS proxy type for '${CT_PROXY_HOST}:${CT_PROXY_PORT}'"
    3.94 +                    esac
    3.95 +                    ;;
    3.96 +            esac
    3.97 +            echo "server_type = ${proxy_type}" >> "${CT_BUILD_DIR}/tsocks.conf"
    3.98 +            CT_HasOrAbort tsocks
    3.99 +            # If tsocks was found, then validateconf is present (distributed with tsocks).
   3.100 +            CT_DoExecLog DEBUG validateconf -f "${CT_BUILD_DIR}/tsocks.conf"
   3.101 +            export TSOCKS_CONF_FILE="${CT_BUILD_DIR}/tsocks.conf"
   3.102 +            . tsocks -on
   3.103 +            ;;
   3.104 +    esac
   3.105 +}
   3.106 +
   3.107  # Download an URL using wget
   3.108  # Usage: CT_DoGetFileWget <URL>
   3.109  CT_DoGetFileWget() {
   3.110 @@ -353,35 +453,39 @@
   3.111          return 0
   3.112      fi
   3.113  
   3.114 +    # Try to retrieve the file
   3.115      CT_Pushd "${CT_TARBALLS_DIR}"
   3.116 -    # We'd rather have a bzip2'ed tarball, then gzipped tarball, plain tarball,
   3.117 -    # or, as a failover, a file without extension.
   3.118 -    # Try local copy first, if it exists
   3.119 -    for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
   3.120 -        CT_DoLog DEBUG "Trying '${CT_LOCAL_TARBALLS_DIR}/${file}${ext}'"
   3.121 -        if [ -r "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" -a \
   3.122 -             "${CT_FORCE_DOWNLOAD}" != "y" ]; then
   3.123 -            CT_DoLog EXTRA "Using '${file}' from local storage"
   3.124 -            ln -sv "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog ALL
   3.125 -            return 0
   3.126 -        fi
   3.127 -    done
   3.128 +
   3.129 +    if [ -n "${CT_LOCAL_TARBALLS_DIR}" ]; then
   3.130 +        CT_DoLog DEBUG "Trying to retrieve an already downloaded copy of '${file}'"
   3.131 +        # We'd rather have a bzip2'ed tarball, then gzipped tarball, plain tarball,
   3.132 +        # or, as a failover, a file without extension.
   3.133 +        # Try local copy first, if it exists
   3.134 +        for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
   3.135 +            CT_DoLog DEBUG "Trying '${CT_LOCAL_TARBALLS_DIR}/${file}${ext}'"
   3.136 +            if [ -r "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" -a \
   3.137 +                 "${CT_FORCE_DOWNLOAD}" != "y" ]; then
   3.138 +                CT_DoLog EXTRA "Got '${file}' from local storage"
   3.139 +                ln -sv "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog ALL
   3.140 +                return 0
   3.141 +            fi
   3.142 +        done
   3.143 +    fi
   3.144  
   3.145      # Not found locally, try from the network
   3.146 -    CT_DoLog EXTRA "Retrieving '${file}' from network"
   3.147  
   3.148      # Start with LAN mirror
   3.149      if [ "${CT_USE_LAN_MIRROR}" = "y" ]; then
   3.150 -        LAN_URLs=
   3.151 -        for pat in ${CT_LAN_MIRROR_PATTERNS}; do
   3.152 +        CT_DoSetProxy ${CT_LAN_MIRROR_USE_PROXY:+${CT_PROXY_TYPE}}
   3.153 +        CT_DoLog DEBUG "Trying to retrieve a copy of '${file}' from LAN mirror '${CT_LAN_MIRROR_HOSTNAME}'"
   3.154 +        CT_TestOrAbort "Please set the LAN mirror hostname" -n "${CT_LAN_MIRROR_HOSTNAME}"
   3.155 +        CT_TestOrAbort "Please tell me where to find tarballs on the LAN mirror '${CT_LAN_MIRROR_HOSTNAME}'" -n "${CT_LAN_MIRROR_BASE}"
   3.156 +        for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
   3.157              # Please note: we just have the file's basename in a single piece.
   3.158              # So we have to just try and split it back into name and version... :-(
   3.159 -            pat="${pat//\%pkg/${file%-*}}"
   3.160 -            pat="${pat//\%ver/${file##*-}}"
   3.161 -            LAN_URLs="${LAN_URLs} ${CT_LAN_MIRROR_SCHEME}://${CT_LAN_MIRROR_HOSTNAME}/${pat}"
   3.162 -        done
   3.163 -        for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
   3.164 -            for url in ${LAN_URLs}; do
   3.165 +            for url in "${CT_LAN_MIRROR_SCHEME}://${CT_LAN_MIRROR_HOSTNAME}/${CT_LAN_MIRROR_BASE}/${file%-*}"  \
   3.166 +                       "${CT_LAN_MIRROR_SCHEME}://${CT_LAN_MIRROR_HOSTNAME}/${CT_LAN_MIRROR_BASE}";            \
   3.167 +            do
   3.168                  CT_DoLog DEBUG "Trying '${url}/${file}${ext}'"
   3.169                  CT_DoGetFile "${url}/${file}${ext}"
   3.170                  if [ -f "${file}${ext}" ]; then
   3.171 @@ -393,6 +497,7 @@
   3.172                          mv "${file}${ext}" "${CT_LOCAL_TARBALLS_DIR}" |CT_DoLog ALL
   3.173                          ln -sv "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog ALL
   3.174                      fi
   3.175 +                    CT_DoLog EXTRA "Got '${file}' from the LAN mirror"
   3.176                      return 0
   3.177                  fi
   3.178              done
   3.179 @@ -400,6 +505,7 @@
   3.180      fi
   3.181  
   3.182      # OK, available neither localy, nor from the LAN mirror (if any).
   3.183 +    CT_DoSetProxy ${CT_PROXY_TYPE}
   3.184      for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
   3.185          # Try all urls in turn
   3.186          for url in "$@"; do
   3.187 @@ -414,13 +520,14 @@
   3.188                      mv "${file}${ext}" "${CT_LOCAL_TARBALLS_DIR}" |CT_DoLog ALL
   3.189                      ln -sv "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog ALL
   3.190                  fi
   3.191 +                CT_DoLog EXTRA "Got '${file}' from the Internet"
   3.192                  return 0
   3.193              fi
   3.194          done
   3.195      done
   3.196      CT_Popd
   3.197  
   3.198 -    CT_Abort "Could not download '${file}', and not present in '${CT_LOCAL_TARBALLS_DIR}'"
   3.199 +    CT_Abort "Could not retrieve '${file}'."
   3.200  }
   3.201  
   3.202  # Extract a tarball and patch the resulting sources if necessary.