add auto update support to update script
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
source /etc/birdnet/birdnet.conf
|
source /etc/birdnet/birdnet.conf
|
||||||
trap 'exit 1' SIGINT SIGHUP
|
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
|
if [ -n "${BIRDNET_USER}" ]; then
|
||||||
USER=${BIRDNET_USER}
|
USER=${BIRDNET_USER}
|
||||||
@@ -17,8 +17,9 @@ my_dir=$HOME/BirdNET-Pi/scripts
|
|||||||
# Defaults
|
# Defaults
|
||||||
remote="origin"
|
remote="origin"
|
||||||
branch="main"
|
branch="main"
|
||||||
|
auto_update=""
|
||||||
|
|
||||||
while getopts ":r:b:" o; do
|
while getopts ":r:b:a" o; do
|
||||||
case "${o}" in
|
case "${o}" in
|
||||||
r)
|
r)
|
||||||
remote=${OPTARG}
|
remote=${OPTARG}
|
||||||
@@ -33,6 +34,9 @@ while getopts ":r:b:" o; do
|
|||||||
b)
|
b)
|
||||||
branch=${OPTARG}
|
branch=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
a)
|
||||||
|
auto_update=1
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
@@ -46,6 +50,21 @@ sudo_with_user () {
|
|||||||
set +x
|
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
|
# Get current HEAD hash
|
||||||
commit_hash=$(sudo_with_user git -C $HOME/BirdNET-Pi rev-parse HEAD)
|
commit_hash=$(sudo_with_user git -C $HOME/BirdNET-Pi rev-parse HEAD)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user