add auto update support to update script

This commit is contained in:
frederik
2025-09-20 20:55:03 +02:00
parent a9d807e243
commit af5c8ddf9d
+21 -2
View File
@@ -3,7 +3,7 @@
source /etc/birdnet/birdnet.conf
trap 'exit 1' SIGINT SIGHUP
usage() { echo "Usage: $0 [-r <remote name>] [-b <branch name>]" 1>&2; exit 1; }
usage() { echo "Usage: $0 [-r <remote name>] [-b <branch name>] [-a]" 1>&2; exit 1; }
if [ -n "${BIRDNET_USER}" ]; then
USER=${BIRDNET_USER}
@@ -17,8 +17,9 @@ my_dir=$HOME/BirdNET-Pi/scripts
# Defaults
remote="origin"
branch="main"
auto_update=""
while getopts ":r:b:" o; do
while getopts ":r:b:a" o; do
case "${o}" in
r)
remote=${OPTARG}
@@ -33,6 +34,9 @@ while getopts ":r:b:" o; do
b)
branch=${OPTARG}
;;
a)
auto_update=1
;;
*)
usage
;;
@@ -46,6 +50,21 @@ sudo_with_user () {
set +x
}
can_auto_update () {
if [ -z ${AUTOMATIC_UPDATE} ] || [ "${AUTOMATIC_UPDATE}" == 0 ]; then
echo "Auto update is not enabled"
exit 0
fi
sudo_with_user git -C $HOME/BirdNET-Pi fetch $remote $branch
behind_count=$(sudo_with_user git -C $HOME/BirdNET-Pi rev-list --count HEAD..@{u})
if [ "${behind_count}" -eq 0 ]; then
echo "No updates"
exit 0
fi
}
[ -n "${auto_update}" ] && can_auto_update
# Get current HEAD hash
commit_hash=$(sudo_with_user git -C $HOME/BirdNET-Pi rev-parse HEAD)