You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tuxalarm.sh 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/dash
  2. NAME="tuxalarm.sh"
  3. AUTHOR="Craciun Dan"
  4. HTTP="http://www.tuxarena.com/intro/tuxalarm.php"
  5. MAIL="floydian.embryo@yahoo.com"
  6. VERSION="0.2.0"
  7. DATE="Feb 15, 2014"
  8. LICENSE="GPLv2"
  9. # TODO: make a cli music player using gstreamer and use that instead of avplay
  10. alarm1="Replace this with the absolute path to an audio file (e.g. $HOME/Music/alarm.mp3)."
  11. alarm2="Replace this with the absolute path to an audio file (e.g. $HOME/Music/alarm.mp3)."
  12. alarm3="Replace this with the absolute path to a directory containing audio files."
  13. interval="5"
  14. bin_ogg123=0
  15. bin_avplay=0
  16. if [ -x /usr/bin/ogg123 ]; then
  17. #bin_ogg123=1
  18. bin_ogg123=0 # set this to 1 to use ogg123 instead of avplay
  19. # or replace all ogg123 occurences with mpg123; ogg123 plays only ogg and flac files
  20. fi
  21. if [ -x /usr/bin/avplay ]; then
  22. bin_avplay=1
  23. fi
  24. if [ $bin_ogg123 -eq 0 ] && [ $bin_avplay -eq 0 ]; then
  25. echo "WARNING: No suitable player found. The alarm will NOT work! (Tip: install vorbis-tools or avplay)"
  26. echo "Exiting..."
  27. exit 0
  28. fi
  29. echo -n "Enter alarm time as HHMM format (e.g. 0620 for 6:20 AM): "
  30. read alarm
  31. echo "Available alarms:"
  32. echo "1. $alarm1"
  33. echo "2. $alarm2"
  34. echo "3. All files inside $alarm3"
  35. valid=0
  36. while [ $valid -eq 0 ]; do
  37. echo -n "Choose alarm file (default 1): "
  38. read input
  39. if [ "$input" = "1" ] || [ "$input" = "" ]; then
  40. valid=1
  41. default=1
  42. elif [ "$input" = "2" ]; then
  43. valid=1
  44. default=2
  45. elif [ "$input" = "3" ]; then
  46. found=0
  47. for i in $alarm3/*.ogg; do
  48. if [ -f $i ]; then
  49. found=1
  50. fi
  51. done
  52. for i in $alarm3/*.mp3; do
  53. if [ -f $i ]; then
  54. found=1
  55. fi
  56. done
  57. if [ $found -eq 1 ]; then
  58. valid=1
  59. default=3
  60. else
  61. echo "No .ogg or .mp3 files found inside $alarm3! Change the directory or the alarm will NOT work!"
  62. echo "Exiting..."
  63. exit 0
  64. fi
  65. fi
  66. done
  67. printalarm () {
  68. if [ $bin_ogg123 -eq 1 ]; then
  69. if [ $default -eq 1 ]; then
  70. echo ogg123 $alarm1
  71. elif [ $default -eq 2 ]; then
  72. echo ogg123 $alarm2
  73. else
  74. echo ogg123 $alarm3/*
  75. fi
  76. elif [ $bin_avplay -eq 1 ]; then
  77. if [ $default -eq 1 ]; then
  78. echo avplay -nodisp -autoexit $alarm1
  79. elif [ $default -eq 2 ]; then
  80. echo avplay -nodisp -autoexit $alarm2
  81. else
  82. echo avplay -nodisp -autoexit $alarm3'/*'
  83. fi
  84. fi
  85. }
  86. echo ""
  87. echo "Alarm time: $alarm"
  88. echo "Repeat interval: $interval"
  89. echo -n "Command: "
  90. printalarm
  91. echo ""
  92. playalarm () {
  93. if [ $bin_ogg123 -eq 1 ]; then
  94. if [ $default -eq 1 ]; then
  95. ogg123 $alarm1
  96. elif [ $default -eq 2 ]; then
  97. ogg123 $alarm2
  98. else
  99. ogg123 $alarm3/*.ogg
  100. fi
  101. elif [ $bin_avplay -eq 1 ]; then
  102. if [ $default -eq 1 ]; then
  103. avplay -nodisp -autoexit $alarm1
  104. elif [ $default -eq 2 ]; then
  105. avplay -nodisp -autoexit $alarm2
  106. else
  107. for i in $alarm3/*; do
  108. avplay -nodisp -autoexit $i
  109. done
  110. fi
  111. fi
  112. sleep $interval
  113. }
  114. passed=0
  115. while [ $passed -eq 0 ]; do
  116. if [ `date +"%H%M"` = "$alarm" ]; then
  117. passed=1
  118. echo "Rise and shine! It is `date +"%A %b %d, %Y %H:%M"`. (Press ^C to stop the alarm)\n"
  119. while [ 1 ]; do
  120. playalarm
  121. done
  122. fi
  123. sleep 10
  124. done
  125. # ChangeLog
  126. # v0.2.0 (Feb 15, 2014) - initial release