#!/bin/bash

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

# (c) Antonio Sánchez León, 2018 <introlinux[fix@]gmail[fix.]com>
# (c) Miguel Anxo Bouzada, 2018 <mbouzada[fix@]gmail[fix.]com>
# (c) GALPon MinNo Team, 2018 <minino[fix@]galpon[fix.]org>

## -

## Mensajes según idioma
case $LANG in
	ca*)
		MSG="ATENCIÓ:
Per fer servir aquest script cal «sysbench»,
per instal·lar-ho, ordeni a la terminal «apt install sysbench»."
		TIT="Valoració ràpida"
		PUNT="Qualificació d'aquest ordinador:"
		TEXT0="\n\tAquest equip és <b>INSUFICIENT</b> \n\tper a les tasques quotidianes d'avui dia.\t"
		TEXT1="\n\tAquest equip és <b>MOLT JUST</b> \n\tper a les tasques quotidianes d'avui dia.\t"
		TEXT2="\n\tAquest equip és <b>SUFICIENT</b> \n\tper fer gairabé de tot però una mica just\t\n\tper a algunes tasques."
		TEXT3="\n\tAquest equip està <b>BÉ</b> \n\tper fer de tot una mica, però sense demanar-li\t\n\tla lluna en un cove."
		TEXT4="\n\tAquest equip és <b>NOTABLE</b>, \n\tpot fer pràcticament qualsevol cosa.\t"
		TEXT5="\n\tAquest equip és <b>EXCEL·LENT</b>, \n\tpot fer pràcticament qualsevol cosa.\t"
		TEXT6="\n\t<span size='large' color='red'><b>No va ser possible avaluar aquest equip.\t</b></span>"
		;;
	es*)
		MSG="ATENCIÓN:
Para Usar este script necesita tener instalado «sysbench»,
para solucionarlo, aplique en la terminal «apt install sysbench»."
		TIT="Valoración rápida"
		PUNT="Calificación de este ordenador:"
		TEXT0="\n\tEste equipo es <b>INSUFICIENTE</b> \n\tpara tareas cotidianas de hoy día.\t"
		TEXT1="\n\tEste equipo es <b>MUY JUSTO</b> \n\tpara tareas cotidianas de hoy día.\t"
		TEXT2="\n\tEste equipo es <b>SUFICIENTE</b> \n\tpara hacer casi de todo pero un poco\t\n\tjusto para algunas tareas."
		TEXT3="\n\tEste equipo está <b>BIEN</b> \n\tpara hacer de todo un poco, pero\t\n\tsin pedirle peras al olmo."
		TEXT4="\n\tEste equipo es <b>NOTABLE</b>, \n\tpodrá hacer prácticamente cualquier cosa.\t"
		TEXT5="\n\tEste equipo es <b>SOBRESALIENTE</b>, \n\tpodrá hacer prácticamente cualquier cosa.\t"
		TEXT6="\n\t<span size='large' color='red'><b>No fué posible evaluar este equipo.\t</b></span>"
		;;
	gl*)
		MSG="ATENCIÓN:
Para Usar este script precisa ter instalado «sysbench»,
para solucionalo, aplique na terminal «apt install sysbench»."
		TIT="Valoración rápida"
		PUNT="Cualificación deste computador:"
		TEXT0="\n\tEste equipo é <b>INSUFICIENTE</b> \n\tpara tarefas cotiás de hoxe en día.\t"
		TEXT1="\n\tEste equipo é <b>MOI XUSTO</b> \n\tpara tarefas cotiás de hoxe en día.\t"
		TEXT2="\n\tEste equipo é <b>SUFICIENTE</b> \n\tpara facer case de todo mais un chisco\t\n\txusto para algunhas tarefas."
		TEXT3="\n\tEste equipo está <b>BEN</b> \n\tpara facer de todo un pouco, mais\t\n\tsen pedir o demo e a aña ."
		TEXT4="\n\tEste equipo é <b>NOTÁBEL</b>, \n\tpoderá facer practicamente calquera cousa.\t"
		TEXT5="\n\tEste equipo é <b>SOBRESAÍNTE</b>, \n\tpoderá facer practicamente calquera cousa.\t"
		TEXT6="\n\t<span size='large' color='red'><b>Non foi posíbel avaliar este equipo.\t</b></span>"
		;;
	*)
		MSG="Warning:
To use this script you need «sysbench»,
to solve it, launch «apt install sysbench» in a terminal."
		TIT="Fast benchmark"
		PUNT="Rating of this computer:"
		TEXT0="\n\tThis computer is <b>INSSUFICIENT</b> \n\tfor today's everyday tasks.\t"
		TEXT1="\n\tThis computer is <b>VERY LIMITED</b> \n\tfor today's everyday tasks.\t"
		TEXT2="\n\tThe speed of this computer is <b>ENOUGH</b> \n\tto do almost everything but a bit fair\t\n\tfor some tasks."
		TEXT3="\n\tThe speed of this computer is <b>QUITE GOOD</b> \n\tto do everything, but\t\n\twithout asking for the moon."
		TEXT4="\n\tThe speed of this computer is <b>REMARKABLE</b>, \n\tyou can do practically everything.\t"
		TEXT5="\n\tThis computer is a <b>BEAST</b>, \n\tyou can do practically everything.\t"
		TEXT6="\n\t<span size='large' color='red'><b>It was not possible to evaluate this computer.\t</b></span>"
		;;
esac

## -

## Comprobamos si existe el ejecutable «sysbench»
FILE0=/usr/bin/sysbench
if [ ! -x ${FILE0} ]; then
	echo ""
	echo "${MSG}"
	echo ""
	exit 0
fi

## Ejecutamos la orden base
EVENTOS=`sysbench --test=cpu --max-time=5 --num-threads=8 run|grep "total number of events"|awk '{print $5}'`

## Calculamos la calificación/nota
#NOTA=$(($EVENTOS/1000))
#NOTA=$(echo "scale=2; $EVENTOS/1000"|bc)
NOTA=`echo print ${EVENTOS}/1000. |python`
NOTASINDECIMALES=`echo print ${EVENTOS}/1000 |python`

## Asignamos el mensaje y el icono en función de la «nota»
case ${NOTASINDECIMALES} in
	0)
		VALORACION="${TEXT0}"
		FACE="face-sick"
		;;
	1)
		VALORACION="${TEXT0}"
		FACE="face-sick"
		;;
	2)
		VALORACION="${TEXT0}"
		FACE="face-worried"
		;;
	3)
		VALORACION="${TEXT0}"
		FACE="face-tired"
		;;
	4)
		VALORACION="${TEXT1}"
		FACE="face-uncertain"
		;;
	5)
		VALORACION="${TEXT2}"
		FACE="face-smirk"
		;;
	6) 
		VALORACION="${TEXT3}"
		FACE="face-smile"
		;;
	7)
		VALORACION="${TEXT4}"
		FACE="face-smile-big"
		;;
	8)
		VALORACION="${TEXT4}"
		FACE="face-smile-big"
		;;
	9)
		VALORACION="${TEXT5}"
		FACE="face-laugh"
		;;
	10) 
		VALORACION="${TEXT5}"
		FACE="face-laugh"
		;;
	*)
		VALORACION="${TEXT6}"
		FACE="face-angry"
		;;
esac


echo ${PUNT} ${NOTA}

## Ventana con mensaje final en función del generador de ventanas existente en el sistema
FILE1=/usr/bin/yad
if [ "test -x ${FILE1}" ]; then
    yad --info \
		--window-icon="face-smile"\
		--image="${FACE}" \
		--title "${TIT}" \
		--text \
			"\n\t${PUNT} <b>${NOTA}</b> 
			\t${VALORACION}"
else
    zenity --info \
		--title "${TIT}" \
		--text \
			"\n\t${PUNT} <b>${NOTA}</b> 
			\t${VALORACION}"
fi

