<commit_before>#!/bin/bash

#  runAs (settings_file_name, command_file_name, password)
if [ $# -eq 3 ];
then
        args=$(cat "$1")
        command=$2
        password=$3

	exitCodeFile=$(tempfile)
	stdOutFile=$(tempfile)
        chmod a+w $exitCodeFile
	cmd="${0} runAs $exitCodeFile $command $args"

        # run command
        (
		# wait for password input
		attempts=100
		while [[ ! -s $stdOutFile || attemps -gt 0 ]];
		do
			sleep .1
			attempts=$((attempts-1))
		done

		if [[ $attempts -eq 0 ]];
		then
			echo "##teamcity[message text='Error during sending password.' status='ERROR']"
			exit 1
		fi

		# send password to su stdIn
		echo "$password"

		# wait for process finish
		while ps axg | grep "$stdOutFile" > /dev/null; 
		do
			sleep .1
		done
	) | (
		# su
		socat - EXEC:"$cmd",pty,ctty,setsid;
	) 2> >(tee >"$stdOutFile" >(grep -v "[Pp]assword:" >&2))

	rm $stdOutFile 1> /dev/null 2> /dev/null

        # if exit file is empty
        if [ ! -s $exitCodeFile ];
        then
		exit 1
        fi

	# take exid code from file
	exitCode=$(cat "$exitCodeFile")
	rm $exitCodeFile 1> /dev/null 2> /dev/null
	exit $exitCode
fi

# su (su, exit_code_file, command_file_name, args)
if [ $# -eq 4 ];
then
	exitCodeFile=$2
	command=$3
	args=$4

	su -p -c "$command" "$args"
	exitCode=$?

	echo $exitCode>$exitCodeFile
	exit $exitCode
fi

echo Invalid arguments. >&2
echo Usage: runAs.sh settings_file_name command_file_name password >&2
exit 255<commit_msg>#6 Support Unix OS - add permissions for temp and checkout dirs, minor<commit_after>#!/bin/bash

#  runAs (settings_file_name, command_file_name, password)
if [ $# -eq 3 ];
then
        args=$(cat "$1")
        command=$2
        password=$3

	tmpFile=$(tempfile)
        chmod a+rw "$tmpFile"
	cmd="${0} runAs $tmpFile $command $args"

        # run command
        (
		# wait for password input
		attempts=100
		while [[ ! -s "$tmpFile" || attemps -gt 0 ]];
		do
			sleep .1
			attempts=$((attempts-1))
		done

		if [[ $attempts -eq 0 ]];
		then
			echo "##teamcity[message text='Error during sending password.' status='ERROR']"
			exit 1
		fi

		# send password to su stdIn
		echo "$password"

		# wait for process finish
		while ps axg | grep "$tmpFile" > /dev/null; 
		do
			sleep .1
		done
	) | (
		# su
		socat - EXEC:"$cmd",pty,ctty,setsid;
	) 2> >(tee >> "$tmpFile" >(grep -v "[Pp]assword:" >&2))

        # if exit file is empty
        if [ ! -s "$tmpFile" ];
        then
		exit 1
        fi

	# take exid code from file
	exitCode=$(cat "$tmpFile")
	rm "$tmpFile" 1> /dev/null 2> /dev/null
	exit $exitCode
fi

# su (su, tmp_file, command_file_name, args)
if [ $# -eq 4 ];
then
	tmpFile=$2
	command=$3
	args=$4

	su -p -c "$command" "$args"
	exitCode=$?

	echo $exitCode>"$tmpFile"
	exit $exitCode
fi

echo Invalid arguments. >&2
echo Usage: runAs.sh settings_file_name command_file_name password >&2
exit 255
{'fraction_non_alphanumeric': 0.14488243430152145, 'fraction_numerical': 0.020401106500691563, 'mean_word_length': 2.831788079470199, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '7407459', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1067, 'n_words': 317}