balarm.sh (2537B)
1 #!/usr/bin/env bash 2 # Copyright (C) 2020 Jan "JayVii" 3 # Author 2020 Jan "JayVii" <jayvii [AT] posteo [DOT] de> 4 # SPDX-License-Identifier: gpl-3.0 5 # About this header: <https://reuse.software> 6 7 ############################################################################### 8 # balarm.sh - the alarm-script written in bash. # 9 # # 10 # this script is typically executed by daemon.sh, but may also work with cron # 11 # # 12 # this script requires "yad" and "mpv" to be installed. # 13 ############################################################################### 14 15 # Configuration --------------------------------------------------------------- 16 BASE_PATH="$HOME/.config/balarm" 17 ALARM_FILE="$BASE_PATH/sound" 18 SNOOZE_TIME=300 19 20 # defaults -------------------------------------------------------------------- 21 ZZZACTION=0 22 FULLVOLUME=1 23 24 # checks ---------------------------------------------------------------------- 25 # has alarmtone been chosen yet? 26 if [ ! -f "$ALARM_FILE" ]; then 27 # assuming some tone... 28 ln -s /usr/share/sounds/freedesktop/stereo/phone-incoming-call.oga \ 29 "$ALARM_FILE" 30 fi 31 32 # turn up volume 33 if [ $FULLVOLUME == 1 ]; then 34 pactl set-sink-volume 0 0.99 # not really sure why, but it works... 35 pactl set-sink-volume 1 0.99 # can be either apparently... 36 fi 37 38 # Function: ring alarm -------------------------------------------------------- 39 function alarm_ring { 40 # play ringtone 41 mpv --loop-file=inf "$1" & 42 # noting down PID of alarm process 43 ALARMPID=$! 44 } 45 46 # Function: ask user what to do ----------------------------------------------- 47 function zzzorawake { 48 yad --title="Alarm!" \ 49 --text="$(date '+%a, %Y-%m-%d %H:%M:%S')" \ 50 --button="Snooze..." \ 51 --button="Stop!" 52 ZZZACTION=$? 53 } 54 55 # initial run ----------------------------------------------------------------- 56 # ringing alarm... 57 alarm_ring "$ALARM_FILE" 58 # asking user what to do 59 zzzorawake 60 61 # the famous snooze loop ------------------------------------------------------ 62 # if snooze was chosen, wait for another 5 minutes before ringing 63 while [ $ZZZACTION == 0 ]; do 64 kill -9 $ALARMPID 65 sleep $SNOOZE_TIME # snooze... 66 alarm_ring "$ALARM_FILE" # ring alarm 67 zzzorawake # ask user what to do 68 done 69 70 # if you finally get up, we can stop the misery ------------------------------- 71 kill $ALARMPID 72 73 # EOF balarm.sh