<commit_before>#!/bin/bash

# Replaces string "IPADDRESS_AWKARD" with the systems actual IP address in the ip rule's name and content

incomingHost=$1
incomingPort=$2
outgoingHost=$3
outgoingPort=$4

nginxRuleContent="

server {
	listen ${incomingHost}:${incomingPort};

	location ~ ^/ {
	    proxy_pass http://${outgoingHost}:${outgoingPort};

        proxy_http_version 1.1;
        proxy_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host \$host;
        proxy_cache_bypass \$http_upgrade;
	}
}
"

nginxRuleFilepath="/etc/nginx/conf.d/${incomingHost}_port${incomingPort}_to_${outgoingHost}_port${outgoingPort}.conf"

ipAddress=$(ip addr show eth0 | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/')

nginxRuleContent=$(echo $nginxRuleContent | sed "s/IPADDRESS_AWKWARD/$ipAddress/")
nginxRuleFilepath=$(echo $nginxRuleFilepath | sed "s/IPADDRESS_AWKWARD/$ipAddress/")

#note: need quotes on "$nginxRuleContent" to preserve newlines, though its not sufficient w/ vagrant provisioner for some reason
echo "$nginxRuleContent" > $nginxRuleFilepath<commit_msg>writeNginxRule checks parameters are passed in<commit_after>#!/bin/bash

# Replaces string "IPADDRESS_AWKARD" with the systems actual IP address in the ip rule's name and content

incomingHost=${1:?"Expected incoming host as parameter 1."}
incomingPort=${2:?"Expected incoming port as parameter 2."}
outgoingHost=${3:?"Expected outgoing host as parameter 3."}
outgoingPort=${4:?"Expected outgoing port as parameter 4."}

nginxRuleContent="

server {
	listen ${incomingHost}:${incomingPort};

	location ~ ^/ {
	    proxy_pass http://${outgoingHost}:${outgoingPort};

        proxy_http_version 1.1;
        proxy_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host \$host;
        proxy_cache_bypass \$http_upgrade;
	}
}
"

nginxRuleFilepath="/etc/nginx/conf.d/${incomingHost}_port${incomingPort}_to_${outgoingHost}_port${outgoingPort}.conf"

ipAddress=$(ip addr show eth0 | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/')

nginxRuleContent=$(echo $nginxRuleContent | sed "s/IPADDRESS_AWKWARD/$ipAddress/")
nginxRuleFilepath=$(echo $nginxRuleFilepath | sed "s/IPADDRESS_AWKWARD/$ipAddress/")

#note: need quotes on "$nginxRuleContent" to preserve newlines, though its not sufficient w/ vagrant provisioner for some reason
echo "$nginxRuleContent" > $nginxRuleFilepath
{'fraction_non_alphanumeric': 0.12484897301651228, 'fraction_numerical': 0.010471204188481676, 'mean_word_length': 5.148514851485149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4860595', 'n_tokens_mistral': 832, 'n_tokens_neox': 790, 'n_words': 198}