<commit_before>#!/bin/sh

suffix="-tmp-$$-`date +%H-%M-%S`"

trap "tidy" SIGHUP SIGINT SIGTERM

tidy () {
  rm -f /tmp/*$suffix*
  exit $1
}

abend () {
  echo "error: $1" 1>&2
  tidy 1
}

uname=`uname`
dirname=`dirname $0`

if ! which postfix > /dev/null 2>&1; then
  abend "install Postfix with Cyrus SASL" 
fi

if which yum > /dev/null && ! rpm -q cyrus-sasl-plain > /dev/null; then
  abend "install cyrus-sasl-plain" 
fi

if [ "$uname-x" = "FreeBSD-x" ]; then
  . "$dirname/rc.subr"
  confdir="/usr/local/etc/postfix"
else
  confdir="/etc/postfix"
fi

# If we have no original file, create one.
if [ ! -e "$confdir/main.cf.orig" ]; then
  sudo cp "$confdir/main.cf" "$confdir/main.cf.orig"
fi

cp "$confdir/main.cf.orig" "/tmp/main$suffix.cf"

for file in /etc/ssl/certs/ca-bundle.crt \
            /usr/local/share/certs/ca-root-nss.crt
do
  [ -e $file ] && smtp_tls_CAfile=/etc/ssl/certs/ca-bundle.crt
done

cat <<EOF >> "/tmp/main$suffix.cf"

# Relay thorugh GMail.
relayhost=smtp.gmail.com:587<commit_msg>Fix Postfix certs configuration on FreeBSD.<commit_after>#!/bin/sh

suffix="-tmp-$$-`date +%H-%M-%S`"

trap "tidy" SIGHUP SIGINT SIGTERM

tidy () {
  rm -f /tmp/*$suffix*
  exit $1
}

abend () {
  echo "error: $1" 1>&2
  tidy 1
}

uname=`uname`
dirname=`dirname $0`

if ! which postfix > /dev/null 2>&1; then
  abend "install Postfix with Cyrus SASL" 
fi

if which yum > /dev/null && ! rpm -q cyrus-sasl-plain > /dev/null; then
  abend "install cyrus-sasl-plain" 
fi

if [ "$uname-x" = "FreeBSD-x" ]; then
  . "$dirname/rc.subr"
  confdir="/usr/local/etc/postfix"
else
  confdir="/etc/postfix"
fi

# If we have no original file, create one.
if [ ! -e "$confdir/main.cf.orig" ]; then
  sudo cp "$confdir/main.cf" "$confdir/main.cf.orig"
fi

cp "$confdir/main.cf.orig" "/tmp/main$suffix.cf"

for file in /etc/ssl/certs/ca-bundle.crt \
            /usr/local/share/certs/ca-root-nss.crt
do
  [ -e $file ] && smtp_tls_CAfile=$file
done

cat <<EOF >> "/tmp/main$suffix.cf"

# Relay thorugh GMail.
relayhost=smtp.gmail.com:587
{'fraction_non_alphanumeric': 0.1839645843580915, 'fraction_numerical': 0.010821446138711265, 'mean_word_length': 3.125760649087221, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1330137', 'n_tokens_mistral': 923, 'n_tokens_neox': 882, 'n_words': 196}