Created
January 4, 2015 21:16
-
-
Save Munksgaard/a9de8aa32d93a1e3aebb to your computer and use it in GitHub Desktop.
A script to wake you up by playing some music.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Wakeup | |
# Author: Philip Munksgaard | |
# Description: Suspends the computer and wakes up at a specified | |
# time and starts playing a song. | |
# Note: does not ensure that sound is on and high enough! | |
wakeuptime=$1 | |
shift | |
usage () { | |
echo "Usage: $0 WAKEUPTIME SONG" | |
} | |
help () { | |
echo "Will suspend the computer and wake up at WAKEUPTIME" | |
echo "playing the specificed song(s)." | |
echo | |
echo "Examples:" | |
echo "$0 8:00 song.mp3 - Will play song.mp3 at 8:00 today" | |
echo "$0 tomorrow 8:00 song.mp3 - will play song.mp3 at 8:00 tomorrow" | |
} | |
if [ "$1" = "--help" -o "$1" = "-h" ]; then | |
usage | |
echo | |
help | |
exit 0 | |
fi | |
if [ -z "$1" -o -z "$wakeuptime" ]; then | |
usage | |
exit 1 | |
fi | |
sudo echo "Going to sleep. Will wake you up $wakeuptime by playing $@" | |
alarmtimer="`date '+%s' -d "$wakeuptime"`" | |
if [ "$alarmtimer" -le $(date +%s) ]; then | |
alarmtimer="`date '+%s' -d "tomorrow $wakeuptime"`" | |
fi | |
sudo sh -c "echo '0' > /sys/class/rtc/rtc0/wakealarm" | |
sudo sh -c "echo '$alarmtimer' > /sys/class/rtc/rtc0/wakealarm" | |
sleep 5 | |
sudo pm-suspend ; mplayer "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment