notion / entrypoint.sh
clash-linux's picture
Upload 17 files
94ed8a9 verified
#!/bin/sh
set -e
# This script configures and runs the application with proxychains if STASTIC_PROXY is set.
# It is designed to be the ENTRYPOINT of a Docker container.
if [ -n "$STASTIC_PROXY" ]; then
echo "STASTIC_PROXY is set. Configuring proxychains..."
# Extract details from STASTIC_PROXY
# Format: http://user:pass@host:port
PROTO=$(echo "$STASTIC_PROXY" | grep :// | sed -e's,^\(.*://\).*,\1,g' | sed -e 's,://,,g')
URL_NO_PROTO=$(echo "$STASTIC_PROXY" | sed -e 's,^.*://,,g')
USER_PASS=$(echo "$URL_NO_PROTO" | grep -o '.*@' | sed 's/@//')
HOST_PORT=$(echo "$URL_NO_PROTO" | sed -e "s,$USER_PASS@,,g")
HOST=$(echo "$HOST_PORT" | cut -d: -f1)
PORT=$(echo "$HOST_PORT" | cut -d: -f2)
# Default to http if protocol is not supported by proxychains
if [ "$PROTO" != "http" ] && [ "$PROTO" != "socks4" ] && [ "$PROTO" != "socks5" ]; then
echo "Warning: Unsupported proxy type '$PROTO'. Defaulting to 'http'."
PROTO="http"
fi
# Create proxychains config in the home directory of the 'node' user
CONFIG_DIR="/home/node/.proxychains"
mkdir -p "$CONFIG_DIR"
CONFIG_FILE="$CONFIG_DIR/proxychains.conf"
# Write base config
cat > "$CONFIG_FILE" <<EOF
strict_chain
proxy_dns
# Exclude local traffic from proxying, so the app can talk to the local ProxyServer.
localnet 127.0.0.0/8
localnet ::1/128
[ProxyList]
EOF
# Add proxy server entry
if [ -n "$USER_PASS" ]; then
USER=$(echo "$USER_PASS" | cut -d: -f1)
PASS=$(echo "$USER_PASS" | cut -d: -f2)
echo "$PROTO $HOST $PORT $USER $PASS" >> "$CONFIG_FILE"
echo "Configured proxy: $PROTO://$USER_PASS@$HOST:$PORT"
else
echo "$PROTO $HOST $PORT" >> "$CONFIG_FILE"
echo "Configured proxy: $PROTO://$HOST:$PORT"
fi
echo "Starting application with proxychains..."
# Execute the command passed to the script, wrapped in proxychains
exec proxychains4 "$@"
else
echo "STASTIC_PROXY is not set. Starting application without proxy."
# Execute the command as is
exec "$@"
fi