<commit_before>#!/bin/bash

md5=$(if [ `uname` == Darwin ] ; then echo md5 ; else echo md5sum ; fi)
randPass=$(date +"%s" | $md5 | base64)

tmpfile=$(mktemp /tmp/XXXXXX)

dialog --backtitle "System Administration Tool" --title "Create Mongo Database and DB user" \
--form "\n* siteUserAdmin is for login, if login is not needed:\n  set both siteUserAdmin & siteUserAdmin to empty\n* Will create DB user (password is randomly generated)\n* Will create DB name" 25 70 16 \
"siteUserAdmin(user):" 1 1 "siteUserAdmin" 1 25 35 30 \
"siteUserAdmin(pass):" 2 1 "" 2 25 35 30 \
"DB user(user):" 3 1 "" 3 25 35 30 \
"DB user(pass):" 4 1 "$randPass" 4 25 35 30 \
"DB name:" 5 1 "" 5 25 35 30 \
"role:" 6 1 "readWrite" 6 25 35 30 \
2> $tmpfile

if [ $? -eq 0 ]
then
	nonEmptyFields=$(cat $tmpfile | grep -v "^$" | wc -l)
	if [ $nonEmptyFields -lt 4 ] #at least give 4 (the last 4 fields)
	then
		printf "\x1B[31m"
		echo "ERR: Please fill all necessary fields."
		printf "\x1B[0m"
		exit 1
	fi

	siteUserAdmin_user=$(cat $tmpfile | head -n 1 | tail -n 1)
	siteUserAdmin_pass=$(cat $tmpfile | head -n 2 | tail -n 1)
	dbUser_user=$(cat $tmpfile | head -n 3 | tail -n 1)
	dbUser_pass=$(cat $tmpfile | head -n 4 | tail -n 1)
	dbName=$(cat $tmpfile | head -n 5 | tail -n 1)
	role=$(cat $tmpfile | head -n 6 | tail -n 1)

	
	mongo="mongo admin -u$siteUserAdmin_user -p$siteUserAdmin_pass"
	if [ x$siteUserAdmin_user == x -o x$siteUserAdmin_pass == x ]
	then
		mongo="mongo"<commit_msg>support immediate command line args<commit_after>#!/bin/bash

md5=$(if [ `uname` == Darwin ] ; then echo md5 ; else echo md5sum ; fi)

siteUserAdmin_user="$1"
siteUserAdmin_pass="$2"
dbUser_user="$3"
dbUser_pass="$4"
dbName="$5"
role="$6"
okDirectly="$7"
if [ x"$siteUserAdmin_user" == x ]
then
	siteUserAdmin_user=siteUserAdmin
fi
if [ x"$dbUser_pass" == x ]
then
	dbUser_pass=$(date +"%s" | $md5 | base64)
fi
if [ x"$role" == x ]
then
	role=readWrite
fi


tmpfile=$(mktemp /tmp/XXXXXX)

if [ x"$okDirectly" != xOK ]
then

dialog --backtitle "System Administration Tool" --title "Create Mongo Database and DB user" \
--form "\n* siteUserAdmin is for login, if login is not needed:\n  set both siteUserAdmin & siteUserAdmin to empty\n* Will create DB user (password is randomly generated)\n* Will create DB name" 25 70 16 \
"siteUserAdmin(user):" 1 1 "$siteUserAdmin_user" 1 25 35 30 \
"siteUserAdmin(pass):" 2 1 "$siteUserAdmin_pass" 2 25 35 30 \
"DB user(user):" 3 1 "$dbUser_user" 3 25 35 30 \
"DB user(pass):" 4 1 "$dbUser_pass" 4 25 35 30 \
"DB name:" 5 1 "$dbName" 5 25 35 30 \
"role:" 6 1 "$role" 6 25 35 30 \
2> $tmpfile
	if [ $? -eq 0 ]
	then
		okDirectly=OK
	fi

else
	cat <<EOF > $tmpfile
$siteUserAdmin_user
$siteUserAdmin_pass
$dbUser_user
$dbUser_pass
$dbName
$role
EOF

fi

if [ x"$okDirectly" == xOK ]
then
	nonEmptyFields=$(cat $tmpfile | grep -v "^$" | wc -l)
	if [ $nonEmptyFields -lt 4 ] #at least give 4 (the last 4 fields)
	then
		printf "\x1B[31m"
		echo "ERR: Please fill all necessary fields."
		printf "\x1B[0m"
		exit 1
	fi

	siteUserAdmin_user=$(cat $tmpfile | head -n 1 | tail -n 1)
	siteUserAdmin_pass=$(cat $tmpfile | head -n 2 | tail -n 1)
	dbUser_user=$(cat $tmpfile | head -n 3 | tail -n 1)
	dbUser_pass=$(cat $tmpfile | head -n 4 | tail -n 1)
	dbName=$(cat $tmpfile | head -n 5 | tail -n 1)
	role=$(cat $tmpfile | head -n 6 | tail -n 1)

	
	mongo="mongo admin -u$siteUserAdmin_user -p$siteUserAdmin_pass"
	if [ x$siteUserAdmin_user == x -o x$siteUserAdmin_pass == x ]
	then
		mongo="mongo"
{'fraction_non_alphanumeric': 0.14919816723940435, 'fraction_numerical': 0.05297823596792669, 'mean_word_length': 3.7523809523809524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '72592', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1341, 'n_words': 468}