working on update button

This commit is contained in:
Patrick McGuire
2021-10-15 14:54:15 -04:00
parent d5620eb2af
commit 837ced6fef
4 changed files with 89 additions and 115 deletions
+9 -6
View File
@@ -2,7 +2,7 @@
<input type="submit" value="Edit the birdnet.conf file"> <input type="submit" value="Edit the birdnet.conf file">
</form> </form>
<form action="/scripts/restart_services.php"> <form action="/scripts/restart_services.php" onclick="return confirm('Restart ALL services?')">
<input type="submit" value="Restart ALL BirdNET-Pi Services"> <input type="submit" value="Restart ALL BirdNET-Pi Services">
</form> </form>
@@ -18,20 +18,23 @@
<input type="submit" value="Restart Extraction Service"> <input type="submit" value="Restart Extraction Service">
</form> </form>
<form action="/scripts/restart_caddy.php"> <form action="/scripts/restart_caddy.php" onclick="return confirm('Restart Caddy? You will be disconnected for about 20 seconds.')">
<input type="submit" value="Restart Caddy"> <input type="submit" value="Restart Caddy">
</form> </form>
<form action="/scripts/clear_all_data.php" onclick="return confirm('Are you sure?')"> <form action="/scripts/clear_all_data.php" onclick="return confirm('Clear ALL Data? This cannot be undone.')">
<input type="submit" value="Clear ALL data"> <input type="submit" value="Clear ALL data">
</form> </form>
<form action="/scripts/reboot_system.php"> <form action="/scripts/update_birdnet.php" onclick="return confirm('Are you sure you want to update?')">
<input type="submit" value="Update BirdNET-Pi">
</form>
<form action="/scripts/reboot_system.php" onclick="return confirm('Are you sure you want to reboot?')">
<input type="submit" value="Reboot BirdNET-Pi"> <input type="submit" value="Reboot BirdNET-Pi">
</form> </form>
<form action="/scripts/shutdown_system.php"> <form action="/scripts/shutdown_system.php" onclick="return confirm('Are you sure you want to shutdown?')">
<input type="submit" value="Shutdown BirdNET-Pi"> <input type="submit" value="Shutdown BirdNET-Pi">
</form> </form>
+8 -10
View File
@@ -218,6 +218,9 @@ ${EXTRACTIONS_URL} {
basicauth /stream { basicauth /stream {
birdnet ${HASHWORD} birdnet ${HASHWORD}
} }
basicauth /phpsysinfo {
birdnet ${HASHWORD}
}
reverse_proxy /stream localhost:8000 reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.3-fpm.sock php_fastcgi unix//run/php/php7.3-fpm.sock
} }
@@ -234,17 +237,12 @@ http://birdnetpi.local {
basicauth /stream { basicauth /stream {
birdnet ${HASHWORD} birdnet ${HASHWORD}
} }
basicauth /phpsysinfo {
birdnet ${HASHWORD}
}
reverse_proxy /stream localhost:8000 reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.3-fpm.sock php_fastcgi unix//run/php/php7.3-fpm.sock
} }
http://birdlog.local {
reverse_proxy localhost:8080
}
http://extractionlog.local {
reverse_proxy localhost:8888
}
EOF EOF
systemctl reload caddy systemctl reload caddy
} }
@@ -345,7 +343,7 @@ install_sox() {
} }
install_php() { install_php() {
if ! which pip &> /dev/null || ! which php-fpm7.3;then if ! which php &> /dev/null || ! which php-fpm7.3 || ! apt list --installed | grep php-xml;then
echo "Installing PHP modules" echo "Installing PHP modules"
apt -qq update apt -qq update
apt install -qqy php php-fpm php7.3-mysql php-xml apt install -qqy php php-fpm php7.3-mysql php-xml
@@ -360,7 +358,7 @@ install_php() {
caddy ALL=(ALL) NOPASSWD: ALL caddy ALL=(ALL) NOPASSWD: ALL
EOF EOF
chmod 0440 /etc/sudoers.d/010_caddy-nopasswd chmod 0440 /etc/sudoers.d/010_caddy-nopasswd
if [ -d ${HOME}/phpsysinfo ];then if [ ! -d ${HOME}/phpsysinfo ];then
echo "Fetching phpSysInfo" echo "Fetching phpSysInfo"
sudo -u ${USER} git clone https://github.com/phpsysinfo/phpsysinfo.git \ sudo -u ${USER} git clone https://github.com/phpsysinfo/phpsysinfo.git \
${HOME}/phpsysinfo ${HOME}/phpsysinfo
+47 -29
View File
@@ -1,8 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Update BirdNET-Pi # Update BirdNET-Pi
source /etc/birdnet/birdnet.conf source /etc/birdnet/birdnet.conf
trap 'rm -f ${TMPFILE}' EXIT trap 'rm -f ${tmpfile}' EXIT
SCRIPTS=(birdnet_analysis.sh trap 'exit 1' SIGINT SIGHUP
USER=pi
HOME=/home/pi
my_dir=${HOME}/BirdNET-Pi/scripts
tmpfile=$(mktemp)
scripts=(birdnet_analysis.sh
birdnet_recording.sh birdnet_recording.sh
birdnet_stats.sh birdnet_stats.sh
cleanup.sh cleanup.sh
@@ -45,34 +51,31 @@ update_species.sh
${HOME}/.gotty) ${HOME}/.gotty)
SERVICES=(avahi-alias@.service # Change this to sourcing from current uninstall.sh
avahi-alias@birdlog.local.service # Create a pre-update services array for disabling
# Create a post-update services array for restarting
services=(avahi-alias@birdlog.local.service
avahi-alias@birdnetpi.local.service avahi-alias@birdnetpi.local.service
avahi-alias@birdstats.local.service avahi-alias@birdstats.local.service
avahi-alias@extractionlog.local.service avahi-alias@extractionlog.local.service
avahi-alias@birdterminal.local.service avahi-alias@birdterminal.local.service
birdnet_analysis.d
birdnet_analysis.service birdnet_analysis.service
birdnet_log.service birdnet_log.service
birdnet_recording.d
birdnet_recording.service birdnet_recording.service
birdstats.service birdstats.service
birdterminal.service birdterminal.service
caddy.d
caddy.service
edit_birdnet_conf.service edit_birdnet_conf.service
extraction_log.service extraction_log.service
extraction.d
extraction.service extraction.service
extraction.timer extraction.timer
livestream.service livestream.service
spectrogram_viewer.service spectrogram_viewer.service)
${SYSTEMD_MOUNT})
remove_services() { remove_services() {
for i in "${SERVICES[@]}"; do for i in "${services[@]}"; do
if [ -L /etc/systemd/system/multi-user.target.wants/"${i}" ];then if [ -L /etc/systemd/system/multi-user.target.wants/"${i}" ];then
sudo systemctl kill "${i}" sudo systemctl kill "${i}"
sudo systemctl disable "${i}"
fi fi
if [ -f /etc/systemd/system/"${i}" ];then if [ -f /etc/systemd/system/"${i}" ];then
sudo rm /etc/systemd/system/"${i}" sudo rm /etc/systemd/system/"${i}"
@@ -86,9 +89,8 @@ remove_services() {
} }
remove_crons() { remove_crons() {
TMPFILE=$(mktemp) crontab -u${USER} -l | sed -e '/birdnet/,+1d' > "${tmpfile}"
crontab -l | sed -e '/birdnet/,+1d' > "${TMPFILE}" crontab -u${USER} "${tmpfile}"
crontab "${TMPFILE}"
} }
remove_icecast() { remove_icecast() {
@@ -99,24 +101,40 @@ remove_icecast() {
} }
remove_scripts() { remove_scripts() {
for i in "${SCRIPTS[@]}";do for i in "${scripts[@]}";do
if [ -L "/usr/local/bin/${i}" ];then if [ -L "/usr/local/bin/${i}" ];then
sudo rm -v "/usr/local/bin/${i}" sudo rm -v "/usr/local/bin/${i}"
fi fi
done done
} }
echo "Updating BirdNET" restart_services() {
remove_services | tee -a /tmp/birdnetupdate.log for i in ${services[@]};do
remove_scripts | tee -a /tmp/birdnetupdate.log sudo systemctl restart ${i}
cd ${HOME}/BirdNET-Pi || exit 1
git pull || exit 1
USER=${USER} sudo ./scripts/update_services.sh | tee -a /tmp/birdnetupdate.log
echo "Restarting services"
for i in "${SERVICES[@]}";do
if [ -f /etc/systemd/system/"${i}" ];then
sudo systemctl restart ${i} | tee -a /tmp/birdnetupdate.log
fi
done done
echo "Update Complete" }
# Stage 1 removes old stuff
remove_services
remove_scripts
# Stage 2 does a git pull to fetch new things
sudo -u${USER} git -C ${HOME}/BirdNET-Pi pull || exit 1
# Stage 3 updates the services
sudo ${my_dir}/update_services.sh
# Stage 4 restarts the services
services=(avahi-alias@birdnetpi.local.service
birdnet_analysis.service
birdnet_log.service
birdnet_recording.service
edit_birdnet_conf.service
extraction_log.service
extraction.service
extraction.timer
livestream.service
spectrogram_viewer.service)
restart_services
+25 -70
View File
@@ -1,13 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# This installs the services that have been selected # This installs the services that have been selected
#set -x # Uncomment to enable debugging #set -x # Uncomment to enable debugging
trap 'rm -f ${TMPFILE}' EXIT trap 'rm -f ${tmpfile}' EXIT
trap 'exit 1' SIGINT SIGHUP trap 'exit 1' SIGINT SIGHUP
my_dir=$(realpath $(dirname $0)) USER=pi
TMPFILE=$(mktemp) HOME=/home/pi
my_dir=${HOME}/BirdNET-Pi/scripts
tmpfile=$(mktemp)
nomachine_url="https://download.nomachine.com/download/7.6/Arm/nomachine_7.6.2_3_arm64.deb" nomachine_url="https://download.nomachine.com/download/7.6/Arm/nomachine_7.6.2_3_arm64.deb"
gotty_url="https://github.com/yudai/gotty/releases/download/v1.0.1/gotty_linux_arm.tar.gz" gotty_url="https://github.com/yudai/gotty/releases/download/v1.0.1/gotty_linux_arm.tar.gz"
CONFIG_FILE="$(dirname ${my_dir})/birdnet.conf" config_file="$(dirname ${my_dir})/birdnet.conf"
install_scripts() { install_scripts() {
echo "Installing BirdNET-Pi scripts to /usr/local/bin" echo "Installing BirdNET-Pi scripts to /usr/local/bin"
@@ -22,8 +24,6 @@ install_mariadb() {
apt -qqy install mariadb-server apt -qqy install mariadb-server
echo "MariaDB Installed" echo "MariaDB Installed"
fi fi
echo "Initializing the database"
# ${my_dir}/createdb.sh
} }
install_birdnet_analysis() { install_birdnet_analysis() {
@@ -76,9 +76,9 @@ EOF
if ! crontab -u ${USER} -l &> /dev/null;then if ! crontab -u ${USER} -l &> /dev/null;then
crontab -u ${USER} $(dirname ${my_dir})/templates/species_updater.cron &> /dev/null crontab -u ${USER} $(dirname ${my_dir})/templates/species_updater.cron &> /dev/null
else else
crontab -u ${USER} -l > ${TMPFILE} crontab -u ${USER} -l > ${tmpfile}
cat $(dirname ${my_dir})/templates/species_updater.cron >> ${TMPFILE} cat $(dirname ${my_dir})/templates/species_updater.cron >> ${tmpfile}
crontab -u ${USER} "${TMPFILE}" &> /dev/null crontab -u ${USER} "${tmpfile}" &> /dev/null
fi fi
} }
@@ -94,6 +94,7 @@ create_necessary_dirs() {
[ -L ${EXTRACTED}/viewdb.php ] || sudo -u ${USER} ln -s $(dirname ${my_dir})/scripts/viewdb.php ${EXTRACTED} [ -L ${EXTRACTED}/viewdb.php ] || sudo -u ${USER} ln -s $(dirname ${my_dir})/scripts/viewdb.php ${EXTRACTED}
sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED} sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED}
[ -L ${EXTRACTED}/phpsysinfo.ini ] || sudo -u ${USER} cp ${HOME}/phpsysinfo/phpsysinfo.ini.new ${HOME}/phpsysinfo/phpsysinfo.ini [ -L ${EXTRACTED}/phpsysinfo.ini ] || sudo -u ${USER} cp ${HOME}/phpsysinfo/phpsysinfo.ini.new ${HOME}/phpsysinfo/phpsysinfo.ini
} }
install_alsa() { install_alsa() {
@@ -146,41 +147,6 @@ install_sshfs() {
fi fi
} }
setup_sshkeys() {
echo "Setting up SSH keys for SSHFS"
echo "Adding remote host key to ${HOME}/.ssh/known_hosts"
ssh-keyscan -H ${REMOTE_HOST} >> ${HOME}/.ssh/known_hosts
chown ${USER}:${USER} ${HOME}/.ssh/known_hosts &> /dev/null
if [ ! -f ${HOME}/.ssh/id_ed25519.pub ];then
echo "Creating a new key"
ssh-keygen -t ed25519 -f ${HOME}/.ssh/id_ed25519 -P ""
fi
chown -R ${USER}:${USER} ${HOME}/.ssh/ &> /dev/null
echo "Copying public key to ${REMOTE_HOST}"
ssh-copy-id ${REMOTE_USER}@${REMOTE_HOST}
}
install_systemd_mount() {
echo "Installing systemd.mount"
cat << EOF > /etc/systemd/system/${SYSTEMD_MOUNT}
[Unit]
Description=Mount remote fs with sshfs
DefaultDependencies=no
Conflicts=umount.target
After=network-online.target
Before=umount.target
Wants=network-online.target
[Install]
WantedBy=multi-user.target
[Mount]
What=${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_RECS_DIR}
Where=${RECS_DIR}
Type=fuse.sshfs
Options=delay_connect,_netdev,allow_other,IdentityFile=${HOME}/.ssh/id_ed25519,reconnect,ServerAliveInterval=30,ServerAliveCountMax=5,x-systemd.automount,uid=1000,gid=1000
TimeoutSec=60
EOF
}
install_caddy() { install_caddy() {
if ! which caddy &> /dev/null ;then if ! which caddy &> /dev/null ;then
echo "Installing Caddy" echo "Installing Caddy"
@@ -199,7 +165,6 @@ install_caddy() {
install_Caddyfile() { install_Caddyfile() {
echo "Installing the Caddyfile" echo "Installing the Caddyfile"
[ -d /etc/caddy ] || mkdir /etc/caddy [ -d /etc/caddy ] || mkdir /etc/caddy
sudo -u ${USER} ln -sf $(dirname ${my_dir})/templates/index.html ${EXTRACTED}/
if [ -f /etc/caddy/Caddyfile ];then if [ -f /etc/caddy/Caddyfile ];then
cp /etc/caddy/Caddyfile{,.original} cp /etc/caddy/Caddyfile{,.original}
fi fi
@@ -217,6 +182,9 @@ ${EXTRACTIONS_URL} {
basicauth /stream { basicauth /stream {
birdnet ${HASHWORD} birdnet ${HASHWORD}
} }
basicauth /phpsysinfo {
birdnet ${HASHWORD}
}
reverse_proxy /stream localhost:8000 reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.3-fpm.sock php_fastcgi unix//run/php/php7.3-fpm.sock
} }
@@ -233,17 +201,12 @@ http://birdnetpi.local {
basicauth /stream { basicauth /stream {
birdnet ${HASHWORD} birdnet ${HASHWORD}
} }
basicauth /phpsysinfo {
birdnet ${HASHWORD}
}
reverse_proxy /stream localhost:8000 reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.3-fpm.sock php_fastcgi unix//run/php/php7.3-fpm.sock
} }
http://birdlog.local {
reverse_proxy localhost:8080
}
http://extractionlog.local {
reverse_proxy localhost:8888
}
EOF EOF
systemctl reload caddy systemctl reload caddy
} }
@@ -344,7 +307,7 @@ install_sox() {
} }
install_php() { install_php() {
if ! which pip &> /dev/null || ! which php-fpm7.3;then if ! which php &> /dev/null || ! which php-fpm7.3 || ! apt list --installed | grep php-xml;then
echo "Installing PHP modules" echo "Installing PHP modules"
apt -qq update apt -qq update
apt install -qqy php php-fpm php7.3-mysql php-xml apt install -qqy php php-fpm php7.3-mysql php-xml
@@ -353,7 +316,6 @@ install_php() {
fi fi
echo "Configuring PHP for Caddy" echo "Configuring PHP for Caddy"
sed -i 's/www-data/caddy/g' /etc/php/7.3/fpm/pool.d/www.conf sed -i 's/www-data/caddy/g' /etc/php/7.3/fpm/pool.d/www.conf
systemctl restart php7.3-fpm.service
echo "Adding Caddy sudoers rule" echo "Adding Caddy sudoers rule"
cat << EOF > /etc/sudoers.d/010_caddy-nopasswd cat << EOF > /etc/sudoers.d/010_caddy-nopasswd
caddy ALL=(ALL) NOPASSWD: ALL caddy ALL=(ALL) NOPASSWD: ALL
@@ -434,11 +396,12 @@ EOF
} }
install_nomachine() { install_nomachine() {
if [ ! -d /usr/share/NX ];then
echo "Installing NoMachine" echo "Installing NoMachine"
cd ~
curl -s -O "${nomachine_url}" curl -s -O "${nomachine_url}"
apt install -y ${HOME}/nomachine_7.6.2_3_arm64.deb apt install -y ${HOME}/nomachine_7.6.2_3_arm64.deb
rm -f ${HOME}/nomachine_7.6.2_3_arm64.deb rm -f ${HOME}/nomachine_7.6.2_3_arm64.deb
fi
} }
install_systemd_overrides() { install_systemd_overrides() {
@@ -460,9 +423,9 @@ install_cleanup_cron() {
if ! crontab -u ${USER} -l &> /dev/null;then if ! crontab -u ${USER} -l &> /dev/null;then
crontab -u ${USER} $(dirname ${my_dir})/templates/cleanup.cron &> /dev/null crontab -u ${USER} $(dirname ${my_dir})/templates/cleanup.cron &> /dev/null
else else
crontab -u ${USER} -l > ${TMPFILE} crontab -u ${USER} -l > ${tmpfile}
cat $(dirname ${my_dir})/templates/cleanup.cron >> ${TMPFILE} cat $(dirname ${my_dir})/templates/cleanup.cron >> ${tmpfile}
crontab -u ${USER} "${TMPFILE}" &> /dev/null crontab -u ${USER} "${tmpfile}" &> /dev/null
fi fi
} }
@@ -479,12 +442,6 @@ install_selected_services() {
install_recording_service install_recording_service
fi fi
if [[ "${REMOTE}" =~ [Yy] ]];then
install_sshfs
setup_sshkeys
install_systemd_mount
fi
if [ ! -z "${EXTRACTIONS_URL}" ];then if [ ! -z "${EXTRACTIONS_URL}" ];then
install_caddy install_caddy
install_Caddyfile install_Caddyfile
@@ -514,11 +471,9 @@ install_selected_services() {
install_cleanup_cron install_cleanup_cron
} }
if [ -f ${CONFIG_FILE} ];then if [ -f ${config_file} ];then
source ${CONFIG_FILE} source ${config_file}
USER=${BIRDNET_USER}
HOME="$(getent passwd ${BIRDNET_USER} | cut -d: -f6)"
install_selected_services install_selected_services
else else
echo "Unable to find a configuration file. Please make sure that $CONFIG_FILE exists." echo "Unable to find a configuration file. Please make sure that $config_file exists."
fi fi