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

SERVICE_NAME=spm-agent-mongodb
SYSTEMD_SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
e=$'\e'
COLORblue="$e[0;36m"
COLORred="$e[0;31m"
COLORreset="$e[0m"
function generate_upstart()
{
echo -e "description \"SPM for MongoDB\"
start on runlevel [2345]
stop on runlevel [06]
respawn
env SPM_MONGODB_URLS=$3
env SPM_TOKEN=$2
chdir  /tmp
exec $1 $2 " > /etc/init/${SERVICE_NAME}.conf
CMD="service restart ${SERVICE_NAME}"
echo $CMD
sudo $CMD
}

function generate_systemd() 
{
echo -e \
"
[Unit]
Description=SPM for MongoDB
After=network.target

[Service]
Restart=always\nRestartSec=10
ExecStart=$1 $2 

[Install]
WantedBy=multi-user.target" > $SYSTEMD_SERVICE_FILE

echo "Service file $SERVICE_FILE:"
cat $SYSTEMD_SERVICE_FILE
systemctl enable $SERVICE_NAME
systemctl stop $SERVICE_NAME > /dev/null
systemctl start $SERVICE_NAME
}

function install_script ()
{
	mkdir /etc/spmagent
echo -e \
"[tokens] 
	spm = $2 
	logsene = 
[mongodb] 
	url[] = $3 
[logsene] 
	tailFiles = /var/log/mongodb/mongodb.log" > /etc/spmagent/config

	if [[ `/sbin/init --version` =~ upstart ]]>/dev/null; then 
		echo "Generate upstart script ${UPSTART_SERVICE_FILE}"
		generate_upstart $1 $2 	
		return
	fi
	if [[ `systemctl` =~ -\.mount ]]; then 
		echo "Generate systemd script "
		generate_systemd $1 $2 
		return 
	fi
}

if [[ -n "$1" && -n "$2" ]] ; then 
  token=$1
  mongodb=$2
	command=$(which spm-agent-mongodb)
  install_script $command $token $mongodb;
else 
	echo "${COLORred}Missing paramaters. Usage:"
	echo `basename $0` "SPM_TOKEN MONGODB_URL (mongodb://dbuser:dbpassword@localhost:27017/admin)"<commit_msg>updates for setup<commit_after>#!/usr/bin/env bash

SERVICE_NAME=spm-agent-mongodb
SYSTEMD_SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
e=$'\e'
COLORblue="$e[0;36m"
COLORred="$e[0;31m"
COLORreset="$e[0m"
function generate_upstart()
{
echo -e "description \"SPM for MongoDB\"
start on runlevel [2345]
stop on runlevel [06]
respawn
env SPM_MONGODB_URLS=$3
env SPM_TOKEN=$2
chdir  /tmp
exec $1 $2 " > /etc/init/${SERVICE_NAME}.conf
CMD="service restart ${SERVICE_NAME}"
echo $CMD
sudo $CMD
}

function generate_systemd() 
{
echo -e \
"
[Unit]
Description=SPM for MongoDB
After=network.target

[Service]
Restart=always\nRestartSec=10
ExecStart=$1 $2 $3

[Install]
WantedBy=multi-user.target" > $SYSTEMD_SERVICE_FILE

echo "Service file $SERVICE_FILE:"
cat $SYSTEMD_SERVICE_FILE
systemctl enable $SERVICE_NAME
systemctl stop $SERVICE_NAME > /dev/null
systemctl start $SERVICE_NAME
}

function install_script ()
{
	mkdir /etc/spmagent
echo -e \
"[tokens] 
	spm = $2 
	logsene = 
[mongodb] 
	url[] = $3 
[logsene] 
	tailFiles = /var/log/mongodb/mongodb.log" > /etc/spmagent/config

	if [[ `/sbin/init --version` =~ upstart ]]>/dev/null; then 
		echo "Generate upstart script ${UPSTART_SERVICE_FILE}"
		generate_upstart $1 $2 	$3
		return
	fi
	if [[ `systemctl` =~ -\.mount ]]; then 
		echo "Generate systemd script "
		generate_systemd $1 $2 $3
		return 
	fi
}

if [[ -n "$1" && -n "$2" ]] ; then 
  token=$1
  mongodb=$2
	command=$(which spm-agent-mongodb)
  install_script $command $token $mongodb;
else 
	echo "${COLORred}Missing paramaters. Usage:"
	echo `basename $0` "SPM_TOKEN MONGODB_URL (mongodb://dbuser:dbpassword@localhost:27017/admin)"
{'fraction_non_alphanumeric': 0.1481818181818182, 'fraction_numerical': 0.023333333333333334, 'mean_word_length': 4.781085814360771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1642294', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1290, 'n_words': 294}