<commit_before># helper functions for installer

set -e


ANS_FILE="_answers.sh"

function bee_banner {
	#clear
	echo
	echo "    __    __    __    __    __    __    __    __    __    __"
	echo " __/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__"
	echo "/  \\__ ORDER OF THE BEE /  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\"
	echo "\\__/  \\__/  \\__/  \\__/  \\ Alfresco (TM) Honeycomb Edition   \\__/"
	echo "   \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  "
	echo

}

function get_answer {
	IDX=$1
	if [ "${answers[$IDX]}" != "" ]
	then 
		echo ${answers[$IDX]}
		return
	fi
	echo ${default[$IDX]}
}


function read_entry {
	echo "Please choose an index number to edit, I to install, or Q to quit"
	read -ep" -> " ENTRY

	if [ "$ENTRY" = "I" -o "$ENTRY" = "i" ]
	then
		write_answers
		set +e
		run_install
		# non zero exit might mean that a required field is not filled
		if [ $? = 0 ] 
		then
			exit
		fi
		set -e
		sleep 2
		echo
	elif [ "$ENTRY" = "Q" -o "$ENTRY" = "q" ]
	then
		write_answers
		exit
	else
		edit_param $ENTRY
	fi

}

function write_answers {
	echo Writing answer file $ANS_FILE
	if [ -f $ANS_FILE ]; then mv $ANS_FILE $ANS_FILE.1; fi
	touch $ANS_FILE
	for i in `seq 0 $(( ${#params} -1))`
	do
		if [ "${answers[$i]}" != "" ]
		then
			echo "${params[$i]}=${answers[$i]}" >> $ANS_FILE
		fi
	done
}

function read_answers {
	if [ -f $ANS_FILE ]
	then
		readarray LINES < $ANS_FILE
		for lineIdx in `seq 0 $(( ${#LINES} ))`
		do
			line="${LINES[$lineIdx]}"
			param=`echo $line | cut -f1 -d= `
			value=`echo $line | cut -f2 -d= `

			for i in `seq 0 ${#params} -1 ))`
			do
				if [ "${params[i]}" = "$param" ]
				then
					answers[i]=$value
					break
				fi
			done
		done 
	fi
}

function edit_param {
	IDX=$(( $1 -1 ))
	param="${params[IDX]}"
	descr="${descr[IDX]}"
	value=`get_answer $IDX`
	echo "Parameter: $param"
	echo $descr
	echo -n "[$value]"
	read -ep": " ANSWER
	answers[$IDX]=$ANSWER<commit_msg>fixing param order<commit_after># helper functions for installer

set -e


ANS_FILE="_answers.sh"

function bee_banner {
	#clear
	echo
	echo "    __    __    __    __    __    __    __    __    __    __"
	echo " __/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__"
	echo "/  \\__ ORDER OF THE BEE /  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\"
	echo "\\__/  \\__/  \\__/  \\__/  \\ Alfresco (TM) Honeycomb Edition   \\__/"
	echo "   \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  \\__/  "
	echo

}

function get_answer {
	IDX=$1
	if [ "${answers[$IDX]}" != "" ]
	then 
		echo ${answers[$IDX]}
		return
	fi
	echo ${default[$IDX]}
}


function read_entry {
	echo "Please choose an index number to edit, I to install, or Q to quit"
	read -ep" -> " ENTRY

	if [ "$ENTRY" = "I" -o "$ENTRY" = "i" ]
	then
		write_answers
		set +e
		run_install
		# non zero exit might mean that a required field is not filled
		if [ $? = 0 ] 
		then
			exit
		fi
		set -e
		sleep 2
		echo
	elif [ "$ENTRY" = "Q" -o "$ENTRY" = "q" ]
	then
		write_answers
		exit
	else
		edit_param $ENTRY
	fi

}

function write_answers {
	echo Writing answer file $ANS_FILE
	if [ -f $ANS_FILE ]; then mv $ANS_FILE $ANS_FILE.1; fi
	touch $ANS_FILE
	for i in `seq 0 $(( ${#params} -1))`
	do
		if [ "${answers[$i]}" != "" ]
		then
			echo "${params[$i]}=${answers[$i]}" >> $ANS_FILE
		fi
	done
}

function read_answers {
	if [ -f $ANS_FILE ]
	then
		readarray LINES < $ANS_FILE
		for lineIdx in `seq 0 $(( ${#LINES} ))`
		do
			line="${LINES[$lineIdx]}"
			param=`echo $line | cut -f1 -d= `
			value=`echo $line | cut -f2 -d= `

			for i in `seq 0 $(( ${#params} -1 ))`
			do
				if [ "${params[i]}" = "$param" ]
				then
					answers[i]=$value
					break
				fi
			done
		done 
	fi
}

function edit_param {
	IDX=$(( $1 -1 ))
	param="${params[IDX]}"
	descr="${descr[IDX]}"
	value=`get_answer $IDX`
	echo "Parameter: $param"
	echo $descr
	echo -n "[$value]"
	read -ep": " ANSWER
	answers[$IDX]=$ANSWER
{'fraction_non_alphanumeric': 0.19216277317256972, 'fraction_numerical': 0.006531022356191912, 'mean_word_length': 2.1109375, 'pattern_counts': {'":': 2, '<': 5, '<?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': '4178481', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1697, 'n_words': 407}