pinephone-scripts

Scripts and small applications for the PinePhone
git clone https://src.jayvii.de/pub/pinephone-scripts.git
Log | Files | Refs | README | LICENSE

commit bd6dbba5223f85854797f26b3ea369d38a121985
parent 828f592fd74c6c8d3e73ced9c68d02102e02583a
Author: JayVii <jayvii@posteo.de>
Date:   Thu,  5 Nov 2020 21:29:07 +0100

Fix Up code

Diffstat:
Mbalarm/balarm.sh | 2+-
Mbalarm/daemon.sh | 38+++++++++++++++++++++++---------------
2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/balarm/balarm.sh b/balarm/balarm.sh @@ -13,7 +13,7 @@ ############################################################################### # Configuration --------------------------------------------------------------- -BASE_PATH="~/.config/balarm" +BASE_PATH="$HOME/.config/balarm" ALARM_FILE="$BASE_PATH/sound" SNOOZE_TIME=300 diff --git a/balarm/daemon.sh b/balarm/daemon.sh @@ -12,9 +12,9 @@ ############################################################################### # Configuration --------------------------------------------------------------- -BASE_PATH="~/.config/balarm" -PID_FILE="~/.cache/balarm.pid" -RANG_FILE="~/.cache/balarm.log" +BASE_PATH="$HOME/.config/balarm" +PID_FILE="$HOME/.cache/balarm.pid" +RANG_FILE="$HOME/.cache/balarm.log" TIME_FILE="$BASE_PATH/timings.txt" # SetUp ----------------------------------------------------------------------- @@ -33,18 +33,26 @@ function compare_time { _MINUTES=$(echo "$1" | awk '{ print $2 }') _DAY=$(echo "$1" | awk '{ print $3 }') # construct +1 and -1 minute strings - if [ $_MINUTES == 0 ]; then - M1="$(($_HOURS - 1)) 59 $_DAY" + if [[ $_MINUTES -eq 0 ]]; then + if [[ $_HOURS -lt 11 ]]; then + M1="0$(($_HOURS - 1)) 59 $_DAY" + else + M1="$(($_HOURS - 1)) 59 $_DAY" + fi P1="$_HOURS $(($_MINUTES + 1)) $_DAY" - elif [ $_MINUTES == 59 ]; then - M1="$_HOURS $(($_MINUTES - 1)) $_DAY" + elif [[ $_MINUTES -eq 59 ]]; then + M1="$_HOURS 58 $_DAY" P1="$(($_HOURS + 1)) 00 $_DAY" else - M1="$_HOURS $(($_MINUTES - 1)) $_DAY" + if [[ $_MINUTES -lt 11 ]]; then + M1="$_HOURS 0$(($_MINUTES - 1)) $_DAY" + else + M1="$_HOURS $(($_MINUTES - 1)) $_DAY" + fi P1="$_HOURS $(($_MINUTES + 1)) $_DAY" fi # compare strings - if [[ "$2" == "$1" ]] || [[ "$2" == "$M1" ]] || [[ "$2" == "$P1"]]; then + if [[ "$2" == "$1" ]] || [[ "$2" == "$M1" ]]; then #|| [[ "$2" == "$P1" ]]; then TIME_MATCH=1 else TIME_MATCH=0 @@ -52,10 +60,10 @@ function compare_time { } # checks whether current alarm has been executed already. -rang_yet { +function rang_yet { # check whether current alarm has been executed today already... _RANG=$(grep "$CURRDATE $ALARM" "$RANG_FILE") - if [[ "$_RANG" ]]; then + if [[ "$_RANG" == "$CURRDATE $ALARM" ]]; then HAS_RANG=1 # yes, it has! else HAS_RANG=0 # no, it has not! @@ -91,16 +99,16 @@ while :; do CURRDATE=$(date "+%Y %m %d") # loop through all set up alarms - for i in {1..$ALARM_N}; do + for i in $(seq 1 1 $ALARM_N); do # current alarm's time - ALARMTIME=$(sed -ne '${i}p' "$TIME_FILE") + ALARMTIME=$(sed -ne "${i}p" "$TIME_FILE") # compare alarm time to current time compare_time "$CURRTIME" "$ALARMTIME" # if they match, check whether it has been executed already - if [ $TIME_MATCH == 1 ]; then + if [ $TIME_MATCH -eq 1 ]; then rang_yet # if it has not been executed yet, execute it - if [ $HAS_RANG == 0 ]; then + if [ $HAS_RANG -eq 0 ]; then balarm.sh & echo "$CURRDATE $ALARMTIME" > "$RANG_FILE" fi