<commit_before>#!/bin/bash

# Console colors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[1;33m'
NC='\033[0m'

# For testing
BRANCH='master'
if [ ! $DRUDE_TEST_ENVIRONMENT == "" ]; then
	BRANCH=$DRUDE_TEST_ENVIRONMENT
	echo -e "${red}[install-drude] testing mode: environment = \"${BRANCH}\"$NC"
fi

# Drude repo
DRUDE_REPO="https://github.com/blinkreaction/drude.git"
DRUDE_REPO_RAW="https://raw.githubusercontent.com/blinkreaction/drude/$BRANCH"

# Yes/no confirmation dialog with an optional message
# @param $1 confirmation message
_confirm ()
{
	while true; do
		read -p "$1 [y/n]: " answer
		case $answer in
			[Yy]|[Yy][Ee][Ss] )
				break
				;;
			[Nn]|[Nn][Oo] )
				exit 1
				;;
			* )
				echo 'Please answer yes or no.'
		esac
	done
}

# Install/update dsh tool wrapper
curl -fsS "$DRUDE_REPO_RAW/install-dsh.sh" -o install-dsh.sh
if [ $? -eq 0 ]; then
	source install-dsh.sh
	dsh_success=$?
	rm install-dsh.sh
	if [ ! $dsh_success -eq 0 ]; then
		_confirm "Do you want to continue with drude update regardless?"
	fi
else
	echo -e "${red}Could not get install-dsh script.${NC}"
	_confirm "Do you want to continue with drude update regardless?"
fi

echo -e "${green}Installing Drude update...${NC}"
# Check that git binary is available
type git > /dev/null 2>&1 || { echo -e >&2 "${red}No git? Srsly? \n${yellow}Please install git then come back. Aborting...${NC}"; exit 1; }

# Check if current directory is a Git repository
if [[ -z $(git rev-parse --git-dir 2>/dev/null) ]]; then
	# If there is no git repo - initialize one and commit everything before we proceed
	echo -e "${yellow}No git repository! We'll create one to proceed with the install.${NC}"
	echo -e "${green}Going to initialize a git repo and commit everything.${NC}"
	_confirm "Do you want to initialize new git repo in $(pwd)?"
	git init -q && git add -A && git commit -q -m 'Initial commit'
fi

# Make sure we are in the root of a git repository
if [[ $(git rev-parse --git-dir) != '.git' ]]; then
	GIT_ROOT=$(git rev-parse --show-toplevel)
	echo "Switching to git repo root: $GIT_ROOT"
	cd $GIT_ROOT
fi

# Check if the working tree and index are clean
if [[ -n $(git status .docker docker-compose.yml -s) ]]; then
	echo -e "${yellow}Your have uncommitted changes in following files:${NC}"<commit_msg>Fix typo<commit_after>#!/bin/bash

# Console colors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[1;33m'
NC='\033[0m'

# For testing
BRANCH='master'
if [ ! $DRUDE_TEST_ENVIRONMENT == "" ]; then
	BRANCH=$DRUDE_TEST_ENVIRONMENT
	echo -e "${red}[install-drude] testing mode: environment = \"${BRANCH}\"$NC"
fi

# Drude repo
DRUDE_REPO="https://github.com/blinkreaction/drude.git"
DRUDE_REPO_RAW="https://raw.githubusercontent.com/blinkreaction/drude/$BRANCH"

# Yes/no confirmation dialog with an optional message
# @param $1 confirmation message
_confirm ()
{
	while true; do
		read -p "$1 [y/n]: " answer
		case $answer in
			[Yy]|[Yy][Ee][Ss] )
				break
				;;
			[Nn]|[Nn][Oo] )
				exit 1
				;;
			* )
				echo 'Please answer yes or no.'
		esac
	done
}

# Install/update dsh tool wrapper
curl -fsS "$DRUDE_REPO_RAW/install-dsh.sh" -o install-dsh.sh
if [ $? -eq 0 ]; then
	source install-dsh.sh
	dsh_success=$?
	rm install-dsh.sh
	if [ ! $dsh_success -eq 0 ]; then
		_confirm "Do you want to continue with drude update regardless?"
	fi
else
	echo -e "${red}Could not get install-dsh script.${NC}"
	_confirm "Do you want to continue with drude update regardless?"
fi

echo -e "${green}Installing Drude update...${NC}"
# Check that git binary is available
type git > /dev/null 2>&1 || { echo -e >&2 "${red}No git? Srsly? \n${yellow}Please install git then come back. Aborting...${NC}"; exit 1; }

# Check if current directory is a Git repository
if [[ -z $(git rev-parse --git-dir 2>/dev/null) ]]; then
	# If there is no git repo - initialize one and commit everything before we proceed
	echo -e "${yellow}No git repository! We'll create one to proceed with the install.${NC}"
	echo -e "${green}Going to initialize a git repo and commit everything.${NC}"
	_confirm "Do you want to initialize new git repo in $(pwd)?"
	git init -q && git add -A && git commit -q -m 'Initial commit'
fi

# Make sure we are in the root of a git repository
if [[ $(git rev-parse --git-dir) != '.git' ]]; then
	GIT_ROOT=$(git rev-parse --show-toplevel)
	echo "Switching to git repo root: $GIT_ROOT"
	cd $GIT_ROOT
fi

# Check if the working tree and index are clean
if [[ -n $(git status .docker docker-compose.yml -s) ]]; then
	echo -e "${yellow}You have uncommitted changes in following files:${NC}"
{'fraction_non_alphanumeric': 0.14835886214442012, 'fraction_numerical': 0.01400437636761488, 'mean_word_length': 3.7813807531380754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 4, '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': '5127165', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1642, 'n_words': 556}