Update castor.sh
This commit is contained in:
parent
6e44574678
commit
e66e0fc3cf
1 changed files with 78 additions and 15 deletions
93
castor.sh
93
castor.sh
|
@ -6,8 +6,10 @@ normal=$(tput sgr0)
|
|||
red=$(tput setaf 1)
|
||||
green=$(tput setaf 2)
|
||||
|
||||
castorheader=" 🦫 "
|
||||
|
||||
usage() {
|
||||
echo "Usage: $(basename "$0") [OPTIONS] COMMAND"
|
||||
echo "$castorheader Usage: $(basename "$0") [OPTIONS] COMMAND"
|
||||
}
|
||||
|
||||
help() {
|
||||
|
@ -20,32 +22,77 @@ ${bold}COMMANDS${normal}
|
|||
stop castor
|
||||
|
||||
${bold}OPTIONS${normal}
|
||||
${bold}-h --help${normal}
|
||||
${bold}-h${normal}
|
||||
Display usage statement
|
||||
${bold}-p --port${normal}=8080
|
||||
${bold}-p${normal}=int
|
||||
Port to run the proxy (default=8080)
|
||||
${bold}-m --mode${normal}=socks|http
|
||||
Proxy mode, either SOCKS5 or HTTP CONNECT proxy (default=socks)
|
||||
${bold}-m${normal}=socks|http
|
||||
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
|
||||
if test -f .env; then
|
||||
export $(grep -v '^#' .env | xargs)
|
||||
# Set default values with env vars (if any)
|
||||
port=$PROXY_PORT
|
||||
mode=$PROXY_MODE
|
||||
else
|
||||
# otherwise set default values
|
||||
port=8080
|
||||
mode=socks
|
||||
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
|
||||
p) port=$OPTARG ;;
|
||||
m) mode=$OPTARG ;;
|
||||
h) help ;;
|
||||
t) tors=$OPTARG ;;
|
||||
h)
|
||||
help
|
||||
exit 0
|
||||
;;
|
||||
?)
|
||||
help
|
||||
exit 1
|
||||
;;
|
||||
help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift "$(($OPTIND -1))"
|
||||
|
@ -73,17 +120,33 @@ if [ "$cmd" != "start" ] && [ "$cmd" != "stop" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Starting castor proxy
|
||||
if [ $cmd = "start" ]; then
|
||||
echo -ne " Starting $mode proxy on port $port... \r"
|
||||
docker-compose up -d -V > /dev/null 2>&1
|
||||
echo ${green}"Your castor $mode proxy is available at localhost:$port"${normal}
|
||||
echo -ne "$castorheader Starting $mode proxy on port $port... \r"
|
||||
docker-compose up -d -V --scale tor=$tors > /dev/null 2>&1
|
||||
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
|
||||
|
||||
# Stopping castor proxy
|
||||
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
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue