<commit_before>#!/usr/bin/env bash

#save current directory
starting_dir=$(pwd)

#cd to the directory of this script
#from http://www.ostricher.com/2014/10/the-right-way-to-get-the-directory-of-a-bash-script/

get_script_dir  () {
	SOURCE="${BASH_SOURCE[0]}"
	# While $SOURCE is a symlink, resolve it
	while [ -h "$SOURCE" ]; do
		DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
		SOURCE="$( readlink "$SOURCE" )"
		# If $SOURCE was a relative symlink (so no "/" as prefix, need to resolve it relative to the symlink base directory
		[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
	done
	DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
	echo $DIR
}

cd_to_current_dir () {
	DIR="$(get_script_dir)"
	echo "Changing ing to ${DIR}"
	cd "${DIR}" || die "Folder ${DIR} does not exist."
}

add_line_to_file_if_not_present () {
	LINE=$1
	FILE=$2
	sudo sh -c "grep -q -F \"$LINE\" \"$FILE\" || sudo echo \"$LINE\" >> \"$FILE\""
}

copy_config_files() {
	#place configuration file in dendro's deployment configs folder
	wd="$starting_dir"
	warning "Copying configuration file ${wd}/Programs/generated_configurations/deployment_configs.json to ${dendro_installation_path}/conf"
	sudo cp "$wd/Programs/generated_configurations/deployment_configs.json" "$dendro_installation_path/conf"
}

installShibbolethDependencies()
{

	generateNewServiceProvideFiles()
	{
		parent_of_shibboleth_authentication_key_file=$1
		parent_of_shibboleth_authentication_cert_file=$2

		info "parent_of_shibboleth_authentication_key DEBUG: $parent_of_shibboleth_authentication_key_file"
	    info "parent_of_shibboleth_authentication_cert DEBUG: $parent_of_shibboleth_authentication_cert_file"

		warning "Will generate Shibboleth service provider files!"
        mkdir -p $parent_of_shibboleth_authentication_key_file || die "could not create folder $parent_of_shibboleth_authentication_key_file"
        mkdir -p $parent_of_shibboleth_authentication_cert_file || die "could not create folder $parent_of_shibboleth_authentication_cert_file"
        openssl req -x509 \
        	-newkey rsa:4096 \
        	-keyout $shibboleth_authentication_key_path \
        	-out $shibboleth_authentication_cert_path \
        	-nodes \
        	-days 900 \
        	-subj "/C=$openssl_country/ST=$openssl_state/L=$openssl_location/O=$openssl_organization/OU=$openssl_organizational_unit/CN=$openssl_common_name" || die "could not create service provider files!"
        success "Shibboleth service provider files generated!"
	}

	checkIfServiceProviderShibbolethFilesExist()
	{
		parent_of_shibboleth_authentication_key_file=${shibboleth_authentication_key_path%/*}
	    parent_of_shibboleth_authentication_cert_file=${shibboleth_authentication_cert_path%/*}

	    info "parent_of_shibboleth_authentication_key: $parent_of_shibboleth_authentication_key_file"
	    info "parent_of_shibboleth_authentication_cert: $parent_of_shibboleth_authentication_cert_file"

	    #if key.pem and cert.pem files are missing, the script should generate them
	    #However the idp_cert.pem file is dependent on the Shibboleth IDP, so this file must be manually retrieved and set by the system admin
	    if [ ! -f $shibboleth_authentication_key_path -o  ! -f $shibboleth_authentication_cert_path ]; then
	        warning "Shibboleth service provider files not found!"
	        while true; do
	            read -p "Will generate new Shibboleth service provider files!!! PLEASE PROVIDE the updated xml(with the updated $shibboleth_authentication_cert_path) file to the Identity Provider! Type 'yes' to continue OR 'no' to abort : " yn
	            case $yn in
	                [Yy]* ) generateNewServiceProvideFiles "$parent_of_shibboleth_authentication_key_file" "$parent_of_shibboleth_authentication_cert_file"; break;;
	                [Nn]* ) die "Will NOT continue Shibboleth installation!"; break;;
	                * ) echo "Please answer yes or no.";;
	            esac
	        done
	        #warning "Will generate Shibboleth service provider files!"
	        #mkdir -p $parent_of_shibboleth_authentication_key_file || die "could not create folder $parent_of_shibboleth_authentication_key_file"
	        #mkdir -p $parent_of_shibboleth_authentication_cert_file || die "could not create folder $parent_of_shibboleth_authentication_cert_file"
	        #openssl req -x509 \
	        #	-newkey rsa:4096 \
	        #	-keyout $shibboleth_authentication_key_path \
	        #	-out $shibboleth_authentication_cert_path \
	        #	-nodes \
	        #	-days 900 \
	        #	-subj "/C=$openssl_country/ST=$openssl_state/L=$openssl_location/O=$openssl_organization/OU=$openssl_organizational_unit/CN=$openssl_common_name" || die "could not create service provider files!"
	        #success "Shibboleth service provider files generated!"
	    else
	        success "Shibboleth service provider files already exist!"
	    fi
	}

	checkIfIdentityProviderFilesExist()
	{
		if [ ! -f $shibboleth_authentication_idp_cert_path ]; then
        	error "Shibboleth identity provider files not found!"
	        die "Please upload $shibboleth_authentication_idp_cert_path"
	    else
	        success "Shibboleth identity provider files already exist!"
	    fi
	}

	setup()
	{
		checkIfIdentityProviderFilesExist
		checkIfServiceProviderShibbolethFilesExist
	    success "$shibboleth_authentication_idp_cert_path set!"
	    success "$shibboleth_authentication_key_path set!"
	    success "$shibboleth_authentication_cert_path set!"<commit_msg>cleaned code<commit_after>#!/usr/bin/env bash

#save current directory
starting_dir=$(pwd)

#cd to the directory of this script
#from http://www.ostricher.com/2014/10/the-right-way-to-get-the-directory-of-a-bash-script/

get_script_dir  () {
	SOURCE="${BASH_SOURCE[0]}"
	# While $SOURCE is a symlink, resolve it
	while [ -h "$SOURCE" ]; do
		DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
		SOURCE="$( readlink "$SOURCE" )"
		# If $SOURCE was a relative symlink (so no "/" as prefix, need to resolve it relative to the symlink base directory
		[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
	done
	DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
	echo $DIR
}

cd_to_current_dir () {
	DIR="$(get_script_dir)"
	echo "Changing ing to ${DIR}"
	cd "${DIR}" || die "Folder ${DIR} does not exist."
}

add_line_to_file_if_not_present () {
	LINE=$1
	FILE=$2
	sudo sh -c "grep -q -F \"$LINE\" \"$FILE\" || sudo echo \"$LINE\" >> \"$FILE\""
}

copy_config_files() {
	#place configuration file in dendro's deployment configs folder
	wd="$starting_dir"
	warning "Copying configuration file ${wd}/Programs/generated_configurations/deployment_configs.json to ${dendro_installation_path}/conf"
	sudo cp "$wd/Programs/generated_configurations/deployment_configs.json" "$dendro_installation_path/conf"
}

installShibbolethDependencies()
{

	generateNewServiceProviderFiles()
	{
		parent_of_shibboleth_authentication_key_file=$1
		parent_of_shibboleth_authentication_cert_file=$2

		info "parent_of_shibboleth_authentication_key DEBUG: $parent_of_shibboleth_authentication_key_file"
	    info "parent_of_shibboleth_authentication_cert DEBUG: $parent_of_shibboleth_authentication_cert_file"

		warning "Will generate Shibboleth service provider files!"
        mkdir -p $parent_of_shibboleth_authentication_key_file || die "could not create folder $parent_of_shibboleth_authentication_key_file"
        mkdir -p $parent_of_shibboleth_authentication_cert_file || die "could not create folder $parent_of_shibboleth_authentication_cert_file"
        openssl req -x509 \
        	-newkey rsa:4096 \
        	-keyout $shibboleth_authentication_key_path \
        	-out $shibboleth_authentication_cert_path \
        	-nodes \
        	-days 900 \
        	-subj "/C=$openssl_country/ST=$openssl_state/L=$openssl_location/O=$openssl_organization/OU=$openssl_organizational_unit/CN=$openssl_common_name" || die "could not create service provider files!"
        success "Shibboleth service provider files generated!"
	}

	checkIfServiceProviderShibbolethFilesExist()
	{
		parent_of_shibboleth_authentication_key_file=${shibboleth_authentication_key_path%/*}
	    parent_of_shibboleth_authentication_cert_file=${shibboleth_authentication_cert_path%/*}

	    info "parent_of_shibboleth_authentication_key: $parent_of_shibboleth_authentication_key_file"
	    info "parent_of_shibboleth_authentication_cert: $parent_of_shibboleth_authentication_cert_file"

	    #if key.pem and cert.pem files are missing, the script should generate them
	    #However the idp_cert.pem file is dependent on the Shibboleth IDP, so this file must be manually retrieved and set by the system admin
	    if [ ! -f $shibboleth_authentication_key_path -o  ! -f $shibboleth_authentication_cert_path ]; then
	        warning "Shibboleth service provider files not found!"
	        while true; do
	            read -p "Will generate new Shibboleth service provider files!!! PLEASE PROVIDE the updated xml(with the updated $shibboleth_authentication_cert_path) file to the Identity Provider! Type 'yes' to continue OR 'no' to abort : " yn
	            case $yn in
	                [Yy]* ) generateNewServiceProviderFiles "$parent_of_shibboleth_authentication_key_file" "$parent_of_shibboleth_authentication_cert_file"; break;;
	                [Nn]* ) die "Will NOT continue Shibboleth installation!"; break;;
	                * ) echo "Please answer yes or no.";;
	            esac
	        done
	    else
	        success "Shibboleth service provider files already exist!"
	    fi
	}

	checkIfIdentityProviderFilesExist()
	{
		if [ ! -f $shibboleth_authentication_idp_cert_path ]; then
        	error "Shibboleth identity provider files not found!"
	        die "Please upload $shibboleth_authentication_idp_cert_path"
	    else
	        success "Shibboleth identity provider files already exist!"
	    fi
	}

	setup()
	{
		checkIfIdentityProviderFilesExist
		checkIfServiceProviderShibbolethFilesExist
	    success "$shibboleth_authentication_idp_cert_path set!"
	    success "$shibboleth_authentication_key_path set!"
	    success "$shibboleth_authentication_cert_path set!"
{'fraction_non_alphanumeric': 0.09299097848716169, 'fraction_numerical': 0.005155150193318132, 'mean_word_length': 4.256904637832204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '3348783', 'n_tokens_mistral': 3493, 'n_tokens_neox': 3279, 'n_words': 742}