60 lines
1.4 KiB
Bash
Executable File
60 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Update BirdNET-Pi
|
|
source /etc/birdnet/birdnet.conf
|
|
trap 'rm -f ${tmpfile}' EXIT
|
|
trap 'exit 1' SIGINT SIGHUP
|
|
USER=pi
|
|
HOME=/home/pi
|
|
my_dir=${HOME}/BirdNET-Pi/scripts
|
|
tmpfile=$(mktemp)
|
|
|
|
services=$(awk '/service/ && /systemctl/ && !/php/ {print $3}' ${my_dir}/install_services.sh | sort)
|
|
|
|
remove_services() {
|
|
for i in "${services[@]}"; do
|
|
if [ -L /etc/systemd/system/multi-user.target.wants/"${i}" ];then
|
|
sudo systemctl kill "${i}"
|
|
sudo systemctl disable "${i}"
|
|
fi
|
|
if [ -f /etc/systemd/system/"${i}" ];then
|
|
sudo rm /etc/systemd/system/"${i}"
|
|
fi
|
|
if [ -d /etc/systemd/system/"${i}" ];then
|
|
sudo rm -drf /etc/systemd/system/"${i}"
|
|
fi
|
|
done
|
|
remove_icecast
|
|
remove_crons
|
|
}
|
|
|
|
remove_crons() {
|
|
sudo sed -i '/birdnet/,+1d' /etc/crontab
|
|
}
|
|
|
|
remove_icecast() {
|
|
if [ -f /etc/init.d/icecast2 ];then
|
|
sudo /etc/init.d/icecast2 stop
|
|
sudo systemctl disable --now icecast2
|
|
fi
|
|
}
|
|
|
|
remove_scripts() {
|
|
for i in "${scripts[@]}";do
|
|
if [ -L "/usr/local/bin/${i}" ];then
|
|
sudo rm -v "/usr/local/bin/${i}"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Stage 1 removes old stuff
|
|
remove_services
|
|
remove_scripts
|
|
|
|
# Backup labels.txt
|
|
sudo -u${USER} cp -f ~/BirdNET-Pi/model/labels.txt{,.bak}
|
|
# Stage 2 does a git pull to fetch new things
|
|
sudo -u${USER} git -C ${HOME}/BirdNET-Pi checkout -f
|
|
sudo -u${USER} git -C ${HOME}/BirdNET-Pi pull -f
|
|
# Trigger the new update_birdnet2.sh
|
|
sudo -u${USER} ${my_dir}/update_birdnet2.sh
|