-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrontab.sh
More file actions
59 lines (56 loc) · 1.47 KB
/
crontab.sh
File metadata and controls
59 lines (56 loc) · 1.47 KB
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
#!/bin/sh
has_p_option=false
while getopts :p opt; do
case $opt in
p) has_p_option=true ;;
:)
echo "Missing argument for option -$OPTARG"
exit 1
;;
\?)
echo "Unknown option -$OPTARG"
exit 1
;;
esac
done
# here's the key part: remove the parsed options from the positional params
shift $((OPTIND - 1))
exe=$(python -c "import sys;print(sys.executable)")
if ! command -v tesseract >/dev/null 2>&1; then
newpath="# Tesseract was not found. Make sure it is installed and is in PATH."
else
tesseract=$(dirname "$(which tesseract)")
newpath="PATH=\$PATH:$tesseract"
fi
before="# >>> Added by nlf - Northern Lights Forecast >>>"
after="# <<< Added by nlf - Northern Lights Forecast <<<"
run_forecast="0 0-8,18-23 * 9-12,1-3 * export DISPLAY=:0 && cd $PWD && $exe src/northern_lights_forecast/__main__.py > /dev/null 2>&1"
start_bot="*/10 * * * * export DISPLAY=:0 && cd $PWD && $exe src/northern_lights_forecast/nlf_telegram_bot.py > /dev/null 2>&1"
if "$has_p_option"; then
echo "$before"
echo "$newpath"
echo "$run_forecast"
echo "$start_bot"
echo "$after"
else
(
crontab -l
echo "$before"
) | crontab -
(
crontab -l
echo "$newpath"
) | crontab -
(
crontab -l
echo "$run_forecast"
) | crontab -
(
crontab -l
echo "$start_bot"
) | crontab -
(
crontab -l
echo "$after"
) | crontab -
fi