Skip to content

A live bird collage card for your Home Assistant dashboard.

add auto update support to update script

frederikaf5c8ddf9df5
diff --git a/scripts/update_birdnet.sh b/scripts/update_birdnet.sh
index 1df55765..62cbee36 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 <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)