LINK PER DOWNLOAD CODICE SORGENTE E FILE MP3
Mi sono trovato nella situazione d'aver perso il cellulare che usavo come sveglia: pazienza, da bravo linuxiano mi sono arrangiato scrivendomi uno script Bash che funziona da sveglia personale... e che a tutti qui regalo, ecco il codice:
#!/bin/bash
#########################################################
# SVEGLIA PERSONALE
#
# Richiede i pacchetti acpi, sox, libsox-fmt-mp3
#
# Copyright (C) 2014 Francesco Galgani https://www.informatica-libera.net/
# version 0.1
#
# 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/>.
##########################################################
echo "SVEGLIA PERSONALE"
# Controlla che i programmi richiesti siano installati
if [ -z "$(which acpi)" ]; then
echo "Errore: acpi non è installato"
exit 1
fi
if [ -z "$(which play)" ]; then
echo "Errore: i pacchetti sox e libsox-fmt-mp3 non sono installati"
exit 1
fi
# Per prima cosa, controllo se l'alimentatore è attaccato
ac_adapter=$(acpi -a | cut -d' ' -f3 | cut -d- -f1)
if [ "$ac_adapter" = "on" ]; then
echo "Ricordati di lasciare il computer acceso, con l'alimentatore inserito e con le casse al massimo volume!"
else
echo "Sembra che l'alimentatore del tuo portatile non sia collegato: attaccalo!"
exit 1
fi
while [ true ]
do
echo "Inserisci l'orario di sveglia nel formato hh:mm, e premi Invio: "
read input
check=`date --date=$input +"%H:%M"`
if [ "$input" == "$check" ]
then
break;
else
echo "L'input $input non è valido."
fi
done
sveglia=`date --date=$input +"%s"`
if [ $sveglia -lt `date +"%s"` ]
then
sveglia=$((3600*24+$sveglia))
fi
while [ $sveglia -gt `date +"%s"` ]
do
x=$(($sveglia - `date +"%s"`))
y=$(($x/3600))
z=$(((x-(y*3600))/60))
sec=$((x-(y*3600)-(z*60)))
echo "Devo aspettare ancora $y ore, $z min e $sec sec"
sleep 1
done
while [ true ]
do
play sveglia.mp3
done