github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/bin/helpers/prepare-run-env.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  function setDefaultRoute {
     4      GW=$1;
     5      ip route del default
     6      ip route add default via ${GW}
     7  }
     8  
     9  function ensure_paths {
    10      iptables_path=`which iptables`
    11      if [[ ${iptables_path} == "" ]]; then
    12        echo "required dependency missing: iptables"
    13        exit 1
    14      fi
    15  
    16      # validate utility against valid system paths
    17      basepath=${iptables_path%/*}
    18      echo "iptables basepath detected: ${basepath}"
    19      if ! [[ ${basepath} =~ (^/usr/sbin|^/sbin|^/bin|^/usr/bin) ]]; then
    20        echo "invalid basepath for dependency - check if system PATH has not been altered"
    21        exit 1
    22      fi
    23  
    24      iptables_required_path="/usr/sbin/iptables"
    25  
    26      if ! env [ -x "${iptables_required_path}" ]; then
    27          ln -s ${iptables_path} ${iptables_required_path}
    28      fi
    29  }
    30  
    31  if [ -n "$GATEWAY" ]; then
    32      echo "new gateway: ${GATEWAY}"
    33      iptables -t nat -A POSTROUTING -o `ip r get ${GATEWAY} | awk '{ print $3 }'` -j MASQUERADE
    34      setDefaultRoute ${GATEWAY}
    35  fi
    36  
    37  if [ -n "$DEFAULT_ROUTE" ]; then
    38      echo "new default route: ${DEFAULT_ROUTE}"
    39      setDefaultRoute ${DEFAULT_ROUTE}
    40  fi
    41  
    42  if [ -n "$PUBLIC_ROUTE" ]; then
    43      echo "adding route: ${PUBLIC_ROUTE}"
    44      eval ${PUBLIC_ROUTE}
    45  fi
    46  
    47  if [ ! -d "$OS_DIR_RUN" ]; then
    48      mkdir -p $OS_DIR_RUN
    49  fi
    50  
    51  if [ ! -d "$OS_DIR_DATA" ]; then
    52      mkdir -p $OS_DIR_DATA
    53  fi
    54  
    55  ensure_paths