#!/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" <> "$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