From af5c8ddf9df5f4c0d982ed6e2d4f6471cb614b8b Mon Sep 17 00:00:00 2001 From: frederik Date: Sat, 20 Sep 2025 20:55:03 +0200 Subject: [PATCH] add auto update support to update script --- scripts/update_birdnet.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/update_birdnet.sh b/scripts/update_birdnet.sh index 1df5576..62cbee3 100755 --- a/scripts/update_birdnet.sh +++ b/scripts/update_birdnet.sh @@ -3,7 +3,7 @@ source /etc/birdnet/birdnet.conf trap 'exit 1' SIGINT SIGHUP -usage() { echo "Usage: $0 [-r ] [-b ]" 1>&2; exit 1; } +usage() { echo "Usage: $0 [-r ] [-b ] [-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)