From 8db460ff99aa085fb12fc2c1a73d1a8ddd4d4e73 Mon Sep 17 00:00:00 2001 From: rany Date: Wed, 17 Mar 2021 10:15:03 +0200 Subject: [PATCH 1/3] Add new helper script --- helper.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 helper.sh diff --git a/helper.sh b/helper.sh new file mode 100755 index 0000000..6a4ce4e --- /dev/null +++ b/helper.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# arguments +country=${1-us} +proxytype=${2-direct} + +if [ -z "$3" ] +then + port=17160 + for x in {a..z}{a..z} # loop over all possible country codes (676 possibilities) + do + port=$((port+1)) + if [ "$x" == "$country" ] + then + true + break + else + false + fi + done || { echo "country code $country is invalid" >&2; exit 1;} + + case $proxytype in # port range = 17160+1 -> 17160+676*5 + direct) port=$((676*0+port)) ;; + peer) port=$((676*1+port)) ;; + lum) port=$((676*2+port)) ;; + virt) port=$((676*3+port)) ;; + pool) port=$((676*4+port)) ;; + *) echo "proxy-type $proxytype invalid" >&2 + exit 1 ;; + esac +else + port=$3 +fi + +echo "country $country" +echo "proxytype $proxytype" +echo "proxy 127.0.0.1:$port" +echo +exec hola-proxy -bind-address "127.0.0.1:$port" -country "$country" -proxy-type "$proxytype" -verbosity 50 From 700ae4a4f464448b92642cc8ff3be834b744c67a Mon Sep 17 00:00:00 2001 From: rany Date: Wed, 17 Mar 2021 12:26:37 +0200 Subject: [PATCH 2/3] try to locate hola-proxy in ~/go/bin/hola-proxy also --- helper.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/helper.sh b/helper.sh index 6a4ce4e..59579ab 100755 --- a/helper.sh +++ b/helper.sh @@ -32,8 +32,22 @@ else port=$3 fi -echo "country $country" -echo "proxytype $proxytype" -echo "proxy 127.0.0.1:$port" -echo -exec hola-proxy -bind-address "127.0.0.1:$port" -country "$country" -proxy-type "$proxytype" -verbosity 50 +try_binary() { + for x in "${@}" + do + type -a "$x" >/dev/null 2>&1 && { echo "$x"; return 0; } || false + done || return 1 +} + +binary=`try_binary "hola-proxy" "$HOME/go/bin/hola-proxy"` +if [ -n "$binary" ] +then + echo "country $country" + echo "proxytype $proxytype" + echo "proxy 127.0.0.1:$port" + echo + exec "$binary" -bind-address "127.0.0.1:$port" -country "$country" -proxy-type "$proxytype" -verbosity 50 +else + echo "hola-proxy binary cannot be found" >&2 + exit 1 +fi From bc0b0df26ab5611cbe47320fa451430c083859d7 Mon Sep 17 00:00:00 2001 From: rany Date: Wed, 17 Mar 2021 12:27:25 +0200 Subject: [PATCH 3/3] Use $(...) notation instead of legacy backticked --- helper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper.sh b/helper.sh index 59579ab..8dc5171 100755 --- a/helper.sh +++ b/helper.sh @@ -39,7 +39,7 @@ try_binary() { done || return 1 } -binary=`try_binary "hola-proxy" "$HOME/go/bin/hola-proxy"` +binary=$(try_binary "hola-proxy" "$HOME/go/bin/hola-proxy") if [ -n "$binary" ] then echo "country $country"