mirror of
https://github.com/seriyps/mtproto_proxy.git
synced 2026-08-04 15:19:47 +00:00
Make it possible to configure docker via environment variables
This commit is contained in:
parent
8dd4511701
commit
2f015e2f3f
2 changed files with 36 additions and 15 deletions
12
README.md
12
README.md
|
|
@ -32,11 +32,17 @@ docker run -d --network=host seriyps/mtproto-proxy
|
|||
docker run -d --network=host seriyps/mtproto-proxy -p 443 -s d0d6e111bada5511fcce9584deadbeef -t dcbe8f1493fa4cd9ab300891c0b5b326
|
||||
```
|
||||
|
||||
or via environmet variables
|
||||
|
||||
```bash
|
||||
docker run -d --network=host -e MTP_PORT=443 -e MTP_SECRET=d0d6e111bada5511fcce9584deadbeef -e MTP_TAG=dcbe8f1493fa4cd9ab300891c0b5b326 seriyps/mtproto-proxy
|
||||
```
|
||||
|
||||
Where
|
||||
|
||||
* `-p 443` proxy port
|
||||
* `-s d0d6e111bada5511fcce9584deadbeef` proxy secret (don't append `dd`! it should be 32 chars long!)
|
||||
* `-t dcbe8f1493fa4cd9ab300891c0b5b326` ad-tag that you get from [@MTProxybot](https://t.me/MTProxybot)
|
||||
* `-p 443` / `MTP_PORT` proxy port
|
||||
* `-s d0d6e111bada5511fcce9584deadbeef` / `MTP_SECRET` proxy secret (don't append `dd`! it should be 32 chars long!)
|
||||
* `-t dcbe8f1493fa4cd9ab300891c0b5b326` / `MTP_TAG` ad-tag that you get from [@MTProxybot](https://t.me/MTProxybot)
|
||||
|
||||
### To run with custom config-file
|
||||
|
||||
|
|
|
|||
39
start.sh
39
start.sh
|
|
@ -10,6 +10,13 @@ usage() {
|
|||
echo "${THIS}"
|
||||
echo "To start in single-port mode configured from command-line:"
|
||||
echo "${THIS} -p <port> -s <secret> -t <ad tag>"
|
||||
echo "Parameters:"
|
||||
echo "-p <port>: port to listen on. 1-65535"
|
||||
echo "-s <secret>: proxy secret. 32 hex characters 0-9 a-f"
|
||||
echo "-t <ad tag>: promo tag, that you get from @MTProxybot. 32 hex characters"
|
||||
echo "port secret and tag can also be configured via environment variables:"
|
||||
echo "MTP_PORT, MTP_SECRET, MTP_TAG"
|
||||
echo "If both command line and environment are set, command line have higher priority"
|
||||
}
|
||||
|
||||
error() {
|
||||
|
|
@ -18,36 +25,44 @@ error() {
|
|||
exit 1
|
||||
}
|
||||
|
||||
NUM_OPTS=0
|
||||
PORT=""
|
||||
SECRET=""
|
||||
TAG=""
|
||||
# check environment variables
|
||||
PORT=${MTP_PORT:-""}
|
||||
SECRET=${MTP_SECRET:-""}
|
||||
TAG=${MTP_TAG:-""}
|
||||
|
||||
# check command line options
|
||||
while getopts "p:s:t:h" o; do
|
||||
case "${o}" in
|
||||
p)
|
||||
PORT=${OPTARG}
|
||||
test ${PORT} -gt 0 -a ${PORT} -lt 65535 || error "Invalid port value: ${PORT}"
|
||||
;;
|
||||
s)
|
||||
SECRET=${OPTARG}
|
||||
[ -n "`echo $SECRET | grep -x '[[:xdigit:]]\{32\}'`" ] || error "Invalid secret. Should be 32 chars of 0-9 a-f"
|
||||
;;
|
||||
t)
|
||||
TAG=${OPTARG}
|
||||
[ -n "`echo $TAG | grep -x '[[:xdigit:]]\{32\}'`" ] || error "Invalid tag. Should be 32 chars of 0-9 a-f"
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
esac
|
||||
NUM_OPTS=$((NUM_OPTS + 1))
|
||||
done
|
||||
|
||||
if [ $NUM_OPTS -eq 0 ]; then
|
||||
exec $CMD
|
||||
elif [ $NUM_OPTS -eq 3 ]; then
|
||||
# if at least one option is set...
|
||||
if [ -n "${PORT}" -o -n "${SECRET}" -o -n "${TAG}" ]; then
|
||||
# If at least one of them not set...
|
||||
[ -z "${PORT}" -o -z "${SECRET}" -o -z "${SECRET}" ] && \
|
||||
error "Not enough options: -p '${PORT}' -s '${SECRET}' -t '${TAG}'"
|
||||
|
||||
# validate format
|
||||
[ ${PORT} -gt 0 -a ${PORT} -lt 65535 ] || \
|
||||
error "Invalid port value: ${PORT}"
|
||||
[ -n "`echo $SECRET | grep -x '[[:xdigit:]]\{32\}'`" ] || \
|
||||
error "Invalid secret. Should be 32 chars of 0-9 a-f"
|
||||
[ -n "`echo $TAG | grep -x '[[:xdigit:]]\{32\}'`" ] || \
|
||||
error "Invalid tag. Should be 32 chars of 0-9 a-f"
|
||||
|
||||
exec $CMD -mtproto_proxy ports "[#{name => mtproto_proxy, port => $PORT, secret => <<\"$SECRET\">>, tag => <<\"$TAG\">>}]"
|
||||
else
|
||||
error "Not enough options: -p '${PORT}' -s '${SECRET}' -t '${TAG}'"
|
||||
exec $CMD
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue