Update castor.sh

This commit is contained in:
Iglesys 2022-11-18 08:16:28 +01:00 committed by GitHub
parent 6e44574678
commit e66e0fc3cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,8 +6,10 @@ normal=$(tput sgr0)
red=$(tput setaf 1) red=$(tput setaf 1)
green=$(tput setaf 2) green=$(tput setaf 2)
castorheader=" 🦫 "
usage() { usage() {
echo "Usage: $(basename "$0") [OPTIONS] COMMAND" echo "$castorheader Usage: $(basename "$0") [OPTIONS] COMMAND"
} }
help() { help() {
@ -20,32 +22,77 @@ ${bold}COMMANDS${normal}
stop castor stop castor
${bold}OPTIONS${normal} ${bold}OPTIONS${normal}
${bold}-h --help${normal} ${bold}-h${normal}
Display usage statement Display usage statement
${bold}-p --port${normal}=8080 ${bold}-p${normal}=int
Port to run the proxy (default=8080) Port to run the proxy (default=8080)
${bold}-m --mode${normal}=socks|http ${bold}-m${normal}=socks|http
Proxy mode, either SOCKS5 or HTTP CONNECT proxy (default=socks) Proxy mode, either SOCKS5 or HTTP CONNECT proxy (default=socks)
${bold}-t${normal}=int
Number of Tor instances to run (default=5)
" "
} }
# Checking that docker is installed
which docker > /dev/null
if [ $? -eq 0 ]
then
docker --version | grep "Docker version" > /dev/null
if ! [ $? -eq 0 ]; then
echo ${red}"Docker not found, please make sure it is installed before running castor (see https://docs.docker.com/engine/install/)"${normal}
exit 1
fi
else
echo ${red}"Docker not found, please make sure it is installed before running castor (see https://docs.docker.com/engine/install/)"${normal}
exit 1
fi
# Checking that docker-compose is installed
which docker-compose > /dev/null
if [ $? -eq 0 ]; then
docker-compose version | grep "docker-compose version" > /dev/null
if ! [ $? -eq 0 ]; then
echo ${red}"Docker not found, please make sure it is installed before running castor (see https://docs.docker.com/engine/install/)"${normal}
exit 1
fi
else
# docker-compose can also be called as 'docker compose'
docker compose version | grep "Docker Compose version" > /dev/null
if ! [ $? -eq 0 ]; then
echo ${red}"Docker not found, please make sure it is installed before running castor (see https://docs.docker.com/engine/install/)"${normal}
exit 1
fi
fi
# Read and export values from .env file # Read and export values from .env file
if test -f .env; then if test -f .env; then
export $(grep -v '^#' .env | xargs) export $(grep -v '^#' .env | xargs)
# Set default values with env vars (if any) # Set default values with env vars (if any)
port=$PROXY_PORT port=$PROXY_PORT
mode=$PROXY_MODE mode=$PROXY_MODE
else
# otherwise set default values
port=8080
mode=socks
fi fi
while getopts ':p:m:h:' OPTION; do # set default value for tor instances
tors=5
# Reading options
while getopts 'hp:m:t:' OPTION; do
case "$OPTION" in case "$OPTION" in
p) port=$OPTARG ;; p) port=$OPTARG ;;
m) mode=$OPTARG ;; m) mode=$OPTARG ;;
h) help ;; t) tors=$OPTARG ;;
h)
help
exit 0
;;
?) ?)
help help
exit 1 exit 1
;; ;;
esac esac
done done
shift "$(($OPTIND -1))" shift "$(($OPTIND -1))"
@ -73,17 +120,33 @@ if [ "$cmd" != "start" ] && [ "$cmd" != "stop" ]; then
exit 1 exit 1
fi fi
# Starting castor proxy # Starting castor proxy
if [ $cmd = "start" ]; then if [ $cmd = "start" ]; then
echo -ne " Starting $mode proxy on port $port... \r" echo -ne "$castorheader Starting $mode proxy on port $port... \r"
docker-compose up -d -V > /dev/null 2>&1 docker-compose up -d -V --scale tor=$tors > /dev/null 2>&1
echo ${green}"Your castor $mode proxy is available at localhost:$port"${normal} if [ $? -eq 0 ]; then
echo ${green}"$castorheader Your castor $mode proxy is available at localhost:$port"${normal}
exit 0
else
echo ${red}"Failed to start castor (try using docker commands, see README)"${normal}
exit 1
fi
fi fi
# Stopping castor proxy # Stopping castor proxy
if [ $cmd = "stop" ]; then if [ $cmd = "stop" ]; then
echo -ne " Stoping running castor proxy... \r" echo -ne "$castorheader Stoping running castor proxy... \r"
docker-compose stop > /dev/null 2>&1 docker-compose stop > /dev/null 2>&1
if ! [ $? -eq 0 ]; then
echo ${red}"Failed to stop castor (try using docker commands, see README)"${normal}
exit 1
fi
docker-compose down > /dev/null 2>&1 docker-compose down > /dev/null 2>&1
echo ${green}"Successfully stoped castor proxy"${normal} if ! [ $? -eq 0 ]; then
echo ${red}"Failed to stop castor (try using docker commands, see README)"${normal}
exit 1
fi
echo ${green}"$castorheader Successfully stoped castor proxy"${normal}
exit 0
fi fi