#!/bin/sh set -e echo "Setup default route" default_route_ip=$(ip route | grep default | awk '{print $3}') if [[ -z "$default_route_ip" ]]; then echo "No default route configured" >&2 exit 1 fi echo "Default route $default_route_tp" echo "Check sysctl" if [[ "$(cat /proc/sys/net/ipv4/conf/all/src_valid_mark)" != "1" ]]; then echo "sysctl net.ipv4.conf.all.src_valid_mark=1 is not set" >&2 exit 1 fi /usr/bin/goxray "$URL" & \ echo "runned" # Allow traffic to local subnets for local_subnet in ${LOCAL_SUBNETS//,/$IFS} do echo "Allowing traffic to local subnet ${local_subnet}" >&2 ip route add $local_subnet via $default_route_ip iptables -I OUTPUT -d $local_subnet -j ACCEPT done shutdown () { killall goxray exit 0 } trap shutdown SIGTERM SIGINT SIGQUIT sleep infinity & wait $!