-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup-piprayer.sh
executable file
·67 lines (54 loc) · 2.04 KB
/
setup-piprayer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# PiPrayer - Azaan for Raspberry Pi
# Copyright (C) 2021 Kamran Zafar
#
# 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 <https://www.gnu.org/licenses/>.
CURR_PATH=$(dirname $(realpath "$0"))
CONF_FILE="$CURR_PATH/.piprayer"
CRON_FILE="$CURR_PATH/.piprayercron"
CRON_BLOCK="## PI PRAYER ##"
AZAAN=1
if [ $# -ne 0 ]; then
AZAAN=$1
fi
if [ -z "$XDG_RUNTIME_DIR" ]; then
echo "XDG_RUNTIME_DIR variable not set. Please set the variable and run the setup again."
exit 1
fi
if [ ! -f "$CONF_FILE" ]; then
echo "Configuration file $CONF_FILE not found"
exit 1
fi
PRAYER_TIMES=$(python "$CURR_PATH"/piprayer.py "$CONF_FILE")
if [ "$?" -ne "0" ]; then
echo "$PRAYER_TIMES"
exit 1
fi
#echo "$PRAYER_TIMES"
NEW_CRON="$CRON_BLOCK"
for prayer in $PRAYER_TIMES; do
PRAYER_NAME=$(echo "$prayer" | cut -f1 -d-)
PRAYER_TIME_H=$(echo "$prayer" | cut -f2 -d- | cut -f1 -d:)
PRAYER_TIME_M=$(echo "$prayer" | cut -f2 -d- | cut -f2 -d:)
NEW_CRON="$NEW_CRON\n$PRAYER_TIME_M $PRAYER_TIME_H * * * export XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR && $CURR_PATH/play-azaan.sh $AZAAN #$PRAYER_NAME"
done
NEW_CRON="$NEW_CRON\n0 1 * * * export XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR && $CURR_PATH/$(basename "$0") $AZAAN"
NEW_CRON="$NEW_CRON\n$CRON_BLOCK\n"
#echo -e "$NEW_CRON"
crontab -l >"$CRON_FILE"
cp "$CRON_FILE" "$CRON_FILE.bak"
cat "$CRON_FILE.bak" | sed '/## PI PRAYER ##/,/## PI PRAYER ##/d' >"$CRON_FILE"
echo -e "$NEW_CRON" >>"$CRON_FILE"
crontab <"$CRON_FILE"
rm -f "$CRON_FILE"