<commit_before>#!/bin/bash
# Hadoop dual-nic machine IP forwarding install
# author: <NAME>
#
# Sets up IP forwarding for dual-nic machines
# must be run as root!

function add_line {
  # Adds a line to a file. if that line exists by itself in the file, it will not be added.
  # usage: add_line line file
  line=$1
  file=$2

  if [[ -z $line || -z $file ]]; then
    echo "usage: add_line line file"
    exit 1
  fi

  echo -n $status
  grep $file -e "$line" > /dev/null
  if [[ $? -eq '1' ]]; then
    # if the line wasn't found, then append it to the end of the file
    echo $line >> $file
  fi
}

if [[ $# -ne 2 ]]; then
  echo "usage: $0 card-internal card-external"
  echo "where card-internal is the network card used for the internal network and card-external is the card used for the external network"
  exit 0
fi

# On the current machine, internal is enp12s2, external is enp11s0
internal=$1
external=$2

iptables -A FORWARD -i $internal -j ACCEPT
iptables -A FORWARD -o $external -j ACCEPT
add_line 'net.ipv4.ip_forward=1' /etc/sysctl.conf
# Mask external requests from local LAN nodes with the IP address of the gateway
echo "iptables -t nat -A POSTROUTING -o $external -j MASQUERADE" >> ~/.bashrc<commit_msg>Add separator between code and utility methods, and also add verification that user must be root when the script is run<commit_after>#!/bin/bash
# Hadoop dual-nic machine IP forwarding install
# author: <NAME>
#
# Sets up IP forwarding for dual-nic machines
# must be run as root!

function add_line {
  # Adds a line to a file. if that line exists by itself in the file, it will not be added.
  # usage: add_line line file
  line=$1
  file=$2

  if [[ -z $line || -z $file ]]; then
    echo "usage: add_line line file"
    exit 1
  fi

  echo -n $status
  grep $file -e "$line" > /dev/null
  if [[ $? -eq '1' ]]; then
    # if the line wasn't found, then append it to the end of the file
    echo $line >> $file
  fi
}

################################################################################

if [[ $UID -ne '0' ]]; then
  echo 'Must be run as root!'
  exit 1
fi

if [[ $# -ne 2 ]]; then
  echo "usage: $0 card-internal card-external"
  echo "where card-internal is the network card used for the internal network and card-external is the card used for the external network"
  exit 0
fi

# On the current machine, internal is enp12s2, external is enp11s0
internal=$1
external=$2

iptables -A FORWARD -i $internal -j ACCEPT
iptables -A FORWARD -o $external -j ACCEPT
add_line 'net.ipv4.ip_forward=1' /etc/sysctl.conf
# Mask external requests from local LAN nodes with the IP address of the gateway
echo "iptables -t nat -A POSTROUTING -o $external -j MASQUERADE" >> ~/.bashrc
{'fraction_non_alphanumeric': 0.12670853343184338, 'fraction_numerical': 0.013298854820834873, 'mean_word_length': 3.374798061389338, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '611693', 'n_tokens_mistral': 911, 'n_tokens_neox': 870, 'n_words': 395}