Files
AvianVisitors/scripts/update_birdnet.sh
Twarner491 d3241f92cf Pre-share fixes from final review pass
Blockers
- http://birdnet.local/avian/ now serves the collage (added avian/index.html
  redirect to frontend/; previously the symlink target had no top-level
  index, so users saw a directory listing of api/ assets/ forwarding/
  frontend/ scripts/).
- Gemini model bumped from gemini-2.5-flash-image-preview (deprecated
  2026-01-15) to the stable gemini-2.5-flash-image. Pregen was non-
  functional out of the box.
- avian-mqtt.service: dropped %h (which expands to /root for system-mode
  units regardless of User=). Use WorkingDirectory=~ which DOES respect
  User=, plus a relative ExecStart.
- birdnet-api.php case 'lifelist' now aliases COUNT(*) AS n (was 'total'),
  matching what apt.js reads for atlas card counts. Atlas previously
  always displayed 0.

Bugs
- Retry-After parsing handles HTTP-date format without crashing.
- apt.js no longer fetches firstseen/timeseries (declared in state but
  never consumed). Two wasted round-trips per page load removed.
- update_birdnet.sh defaults branch=avian-visitors so the (opt-in)
  Sunday auto-update cron doesn't reset HEAD to upstream main and
  delete the avian/ overlay.
- recording.php: removed dead $BIRDS_JSON_CANDIDATES.

Polish
- Pregen --sleep default raised 4→6s (more headroom under free-tier RPM).
- en-dash in README BOM (~$35–80) replaced with hyphen for style match.
- Slop sweep across user-facing docs: no em-dashes, no en-dashes, no
  AI-slop word hits (robust/comprehensive/seamless/etc.).
2026-05-28 11:11:20 -07:00

94 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Update BirdNET-Pi's Git Repo
source /etc/birdnet/birdnet.conf
trap 'exit 1' SIGINT SIGHUP
usage() { echo "Usage: $0 [-r <remote name>] [-b <branch name>] [-a]" 1>&2; exit 1; }
if [ -n "${BIRDNET_USER}" ]; then
USER=${BIRDNET_USER}
HOME=/home/${BIRDNET_USER}
else
USER=$(awk -F: '/1000/ {print $1}' /etc/passwd)
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
fi
my_dir=$HOME/BirdNET-Pi/scripts
# Defaults
remote="origin"
# AvianVisitors fork: track our overlay branch by default so the
# Sunday auto-update cron (when enabled) doesn't switch back to
# upstream `main` and delete the avian/ directory.
branch="avian-visitors"
auto_update=""
while getopts ":r:b:a" o; do
case "${o}" in
r)
remote=${OPTARG}
git -C $HOME/BirdNET-Pi remote show $remote > /dev/null 2>&1
ret_val=$?
if [ $ret_val -ne 0 ]; then
echo "Error: remote '$remote' not found. Add the upstream remote to your repository and try again."
exit 1
fi
;;
b)
branch=${OPTARG}
;;
a)
auto_update=1
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
sudo_with_user () {
set -x
sudo -u $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)
# Reset current HEAD to remove any local changes
sudo_with_user git -C $HOME/BirdNET-Pi reset --hard
# Fetches latest changes
sudo_with_user git -C $HOME/BirdNET-Pi fetch $remote $branch
# Switches git to specified branch
sudo_with_user git -C $HOME/BirdNET-Pi switch -C $branch --track $remote/$branch
# Prints out changes
sudo_with_user git --no-pager -C $HOME/BirdNET-Pi diff --stat $commit_hash HEAD
$my_dir/pre_update.sh
sudo systemctl daemon-reload
sudo ln -sf $my_dir/* /usr/local/bin/
# The script below handles changes to the host system
# Any additions to the updater should be placed in that file.
sudo $my_dir/update_birdnet_snippets.sh