scripts/functions
branchnewlib
changeset 1770 f7eaca0e8519
parent 1365 c4d124ed9f8e
     1.1 --- a/scripts/functions	Sun Apr 19 16:17:11 2009 +0000
     1.2 +++ b/scripts/functions	Sun Jan 31 13:09:01 2010 +0100
     1.3 @@ -288,103 +288,6 @@
     1.4      return 0
     1.5  }
     1.6  
     1.7 -# Set environment for proxy access
     1.8 -# Usage: CT_DoSetProxy <proxy_type>
     1.9 -# where proxy_type is one of 'http', 'sockssys', 'socks4' or 'socks5',
    1.10 -# or empty (to not change proxy settings).
    1.11 -CT_DoSetProxy() {
    1.12 -    case "${1}" in
    1.13 -        http)
    1.14 -            http_proxy="http://"
    1.15 -            case  "${CT_PROXY_USER}:${CT_PROXY_PASS}" in
    1.16 -                :)      ;;
    1.17 -                :*)     http_proxy="${http_proxy}:${CT_PROXY_PASS}@";;
    1.18 -                *:)     http_proxy="${http_proxy}${CT_PROXY_USER}@";;
    1.19 -                *:*)    http_proxy="${http_proxy}${CT_PROXY_USER}:${CT_PROXY_PASS}@";;
    1.20 -            esac
    1.21 -            export http_proxy="${http_proxy}${CT_PROXY_HOST}:${CT_PROXY_PORT}/"
    1.22 -            export https_proxy="${http_proxy}"
    1.23 -            export ftp_proxy="${http_proxy}"
    1.24 -            CT_DoLog DEBUG "http_proxy='${http_proxy}'"
    1.25 -            ;;
    1.26 -        sockssys)
    1.27 -            CT_HasOrAbort tsocks
    1.28 -            . tsocks -on
    1.29 -            ;;
    1.30 -        socks*)
    1.31 -            # Remove any lingering config file from any previous run
    1.32 -            rm -f "${CT_BUILD_DIR}/tsocks.conf"
    1.33 -            # Find all interfaces and build locally accessible networks
    1.34 -            server_ip=$(ping -c 1 -W 2 "${CT_PROXY_HOST}" |head -n 1 |sed -r -e 's/^[^\(]+\(([^\)]+)\).*$/\1/;' || true)
    1.35 -            CT_TestOrAbort "SOCKS proxy '${CT_PROXY_HOST}' has no IP." -n "${server_ip}"
    1.36 -            /sbin/ifconfig |"${awk}" -v server_ip="${server_ip}" '
    1.37 -                BEGIN {
    1.38 -                    split( server_ip, tmp, "\\." );
    1.39 -                    server_ip_num = tmp[1] * 2^24 + tmp[2] * 2^16 + tmp[3] * 2^8 + tmp[4] * 2^0;
    1.40 -                    pairs = 0;
    1.41 -                }
    1.42 -
    1.43 -                $0 ~ /^[[:space:]]*inet addr:/ {
    1.44 -                    split( $2, tmp, ":|\\." );
    1.45 -                    if( ( tmp[2] == 127 ) && ( tmp[3] == 0 ) && ( tmp[4] == 0 ) && ( tmp[5] == 1 ) ) {
    1.46 -                        /* Skip 127.0.0.1, it'\''s taken care of by tsocks itself */
    1.47 -                        next;
    1.48 -                    }
    1.49 -                    ip_num = tmp[2] * 2^24 + tmp[3] * 2^16 + tmp[4] * 2 ^8 + tmp[5] * 2^0;
    1.50 -                    i = 32;
    1.51 -                    do {
    1.52 -                        i--;
    1.53 -                        mask = 2^32 - 2^i;
    1.54 -                    } while( (i!=0) && ( and( server_ip_num, mask ) == and( ip_num, mask ) ) );
    1.55 -                    mask = and( 0xFFFFFFFF, lshift( mask, 1 ) );
    1.56 -                    if( (i!=0) && (mask!=0) ) {
    1.57 -                        masked_ip = and( ip_num, mask );
    1.58 -                        for( i=0; i<pairs; i++ ) {
    1.59 -                            if( ( masked_ip == ips[i] ) && ( mask == masks[i] ) ) {
    1.60 -                                next;
    1.61 -                            }
    1.62 -                        }
    1.63 -                        ips[pairs] = masked_ip;
    1.64 -                        masks[pairs] = mask;
    1.65 -                        pairs++;
    1.66 -                        printf( "local = %d.%d.%d.%d/%d.%d.%d.%d\n",
    1.67 -                                and( 0xFF, masked_ip / 2^24 ),
    1.68 -                                and( 0xFF, masked_ip / 2^16 ),
    1.69 -                                and( 0xFF, masked_ip / 2^8 ),
    1.70 -                                and( 0xFF, masked_ip / 2^0 ),
    1.71 -                                and( 0xFF, mask / 2^24 ),
    1.72 -                                and( 0xFF, mask / 2^16 ),
    1.73 -                                and( 0xFF, mask / 2^8 ),
    1.74 -                                and( 0xFF, mask / 2^0 ) );
    1.75 -                    }
    1.76 -                }
    1.77 -            ' >"${CT_BUILD_DIR}/tsocks.conf"
    1.78 -            ( echo "server = ${server_ip}";
    1.79 -              echo "server_port = ${CT_PROXY_PORT}";
    1.80 -              [ -n "${CT_PROXY_USER}"   ] && echo "default_user=${CT_PROXY_USER}";
    1.81 -              [ -n "${CT_PROXY_PASS}" ] && echo "default_pass=${CT_PROXY_PASS}";
    1.82 -            ) >>"${CT_BUILD_DIR}/tsocks.conf"
    1.83 -            case "${CT_PROXY_TYPE/socks}" in
    1.84 -                4|5) proxy_type="${CT_PROXY_TYPE/socks}";;
    1.85 -                auto)
    1.86 -                    reply=$(inspectsocks "${server_ip}" "${CT_PROXY_PORT}" 2>&1 || true)
    1.87 -                    case "${reply}" in
    1.88 -                        *"server is a version 4 socks server") proxy_type=4;;
    1.89 -                        *"server is a version 5 socks server") proxy_type=5;;
    1.90 -                        *) CT_Abort "Unable to determine SOCKS proxy type for '${CT_PROXY_HOST}:${CT_PROXY_PORT}'"
    1.91 -                    esac
    1.92 -                    ;;
    1.93 -            esac
    1.94 -            echo "server_type = ${proxy_type}" >> "${CT_BUILD_DIR}/tsocks.conf"
    1.95 -            CT_HasOrAbort tsocks
    1.96 -            # If tsocks was found, then validateconf is present (distributed with tsocks).
    1.97 -            CT_DoExecLog DEBUG validateconf -f "${CT_BUILD_DIR}/tsocks.conf"
    1.98 -            export TSOCKS_CONF_FILE="${CT_BUILD_DIR}/tsocks.conf"
    1.99 -            . tsocks -on
   1.100 -            ;;
   1.101 -    esac
   1.102 -}
   1.103 -
   1.104  # Download an URL using wget
   1.105  # Usage: CT_DoGetFileWget <URL>
   1.106  CT_DoGetFileWget() {
   1.107 @@ -506,10 +409,9 @@
   1.108      # Add URLs on the LAN mirror
   1.109      LAN_URLS=
   1.110      if [ "${CT_USE_MIRROR}" = "y" ]; then
   1.111 -        CT_TestOrAbort "Please set the LAN mirror hostname" -n "${CT_MIRROR_HOSTNAME}"
   1.112 -        CT_TestOrAbort "Please tell me where to find tarballs on the LAN mirror '${CT_MIRROR_HOSTNAME}'" -n "${CT_MIRROR_BASE}"
   1.113 -        LAN_URLS="${LAN_URLS} ${CT_MIRROR_SCHEME}://${CT_MIRROR_HOSTNAME}/${CT_MIRROR_BASE}/${file%-*}"
   1.114 -        LAN_URLS="${LAN_URLS} ${CT_MIRROR_SCHEME}://${CT_MIRROR_HOSTNAME}/${CT_MIRROR_BASE}"
   1.115 +        CT_TestOrAbort "Please set the mirror base URL" -n "${CT_MIRROR_BASE_URL}"
   1.116 +        LAN_URLS="${LAN_URLS} ${CT_MIRROR_BASE_URL}/${file%-*}"
   1.117 +        LAN_URLS="${LAN_URLS} ${CT_MIRROR_BASE_URL}"
   1.118  
   1.119          if [ "${CT_PREFER_MIRROR}" = "y" ]; then
   1.120              CT_DoLog DEBUG "Pre-pending LAN mirror URLs"
   1.121 @@ -521,7 +423,6 @@
   1.122      fi
   1.123  
   1.124      # Scan all URLs in turn, and try to grab a tarball from there
   1.125 -    CT_DoSetProxy ${CT_PROXY_TYPE}
   1.126      for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
   1.127          # Try all urls in turn
   1.128          for url in ${URLS}; do
   1.129 @@ -567,7 +468,6 @@
   1.130      CT_MktempDir tmp_dir
   1.131      CT_Pushd "${tmp_dir}"
   1.132  
   1.133 -    CT_DoSetProxy ${CT_PROXY_TYPE}
   1.134      CT_DoExecLog ALL cvs -z 9 -d "${uri}" co -P ${tag} "${module}"
   1.135      [ -n "${dirname}" ] && CT_DoExecLog ALL mv "${module}" "${dirname}"
   1.136      CT_DoExecLog ALL tar cjf "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${dirname:-${module}}"
   1.137 @@ -600,7 +500,6 @@
   1.138      CT_MktempDir tmp_dir
   1.139      CT_Pushd "${tmp_dir}"
   1.140  
   1.141 -    CT_DoSetProxy ${CT_PROXY_TYPE}
   1.142      CT_DoExecLog ALL svn export ${rev:+-r ${rev}} "${uri}" "${basename}"
   1.143      CT_DoExecLog ALL tar cjf "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${basename}"
   1.144      CT_SaveLocal "${CT_TARBALLS_DIR}/${basename}.tar.bz2"
   1.145 @@ -844,8 +743,8 @@
   1.146      CT_DoLog DEBUG "  Saving environment and aliases"
   1.147      # We must omit shell functions, and some specific bash variables
   1.148      # that break when restoring the environment, later. We could do
   1.149 -    # all the processing in the gawk script, but a sed is easier...
   1.150 -    set |"${awk}" '
   1.151 +    # all the processing in the awk script, but a sed is easier...
   1.152 +    set |awk '
   1.153                BEGIN { _p = 1; }
   1.154                $0~/^[^ ]+ \(\)/ { _p = 0; }
   1.155                _p == 1