#!/bin/bash
# speedtest-yad
# Script(Gui)to speedtest
# By Frannoe@gmail.com Frannoe(Francisco Luque)
# http://www.dmdcosillas.org/



progressbar () {

          dir / >> /tmp/tmprog

          tail -f /tmp/tmprog | yad --window-icon=/usr/share/pixmaps/speedtest.png --image=/usr/share/pixmaps/speedtest.png --image-on-top --width=400 --title "Procesando... " --text-align=center --text "Espere mientras se recopila la información. " --no-buttons --progress --progress-text="" --pulsate --auto-close
}


function m-grafico {
           kill echo `ps -ef | grep "yad" | grep -v "grep" | awk '{print $2}'` & sleep 0.1

progressbar &

url=`speedtest-cli --share` 
wget -O - `egrep -o '\www\W+(\w+\W+){1,8}png\b' <<< $url` > /tmp/speedtest.png `tail -1`

          killall -KILL tail

`mogrify -resize 450 /tmp/speedtest.png`

yad --window-icon=/usr/share/pixmaps/speedtest.png --no-buttons --title "SpeedTest" --image /tmp/speedtest.png


           rm /tmp/speedtest.png
           rm /tmp/tmprog
}

function m-consola {
            kill echo `ps -ef | grep "yad" | grep -v "grep" | awk '{print $2}'` & sleep 0.1

speedtest-cli | yad --text-info --window-icon=/usr/share/pixmaps/speedtest.png --title="Test de velocidad" --height=450 --width=600 --no-buttons

}

function m-list {
            kill echo `ps -ef | grep "yad" | grep -v "grep" | awk '{print $2}'` & sleep 0.1

speedtest-cli --list | yad --text-info --window-icon=/usr/share/pixmaps/speedtest.png --title="Test de velocidad" --height=450 --width=600 --no-buttons 

}

export -f m-consola
export -f m-grafico
export -f m-list
export -f progressbar
 
yad --columns=3 --window-icon=/usr/share/pixmaps/speedtest.png --image=/usr/share/pixmaps/speedtest.png --width "450" --no-buttons   --text-align=center --title "SpeedTest" --text "Seleccione un modo para realizar el Test. " \
--form \
--field=:LBL '' \
--field=:LBL '' \
--field=:LBL '' \
--field="Modo Gráfico":BTN  'bash -c "m-grafico"' \
--field=:LBL '' \
--field=:LBL '' \
--field=:LBL '' \
--field=:LBL '' \
--field="Modo Consola":BTN  'bash -c "m-consola"' \
--field=:LBL '' \
--field=:LBL '' \
--field=:LBL '' \
--field=:LBL '' \
--field="Lista Servidores":BTN  'bash -c "m-list"' \
--field=:LBL ''


