<commit_before>#!/bin/bash

[ -z "$1" ] && { echo >&2 "Please enter domain name as the first argument"; exit 1; }
[ -z "$2" ] && { echo >&2 "Please enter container name as the second argument"; exit 1; }

CERT_DIR="/etc/letsencrypt/$1"
BACKUP_DIR="/etc/letsencrypt/$1/backup-$(date +"%Y-%m-%d")"
TEMP_DIR="/etc/letsencrypt/$1/tmp/"

mkdir -p $BACKUP_DIR
cp $CERT_DIR/*.{key,crt} $BACKUP_DIR/

MESSAGE=$(docker start -a $2)

if [ ! -z "${MESSAGE// }" ]; then
	# Non-empty output means there was an error
	echo "$MESSAGE"
	echo ""
	echo "Will not copy new certificates to production dir due to error above"
else
	mv $TEMP_DIR/*.* $CERT_DIR/
	if /usr/sbin/nginx -t 2>&1 | grep -q "test is successful"; then 
		#  Nginx successfuly tested config, save to restart
		/bin/systemctl restart nginx.service
		#REMOVE THIS WHEN EVERYTHING WORKS OK!
		echo "OK. Should recieve only this message via mail"
	else
		echo "Nginx test not passed"
		/usr/sbin/nginx -t
		echo ""
		echo "Reverting previous certificates from backup"
		cp $BACKUP_DIR/*.* $CERT_DIR/
	fi
fi

<commit_msg>Check for root in generate.sh, remove message when everything is ok<commit_after>#!/bin/bash

[ "$EUID" -ne 0 ] && { echo "Please run as root"; exit 1; }

[ -z "$1" ] && { echo >&2 "Please enter domain name as the first argument"; exit 1; }
[ -z "$2" ] && { echo >&2 "Please enter container name as the second argument"; exit 1; }

CERT_DIR="/etc/letsencrypt/$1"
BACKUP_DIR="/etc/letsencrypt/$1/backup-$(date +"%Y-%m-%d")"
TEMP_DIR="/etc/letsencrypt/$1/tmp/"

mkdir -p $BACKUP_DIR
cp $CERT_DIR/*.{key,crt} $BACKUP_DIR/

MESSAGE=$(docker start -a $2)

if [ ! -z "${MESSAGE// }" ]; then
	# Non-empty output means there was an error
	echo "$MESSAGE"
	echo ""
	echo "Will not copy new certificates to production dir due to error above"
else
	mv $TEMP_DIR/*.* $CERT_DIR/
	if /usr/sbin/nginx -t 2>&1 | grep -q "test is successful"; then 
		#  Nginx successfuly tested config, save to restart
		/bin/systemctl restart nginx.service
	else
		echo "Nginx test not passed"
		/usr/sbin/nginx -t
		echo ""
		echo "Reverting previous certificates from backup"
		cp $BACKUP_DIR/*.* $CERT_DIR/
	fi
fi


{'fraction_non_alphanumeric': 0.15188109614491407, 'fraction_numerical': 0.012076172782164421, 'mean_word_length': 3.612419700214133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5764514', 'n_tokens_mistral': 828, 'n_tokens_neox': 783, 'n_words': 263}