From ed6092a0053f4fb5a165ccea6dc0ce013fdd9a5f Mon Sep 17 00:00:00 2001 From: Steven Penny Date: Sat, 14 Jun 2014 13:28:46 -0500 Subject: [PATCH] New proxy logic 1. create proxy file if not exist 2. create array from proxy file if not exist 3. if array is empty download proxy file 4. shift continue unless country is US 5. shift continue if proxy is slow 6. shift continue if proxy is blocked by Google 7. print successful proxy 8. save remaining proxies to file --- apt-cyg | 63 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/apt-cyg b/apt-cyg index 1afe4ff..1005bd7 100755 --- a/apt-cyg +++ b/apt-cyg @@ -307,36 +307,51 @@ apt-search () { } proxy () { - local cn sd - cn=proxy.txt + local msg url dt pool px cn + msg=$1 + url=$2 + set -- + dt=proxy.txt cd /tmp - if [ ! -s $cn ] - then - wget -q txt.proxyspy.net/$cn - fi - while read px country + printf 'request %s... ' "$msg" + while : do - if [[ ! $country =~ US ]] + if (( ! $# )) then - (( sd++ )) + touch $dt + mapfile -t pool < $dt + set -- "${pool[@]}" + fi + if (( ! $# )) + then + wget -q -O $dt txt.proxyspy.net/$dt + fi + read px cn <<< $1 + if [[ ! $cn =~ US ]] + then + shift continue fi - if ! wget -q -T 1 -t 1 -O web.json -e http_proxy=$px "$1" + if ! wget -q -T 1 -t 1 -O web.json -e http_proxy=$px "$url" then - (( sd++ )) + shift continue fi - if grep -q 200 web.json - then + case $(awk '/responseStatus/,$0=$2' RS='(, |})' web.json) in + 200) # OK break - else - (( sd++ )) - fi - done < $cn - if (( sd )) - then - sed -i 1,${sd}d $cn - fi + ;; + 400) # out of range start + break + ;; + 403) # suspected terms of service abuse + shift + continue + ;; + esac + done + printf '%s\n' "$px" + printf '%s\n' "$@" > $dt } apt-searchall () { @@ -347,14 +362,12 @@ apt-searchall () { do printf -v qs 'v=1.0&rsz=8&q="%s"+-"index of"+site:%s/%s' $pkg $ste $ARCH (( nof++ )) && echo - echo getting pages . . . - proxy "$api?$qs" + proxy pages "$api?$qs" grep -q pages web.json || continue awk '$2 == "start" {print $4}' RS='[{,]' FS='"' web.json | while read start do - echo getting start $start . . . >&2 - proxy "$api?$qs&start=$start" + proxy "start $start" "$api?$qs&start=$start" >&2 awk '$2 == "url" {print $4}' RS=, FS='"' web.json done > urls.txt awk '!s[$7]++ {print $7}' FS=/ urls.txt