-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·40 lines (34 loc) · 921 Bytes
/
install.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
#!/bin/bash
# Save shell options to be restored later
previous_state="$(set +o); set -$-"
set -xe
# Install packaged dependencies
sudo apt update
sudo apt install -y build-essential python3-yaml python3-paho-mqtt
# Install NodeJS dependencies
npm ci
# Add crontab entry for MQTT script
CRONTAB_ENTRY='@reboot /bin/sleep 15 && /usr/bin/python3 -u /home/pi/MorningNews/mqtt_ha_client.py >/tmp/MorningNews_MQTT.log 2>&1'
if crontab -l | grep -q "$CRONTAB_ENTRY"; then
echo "Crontab entry is already in place"
else
TMPFILE="$(mktemp)"
crontab -l > "$TMPFILE"
echo -e "\n$CRONTAB_ENTRY" >> "$TMPFILE"
crontab "$TMPFILE"
rm "$TMPFILE"
fi
# Add logrotate entry
cat << EOF | sudo tee /etc/logrotate.d/morning_news >/dev/null
/tmp/MorningNews.log
/tmp/MorningNews_MQTT.log {
rotate 0
daily
missingok
notifempty
copytruncate
}
EOF
# Restore previously saved shell options
set +xe
eval "$previous_state"