From 88b2d10214aaed05ee42eb5a1e25a4ff77cc5d29 Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Wed, 10 Nov 2021 12:12:59 -0500 Subject: [PATCH 1/6] root user for db now is socket-only (one less thing for the user to set) --- Birders_Guide_Installer.sh | 158 ++++++++++------------ Birders_Guide_Installer_Configuration.txt | 7 +- birdnet.conf-defaults | 6 +- scripts/birdnet-pi-config | 80 +---------- scripts/createdb.sh | 4 +- 5 files changed, 83 insertions(+), 172 deletions(-) diff --git a/Birders_Guide_Installer.sh b/Birders_Guide_Installer.sh index 6d102db..2ef92b5 100755 --- a/Birders_Guide_Installer.sh +++ b/Birders_Guide_Installer.sh @@ -87,93 +87,75 @@ The installation has finished. Press Enter to close this window." install_birdnet_config() { cat << EOF > ${my_dir}/birdnet.conf ################################################################################ -# Configuration settings for the BirdNET-Pi # +# Configuration settings for BirdNET-Pi # ################################################################################ -#___________The four variables below are the only that are required.___________# +############ CHANGE THE LATITUDE AND LONGITUDE TO STATIC VALUES ################ -## BIRDNET_USER should be the non-root user systemd should use to execute each -## service. -BIRDNET_USER=pi +## LATITUDE and LONGITUDE are self-explanatroy. Find them easily at +## maps.google.com. +## Example: these coordinates would indicate the Eiffel Tower in Paris, France. +## LATITUDE=48.858 +## LONGITUDE=2.294 + +## These are input as shell substitutions so that this will work out of the box. +## It guesses your latitude and longitude based off of your network information. +## THESE SHOULD BE CHANGED TO STATIC NUMBERS!!!! +LATITUDE=${LATITUDE} +LONGITUDE=${LONGITUDE} ## RECS_DIR is the location birdnet_analysis.service will look for the data-set ## it needs to analyze. Be sure this directory is readable and writable for ## the BIRDNET_USER. If you are going to be accessing a remote data-set, you ## still need to set this, as this will be where the remote directory gets -## mounted locally. +## mounted locally. -RECS_DIR=${HOME}/BirdSongs +RECS_DIR=/home/pi/BirdSongs -## LATITUDE and LONGITUDE are self-explanatroy. Find them easily at -## maps.google.com. Only go to the thousanths place for these variables -## Example: these coordinates would indicate the Eiffel Tower in Paris, France. -## LATITUDE=48.858 -## LONGITUDE=2.294 +#----------------------- Web Interface User Password ------------------------# +#____________________The variable below sets the 'birdnet'_____________________# +#___________________user password for the live audio stream,___________________# +#_________________web tools, system info, and processed files__________________# -LATITUDE=${LATITUDE} -LONGITUDE=${LONGITUDE} +## CADDY_PWD is the plaintext password (that will be hashed) and used to access +## certain parts of the web interface -################################################################################ -#------------------------------ Extraction Service ---------------------------# +CADDY_PWD=changeme -# Keep this EMPTY if you do not want this device to perform the extractions # +#------------------------- MariaDB User Passwords ---------------------------# +#_____________The variable below sets the password for the_____________________# +#_______________________'birder' user on the MariaDB___________________________# -## DO_EXTRACTIONS is simply a setting for enabling the extraction.service. -## Set this to Y or y to enable extractions. +## DB_PWD is for the 'birder' user +DB_PWD=changeme -DO_EXTRACTIONS=y +#------------------------- Live Audio Stream --------------------------------# +#_____________The variable below configures/enables the live___________________# +#_____________________________audio stream.____________________________________# -################################################################################ -#----------------------------- Recording Service ----------------------------# -#____________________The variable below can be set to enable __________________# -#________________________the birdnet_recording.service ________________________# -# Keep this EMPTY if you do not want this device to perform the recording. # +## ICE_PWD is the password that icecast2 will use to authenticate ffmpeg as a +## trusted source for the stream. You will never need to enter this manually +## anywhere other than here. -## DO_RECORDING is simply a setting for enabling the 24/7 -## birdnet_recording.service. -## Set this to Y or y to enable recording. +ICE_PWD=changeme -DO_RECORDING=y - -################################################################################ #----------------------- Web-hosting/Caddy File-server -----------------------# #________The four variables below can be set to enable internet access_________# #____________to your data,(e.g., extractions, raw data, live___________________# #______________audio stream, BirdNET.selection.txt files)______________________# -# Leave these EMPTY if you do not want to enable web access # ## BIRDNETPI_URL is the URL where the extractions, data-set, and live-stream -## will be web-hosted. If you do not own a domain, or would just prefer to keep +## will be web-hosted. If you do not own a domain, or would just prefer to keep ## the BirdNET-Pi on your local network, keep this EMPTY. BIRDNETPI_URL=${BIRDNETPI_URL} EXTRACTIONLOG_URL=${EXTRACTIONLOG_URL} BIRDNETLOG_URL=${BIRDNETLOG_URL} -## CADDY_PWD is the plaintext password (that will be hashed) and used to access -## the "Processed" directory and live audio stream. This MUST be set if you -## choose to enable this feature. -CADDY_PWD=${CADDY_PWD} - -################################################################################ -#------------------------- Live Audio Stream --------------------------------# -#_____________The variable below configures/enables the live___________________# -#_____________________________audio stream.____________________________________# - -# Keep this EMPTY if you do not wish to enable the live stream # -# or if this device is not doing the recording # - -## ICE_PWD is the password that icecast2 will use to authenticate ffmpeg as a -## trusted source for the stream. You will never need to enter this manually -## anywhere other than here. - -ICE_PWD=${ICE_PWD} - -################################################################################ #------------------- Mobile Notifications via Pushed.co ---------------------# #____________The two variables below enable mobile notifications_______________# #_____________See https://pushed.co/quick-start-guide to get___________________# @@ -187,6 +169,9 @@ PUSHED_APP_KEY=${PUSHED_APP_KEY} PUSHED_APP_SECRET=${PUSHED_APP_SECRET} ################################################################################ +#-------------------------------- Defaults ----------------------------------# +################################################################################ + #------------------------------- NoMachine ----------------------------------# #_____________The variable below can be set include NoMachine__________________# #_________________remote desktop software to be installed._____________________# @@ -201,14 +186,27 @@ PUSHED_APP_SECRET=${PUSHED_APP_SECRET} INSTALL_NOMACHINE=y -################################################################################ -#-------------------------------- Defaults ----------------------------------# -#______The seven variables below are default settings that you (probably)______# -#__________________don't need to change at all, but can._______________________# +# +#------------------------------ Extraction Service ---------------------------# -## REC_CARD is the sound card you would want the birdnet_recording.service to -## use. This setting is irrelevant if you are not planning on doing data -## collection via recording on this machine. The command substitution below +## DO_EXTRACTIONS is simply a setting for enabling the extraction.service. +## Set this to Y or y to enable extractions. + +DO_EXTRACTIONS=y + +#----------------------------- Recording Service ----------------------------# +#____________________The variable below can be set to enable __________________# +#________________________the birdnet_recording.service ________________________# + +## DO_RECORDING is simply a setting for enabling the 24/7 +## birdnet_recording.service. +## Set this to Y or y to enable recording. + +DO_RECORDING=y + +## REC_CARD is the sound card you would want the birdnet_recording.service to +## use. This setting is irrelevant if you are not planning on doing data +## collection via recording on this machine. The command substitution below ## looks for a USB microphone's dsnoop alsa device. The dsnoop device lets ## birdnet_recording.service and livestream.service share the raw audio stream ## from the microphone. If you would like to use a different microphone than @@ -218,8 +216,8 @@ INSTALL_NOMACHINE=y REC_CARD=default -## PROCESSED is the directory where the formerly 'Analyzed' files are moved -## after extractions have been made from them. This includes both WAVE and +## PROCESSED is the directory where the formerly 'Analyzed' files are moved +## after extractions have been made from them. This includes both WAVE and ## BirdNET.selection.txt files. PROCESSED=${RECS_DIR}/Processed @@ -231,7 +229,7 @@ EXTRACTED=${RECS_DIR}/Extracted ## IDFILE is the file that keeps a complete list of every spececies that ## BirdNET has identified from your data-set. It is persistent across ## data-sets, so would need to be whiped clean through deleting or renaming -## it. A backup is automatically made from this variable each time it is +## it. A backup is automatically made from this variable each time it is ## updated (structure: ${IDFILE}.bak), and would also need to be removed ## or renamed to start a new file between data-sets. Alternately, you can ## change this variable between data-sets to preserve records of disparate @@ -244,7 +242,7 @@ IDFILE=${HOME}/BirdNET-Pi/IdentifiedSoFar.txt OVERLAP=0.0 -## CONFIDENCE is the minimum confidence level from 0.0-1.0 BirdNET's analysis +## CONFIDENCE is the minimum confidence level from 0.0-1.0 BirdNET's analysis ## should reach before creating an entry in the BirdNET.selection.txt file. ## Don't set this to 1.0 or you won't have any results. @@ -254,42 +252,32 @@ CONFIDENCE=0.7 SENSITIVITY=1.25 -################################################################################ -#------------------------------ Auto-Generated ------------------------------# -#_____________________The variables below are auto-generated___________________# -#______________________________during installation_____________________________# - ## CHANNELS holds the variabel that corresponds to the number of channels the ## sound card supports. CHANNELS=2 -# Don't touch the variables below - -## SYSTEMD_MOUNT is created from the RECS_DIR variable to comply with systemd -## mount naming requirements. - -SYSTEMD_MOUNT=$(echo ${RECS_DIR#/} | tr / -).mount - ## VENV is the virtual environment where the the BirdNET python build is found, ## i.e, VENV is the virtual environment miniforge built for BirdNET. -VENV=${my_dir}/birdnet - -################################################################################ -#---------------------------------- Testing -----------------------------------# -#_____________These variables are for testing. Please do not touch_____________# -#_______________them if you are not testing these features.____________________# +VENV=/home/pi/BirdNET-Pi/birdnet +## RECORDING_LENGTH sets the length of the recording that BirdNET-Lite will analyze. RECORDING_LENGTH= +## EXTRACTION_LENGTH sets the length of the audio extractions that will be made +## from each BirdNET-Lite detection. EXTRACTION_LENGTH= +## BIRDNET_USER should be the non-root user systemd should use to execute each +## service. + +BIRDNET_USER=pi + + +## These are just for debugging LAST_RUN= THIS_RUN= - -DB_PWD=${DB_PWD} -DB_ROOT_PWD=${DB_ROOT_PWD} EOF [ -d /etc/birdnet ] || sudo mkdir /etc/birdnet sudo ln -sf ${my_dir}/birdnet.conf /etc/birdnet/birdnet.conf diff --git a/Birders_Guide_Installer_Configuration.txt b/Birders_Guide_Installer_Configuration.txt index 78445fc..b4aa1cd 100644 --- a/Birders_Guide_Installer_Configuration.txt +++ b/Birders_Guide_Installer_Configuration.txt @@ -31,13 +31,10 @@ LONGITUDE= CADDY_PWD= ICE_PWD= -# 1. DB_PWD is the password that the system will use to access the database. Set this to -# anything you want. -# 2. DB_ROOT_PWD is the password that the system will use to secure the database's root -# account. Set this to anything you want. +# DB_PWD is the password that the system will use to access the database. Set this to +# anything you want. DB_PWD= -DB_ROOT_PWD= # This section can be left alone. If you setup a Pushed.co # mobile application, you can enter the App secret and secret diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults index 0ba5c3c..a20c045 100644 --- a/birdnet.conf-defaults +++ b/birdnet.conf-defaults @@ -36,13 +36,11 @@ RECS_DIR=/home/pi/BirdSongs CADDY_PWD=changeme #------------------------- MariaDB User Passwords ---------------------------# -#_____________The variables below set the 'birder' and 'root'__________________# -#_______________________user passwords for the MariaDB_________________________# +#_____________The variable below sets the password for the_____________________# +#_______________________'birder' user on the MariaDB___________________________# ## DB_PWD is for the 'birder' user DB_PWD=changeme -## DB_ROOT_PWD is for the 'root' user -DB_ROOT_PWD=changeme #------------------------- Live Audio Stream --------------------------------# #_____________The variable below configures/enables the live___________________# diff --git a/scripts/birdnet-pi-config b/scripts/birdnet-pi-config index 2560b51..da8d172 100755 --- a/scripts/birdnet-pi-config +++ b/scripts/birdnet-pi-config @@ -485,17 +485,6 @@ do_reget_birdnetpi_urls() { fi } -do_reget_db_root_pwd() { - db_root_pwd=$(whiptail --inputbox "Please set the password the 'root' user will use to access the database." \ - 19 70 3>&1 1>&2 2>&3) ${birdnetpi_dir}/scripts/rewrite_config.sh - if [ $? -eq 0 ];then - return 0 - ASK_TO_REBOOT=2 - else - return 1 - fi -} - do_reget_db_pwd() { db_pwd=$(whiptail --inputbox "Please set the password the 'birder' user will use to access the database." \ 19 70 3>&1 1>&2 2>&3) ${birdnetpi_dir}/scripts/rewrite_config.sh @@ -614,17 +603,6 @@ do_get_birdnetpi_url() { fi } -do_get_db_root_pwd() { - db_root_pwd=$(whiptail --inputbox "Please set the password the 'root' user will use to access the database." \ - 19 70 3>&1 1>&2 2>&3) ${birdnetpi_dir}/scripts/write_config.sh - if [ $? -eq 0 ];then - return 0 - ASK_TO_REBOOT=2 - else - return 1 - fi -} - do_get_db_pwd() { db_pwd=$(whiptail --inputbox "Please set the password the 'birder' user will use to access the database." \ 19 70 3>&1 1>&2 2>&3) ${birdnetpi_dir}/scripts/write_config.sh @@ -759,56 +737,6 @@ do_advanced_reconfig_menu() { done } -do_reget_db_pwds() { - MENU=8 - while [ $MENU -eq 8 ];do - if is_pi ; then - FUN=$(whiptail --title "BirdNET-Pi Software Configuration Tool (birdnet-pi-config)" --menu "Reset Datbase Passwords" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ - "'birder' " "Set the database password for the 'birder' user" \ - "'root' " "Set the database password for the 'root' user" \ - 3>&1 1>&2 2>&3) - else - exit - fi - RET=$? - if [ $RET -eq 1 ]; then - return 0 - MENU=0 - elif [ $RET -eq 0 ]; then - case "$FUN" in - *bird*) do_reget_db_pwd;; - *root*) do_reget_db_root_pwd;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 - fi - done -} - -do_get_db_pwds() { - MENU=7 - while [ $MENU -eq 7 ];do - if is_pi ; then - FUN=$(whiptail --title "BirdNET-Pi Software Configuration Tool (birdnet-pi-config)" --menu "Set Datbase Passwords" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ - "'birder' " "Set the database password for the 'birder' user" \ - "'root' " "Set the database password for the 'root' user" \ - 3>&1 1>&2 2>&3) - else - exit - fi - RET=$? - if [ $RET -eq 1 ]; then - return 0 - MENU=0 - elif [ $RET -eq 0 ]; then - case "$FUN" in - *bird*) do_get_db_pwd;; - *root*) do_get_db_root_pwd;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 - fi - done -} - do_interface_menu() { MENU=6 while [ $MENU -eq 6 ];do @@ -911,7 +839,7 @@ do_reconfig_birdnet_menu() { "Latitude " "Set the latitude your system should use" \ "Longitude" "Set the longitude your system should use" \ "Caddy Password" "Set the web interface password" \ - "Database Passwords" "Set the passwords the MariaDB will use" \ + "Database Password" "Set the password BirdNET-Pi will use to access the DB" \ "Advanced Settings" "Sensitivity, Overlap, Confidence, URLs" \ 3>&1 1>&2 2>&3) else @@ -926,7 +854,7 @@ do_reconfig_birdnet_menu() { Lat*) do_reget_lat;; Lon*) do_reget_lon;; Cad*) do_reget_caddy_pwd;; - Data*) do_reget_db_pwds;; + Data*) do_reget_db_pwd;; Advanced*) do_advanced_reconfig_menu;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 @@ -943,7 +871,7 @@ do_config_birdnet_menu() { "Longitude" "Set the longitude your system should use" \ "Caddy Password" "Set the web interface password" \ "IceCast2 Password" "Set the IceCast2 password" \ - "Database Passwords" "Set the passwords the MariaDB will use" \ + "Database Password" "Set the password BirdNET-Pi will use to access the DB" \ "Set Custom URLS" "Designate custom URLs for the web services if you've set that up" \ 3>&1 1>&2 2>&3) else @@ -959,7 +887,7 @@ do_config_birdnet_menu() { Lon*) do_get_lon;; Cad*) do_get_caddy_pwd;; Ice*) do_get_ice_pwd;; - Data*) do_get_db_pwds;; + Data*) do_get_db_pwd;; Set*) do_get_birdnetpi_url; do_get_birdnetlog_url; do_get_extractionlog_url;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 diff --git a/scripts/createdb.sh b/scripts/createdb.sh index 7f05db3..9f73eee 100755 --- a/scripts/createdb.sh +++ b/scripts/createdb.sh @@ -10,8 +10,8 @@ source /etc/birdnet/birdnet.conf mysql_secure_installation << EOF y -${DB_ROOT_PWD} -${DB_ROOT_PWD} +n +y y y y From 8e860d27a2cf4cf0f477e42975c75cf4bc0849b2 Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Wed, 10 Nov 2021 13:15:44 -0500 Subject: [PATCH 2/6] install php before caddy now to determine php version --- scripts/install_services.sh | 3 ++- scripts/update_services.sh | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/install_services.sh b/scripts/install_services.sh index 7d7609e..6977034 100755 --- a/scripts/install_services.sh +++ b/scripts/install_services.sh @@ -211,6 +211,7 @@ install_Caddyfile() { fi HASHWORD=$(caddy hash-password -plaintext ${CADDY_PWD}) php_version="$(awk -F. '{print $2}' <(ls -l $(which /etc/alternatives/php)))" + echo "php_version=${php_version}" cat << EOF > /etc/caddy/Caddyfile http://localhost http://birdnetpi.local ${BIRDNETPI_URL} { root * ${EXTRACTED} @@ -478,6 +479,7 @@ install_selected_services() { install_recording_service fi + install_php install_caddy install_Caddyfile update_etc_hosts @@ -485,7 +487,6 @@ install_selected_services() { install_gotty_logs install_sox install_mariadb - install_php install_spectrogram_service install_edit_birdnet_conf install_pushed_notifications diff --git a/scripts/update_services.sh b/scripts/update_services.sh index 48695b3..e9698ae 100755 --- a/scripts/update_services.sh +++ b/scripts/update_services.sh @@ -350,15 +350,15 @@ install_sox() { } install_php() { - if ! which php &> /dev/null || ! which php-fpm7.3 || ! apt list --installed | grep php-xml;then + if ! which php &> /dev/null || ! which php-fpm || ! apt list --installed | grep php-xml;then echo "Installing PHP modules" apt -qq update - apt install -qqy php php-fpm php7.3-mysql php-xml + apt install -qqy php php-fpm php-mysql php-xml else echo "PHP and PHP-FPM installed" fi 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/*/fpm/pool.d/www.conf echo "Adding Caddy sudoers rule" cat << EOF > /etc/sudoers.d/010_caddy-nopasswd caddy ALL=(ALL) NOPASSWD: ALL @@ -474,6 +474,7 @@ install_selected_services() { install_recording_service fi + install_php install_caddy install_Caddyfile update_etc_hosts @@ -481,7 +482,6 @@ install_selected_services() { install_gotty_logs install_sox install_mariadb - install_php install_spectrogram_service install_edit_birdnet_conf install_pushed_notifications From 9b2aa502065942de7e3bc5aaaf32bb48f1df80e3 Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Wed, 10 Nov 2021 13:23:57 -0500 Subject: [PATCH 3/6] updating for new mariadb version --- scripts/update_db_pwd.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/update_db_pwd.sh b/scripts/update_db_pwd.sh index eba6dd0..dae2656 100755 --- a/scripts/update_db_pwd.sh +++ b/scripts/update_db_pwd.sh @@ -3,10 +3,7 @@ source /etc/birdnet/birdnet.conf sudo mysql -e " - UPDATE mysql.user - SET Password=PASSWORD('${DB_PWD}') - WHERE USER='birder' - AND Host='localhost'; + SET PASSWORD FOR 'birder'@'localhost' = PASSWORD('${DB_PWD}'); FLUSH PRIVILEGES"; git -C /home/pi/BirdNET-Pi checkout -f analyze.py git -C /home/pi/BirdNET-Pi checkout -f scripts/viewdb.php From a1d2a05e563bc1cf89d793a98ebc9924c9c18c3f Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Wed, 10 Nov 2021 13:26:50 -0500 Subject: [PATCH 4/6] updating update_services to match install_services --- scripts/install_services.sh | 3 +-- scripts/update_services.sh | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install_services.sh b/scripts/install_services.sh index 6977034..e340028 100755 --- a/scripts/install_services.sh +++ b/scripts/install_services.sh @@ -209,9 +209,8 @@ install_Caddyfile() { if [ -f /etc/caddy/Caddyfile ];then cp /etc/caddy/Caddyfile{,.original} fi - HASHWORD=$(caddy hash-password -plaintext ${CADDY_PWD}) php_version="$(awk -F. '{print $2}' <(ls -l $(which /etc/alternatives/php)))" - echo "php_version=${php_version}" + HASHWORD=$(caddy hash-password -plaintext ${CADDY_PWD}) cat << EOF > /etc/caddy/Caddyfile http://localhost http://birdnetpi.local ${BIRDNETPI_URL} { root * ${EXTRACTED} diff --git a/scripts/update_services.sh b/scripts/update_services.sh index e9698ae..b20b7fd 100755 --- a/scripts/update_services.sh +++ b/scripts/update_services.sh @@ -207,6 +207,7 @@ install_Caddyfile() { if [ -f /etc/caddy/Caddyfile ];then cp /etc/caddy/Caddyfile{,.original} fi + php_version="$(awk -F. '{print $2}' <(ls -l $(which /etc/alternatives/php)))" HASHWORD=$(caddy hash-password -plaintext ${CADDY_PWD}) cat << EOF > /etc/caddy/Caddyfile http://localhost http://birdnetpi.local ${BIRDNETPI_URL} { @@ -225,7 +226,7 @@ http://localhost http://birdnetpi.local ${BIRDNETPI_URL} { birdnet ${HASHWORD} } reverse_proxy /stream localhost:8000 - php_fastcgi unix//run/php/php7.3-fpm.sock + php_fastcgi unix//run/php/php7.${php_version}-fpm.sock } EOF if [ ! -z ${EXTRACTIONLOG_URL} ];then From dede5e97af7106ced55e289ea8240c8e8a209fa4 Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Wed, 10 Nov 2021 14:02:26 -0500 Subject: [PATCH 5/6] adusting for bullseye mariadb versions --- Birders_Guide_Installer.sh | 2 +- scripts/{createdb.sh => createdb_bullseye.sh} | 0 scripts/createdb_buster.sh | 44 +++++++++++++++++++ scripts/install_config.sh | 3 -- scripts/install_services.sh | 7 ++- scripts/rewrite_config.sh | 5 --- scripts/update_db_pwd_bullseye.sh | 11 +++++ scripts/update_db_pwd_buster.sh | 14 ++++++ scripts/update_services.sh | 7 ++- scripts/write_config.sh | 1 - 10 files changed, 82 insertions(+), 12 deletions(-) rename scripts/{createdb.sh => createdb_bullseye.sh} (100%) create mode 100755 scripts/createdb_buster.sh create mode 100755 scripts/update_db_pwd_bullseye.sh create mode 100755 scripts/update_db_pwd_buster.sh diff --git a/Birders_Guide_Installer.sh b/Birders_Guide_Installer.sh index 2ef92b5..45362df 100755 --- a/Birders_Guide_Installer.sh +++ b/Birders_Guide_Installer.sh @@ -51,7 +51,7 @@ stage_2() { fi source ${my_dir}/Birders_Guide_Installer_Configuration.txt - if [ -z ${LATITUDE} ] || [ -z ${LONGITUDE} ] || [ -z ${CADDY_PWD} ] || [ -z ${ICE_PWD} ] || [ -z ${DB_PWD} ] || [ -z ${DB_ROOT_PWD} ];then + if [ -z ${LATITUDE} ] || [ -z ${LONGITUDE} ] || [ -z ${CADDY_PWD} ] || [ -z ${ICE_PWD} ] || [ -z ${DB_PWD} ];then echo echo "Follow the instructions to fill out the LATITUDE and LONGITUDE variables and set the passwords for the live audio stream. Save the file after editing diff --git a/scripts/createdb.sh b/scripts/createdb_bullseye.sh similarity index 100% rename from scripts/createdb.sh rename to scripts/createdb_bullseye.sh diff --git a/scripts/createdb_buster.sh b/scripts/createdb_buster.sh new file mode 100755 index 0000000..8f18992 --- /dev/null +++ b/scripts/createdb_buster.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# This script performs the mysql_secure_installation +# Creates the birds database +# Creates the detections table +# Creates the birder user and grants them appropriate +# permissions +# If using this script to re-initialize (DROP then CREATE) +# the DB, be sure to run this as root or with sudo +source /etc/birdnet/birdnet.conf +DB_ROOT_PWD=staggerwontonpurporting +mysql_secure_installation << EOF + +y +${DB_ROOT_PWD} +${DB_ROOT_PWD} +y +y +y +EOF + +mysql << EOF +DROP DATABASE IF EXISTS birds; +CREATE DATABASE IF NOT EXISTS birds; + +USE birds; + +CREATE TABLE IF NOT EXISTS detections ( + Date DATE, + Time TIME, + Sci_Name VARCHAR(100) NOT NULL, + Com_Name VARCHAR(100) NOT NULL, + Confidence FLOAT, + Lat FLOAT, + Lon FLOAT, + Cutoff FLOAT, + Week INT, + Sens FLOAT, + Overlap FLOAT); +GRANT ALL ON birds.* TO 'birder'@'localhost' IDENTIFIED BY '${DB_PWD}' WITH GRANT OPTION; +FLUSH PRIVILEGES; +exit +EOF +sed -i "s/databasepassword/${DB_PWD}/g" /home/pi/BirdNET-Pi/analyze.py +sed -i "s/databasepassword/${DB_PWD}/g" /home/pi/BirdNET-Pi/scripts/viewdb.php diff --git a/scripts/install_config.sh b/scripts/install_config.sh index e435af7..6623923 100755 --- a/scripts/install_config.sh +++ b/scripts/install_config.sh @@ -103,8 +103,6 @@ get_DB_PWDS() { if [ ! -z ${DB_PWD} ];then read -p "Please set a password for your database: " DB_PWD echo - read -p "Please set a root password for the database: " DB_ROOT_PWD - echo fi } @@ -376,7 +374,6 @@ RECORDING_LENGTH= EXTRACTION_LENGTH= DB_PWD=${DB_PWD} -DB_ROOT_PWD=${DB_ROOT_PWD} LAST_RUN=$(dirname ${my_dir})/lastrun.txt THIS_RUN=$(dirname ${my_dir})/thisrun.txt diff --git a/scripts/install_services.sh b/scripts/install_services.sh index e340028..c6a7b36 100755 --- a/scripts/install_services.sh +++ b/scripts/install_services.sh @@ -34,7 +34,12 @@ install_mariadb() { echo "MariaDB Installed" fi echo "Initializing the database" - ${my_dir}/createdb.sh + source /etc/os-release + if [[ "${VERSION_CODENAME}" == "buster" ]];then + ${my_dir}/createdb_buster.sh + elif [[ "${VERSION_CODENAME}" == "bullseye" ]];then + ${my_dir}/createdb_bullseye.sh + fi } install_birdnet_analysis() { diff --git a/scripts/rewrite_config.sh b/scripts/rewrite_config.sh index 93ed90d..38f59f9 100755 --- a/scripts/rewrite_config.sh +++ b/scripts/rewrite_config.sh @@ -24,11 +24,6 @@ sed -i s/'^DB_PWD=.*'/"DB_PWD=${db_pwd}"/g ${birdnet_conf} ${birdnetpi_dir}/scripts/update_db_pwd.sh fi -if ! [ -z ${db_root_pwd} ];then - exit 1 #for now -sed -i s/'^DB_ROOT_PWD=.*'/"DB_ROOT_PWD=${db_root_pwd}"/g ${birdnet_conf} -fi - if ! [ -z ${birdnetpi_url} ];then sed -i s/'^BIRDNETPI_URL=.*'/"BIRDNETPI_URL=${birdnetpi_url/\/\//\\\/\\\/}"/g ${birdnet_conf} sed -i s/'^EXTRACTIONLOG_URL=.*'/"EXTRACTIONLOG_URL=${extractionlog_url/\/\//\\\/\\\/}"/g ${birdnet_conf} diff --git a/scripts/update_db_pwd_bullseye.sh b/scripts/update_db_pwd_bullseye.sh new file mode 100755 index 0000000..dae2656 --- /dev/null +++ b/scripts/update_db_pwd_bullseye.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Update database password +source /etc/birdnet/birdnet.conf + +sudo mysql -e " + SET PASSWORD FOR 'birder'@'localhost' = PASSWORD('${DB_PWD}'); + FLUSH PRIVILEGES"; +git -C /home/pi/BirdNET-Pi checkout -f analyze.py +git -C /home/pi/BirdNET-Pi checkout -f scripts/viewdb.php +sed -i "s/databasepassword/${DB_PWD}/g" /home/pi/BirdNET-Pi/analyze.py +sed -i "s/databasepassword/${DB_PWD}/g" /home/pi/BirdNET-Pi/scripts/viewdb.php diff --git a/scripts/update_db_pwd_buster.sh b/scripts/update_db_pwd_buster.sh new file mode 100755 index 0000000..eba6dd0 --- /dev/null +++ b/scripts/update_db_pwd_buster.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Update database password +source /etc/birdnet/birdnet.conf + +sudo mysql -e " + UPDATE mysql.user + SET Password=PASSWORD('${DB_PWD}') + WHERE USER='birder' + AND Host='localhost'; + FLUSH PRIVILEGES"; +git -C /home/pi/BirdNET-Pi checkout -f analyze.py +git -C /home/pi/BirdNET-Pi checkout -f scripts/viewdb.php +sed -i "s/databasepassword/${DB_PWD}/g" /home/pi/BirdNET-Pi/analyze.py +sed -i "s/databasepassword/${DB_PWD}/g" /home/pi/BirdNET-Pi/scripts/viewdb.php diff --git a/scripts/update_services.sh b/scripts/update_services.sh index b20b7fd..5f0ecd1 100755 --- a/scripts/update_services.sh +++ b/scripts/update_services.sh @@ -33,7 +33,12 @@ install_mariadb() { apt -qqy install mariadb-server echo "MariaDB Installed" fi - ${my_dir}/update_db_pwd.sh + source /etc/os-release + if [[ "${VERSION_CODENAME}" == "buster" ]];then + ${my_dir}/update_db_pwd_buster.sh + elif [[ "${VERSION_CODENAME}" == "bullseye" ]];then + ${my_dir}/update_db_pwd_bullseye.sh + fi } install_birdnet_analysis() { diff --git a/scripts/write_config.sh b/scripts/write_config.sh index 424a753..45ba6f8 100755 --- a/scripts/write_config.sh +++ b/scripts/write_config.sh @@ -7,7 +7,6 @@ sed -i s/'^LONGITUDE=$'/"LONGITUDE=${new_lon}"/g ${birders_conf} sed -i s/'^CADDY_PWD=$'/"CADDY_PWD=${caddy_pwd}"/g ${birders_conf} sed -i s/'^ICE_PWD=$'/"ICE_PWD=${ice_pwd}"/g ${birders_conf} sed -i s/'^DB_PWD=$'/"DB_PWD=${db_pwd}"/g ${birders_conf} -sed -i s/'^DB_ROOT_PWD=$'/"DB_ROOT_PWD=${db_root_pwd}"/g ${birders_conf} sed -i s/'^BIRDNETPI_URL=$'/"BIRDNETPI_URL=${birdnetpi_url/\/\//\\\/\\\/}"/g ${birders_conf} sed -i s/'^EXTRACTIONLOG_URL=$'/"EXTRACTIONLOG_URL=${extractionlog_url/\/\//\\\/\\\/}"/g ${birders_conf} sed -i s/'^BIRDNETLOG_URL=$'/"BIRDNETLOG_URL=${birdnetlog_url/\/\//\\\/\\\/}"/g ${birders_conf} From 5b939e308e0afff7235d8a5c34fbaea8de28923f Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Wed, 10 Nov 2021 15:38:49 -0500 Subject: [PATCH 6/6] consistent birdnet.conf generation --- scripts/install_config.sh | 185 ++++++++++++++++++-------------------- 1 file changed, 86 insertions(+), 99 deletions(-) diff --git a/scripts/install_config.sh b/scripts/install_config.sh index 6623923..884c7f2 100755 --- a/scripts/install_config.sh +++ b/scripts/install_config.sh @@ -172,87 +172,53 @@ configure() { install_birdnet_conf() { cat << EOF > $(dirname ${my_dir})/birdnet.conf ################################################################################ -# Configuration settings for BirdNET as a service # +# Configuration settings for BirdNET-Pi # ################################################################################ -INSTALL_DATE="$(date "+%D")" -#___________The four variables below are the only that are required.___________# -## BIRDNET_USER should be the non-root user systemd should use to execute each -## service. +############ CHANGE THE LATITUDE AND LONGITUDE TO STATIC VALUES ################ -BIRDNET_USER=${USER} + +## LATITUDE and LONGITUDE are self-explanatroy. Find them easily at +## maps.google.com. +## Example: these coordinates would indicate the Eiffel Tower in Paris, France. +## LATITUDE=48.858 +## LONGITUDE=2.294 + +## These are input as shell substitutions so that this will work out of the box. +## It guesses your latitude and longitude based off of your network information. +## THESE SHOULD BE CHANGED TO STATIC NUMBERS!!!! +LATITUDE=${LATITUDE} +LONGITUDE=${LONGITUDE} ## RECS_DIR is the location birdnet_analysis.service will look for the data-set ## it needs to analyze. Be sure this directory is readable and writable for ## the BIRDNET_USER. If you are going to be accessing a remote data-set, you ## still need to set this, as this will be where the remote directory gets -## mounted locally. See REMOTE_RECS_DIR below for mounting remote data-sets. +## mounted locally. RECS_DIR=${RECS_DIR} -## LATITUDE and LONGITUDE are self-explanatroy. Find them easily at -## maps.google.com. Only go to the thousanths place for these variables -## Example: these coordinates would indicate the Eiffel Tower in Paris, France. -## LATITUDE=48.858 -## LONGITUDE=2.294 - -LATITUDE=${LATITUDE} -LONGITUDE=${LONGITUDE} - -################################################################################ -#------------------------------ Extraction Service ---------------------------# - -# Keep this EMPTY if you do not want this device to perform the extractions # - -## DO_EXTRACTIONS is simply a setting for enabling the extraction.service. -## Set this to Y or y to enable extractions. - -DO_EXTRACTIONS=${DO_EXTRACTIONS} - -################################################################################ -#----------------------------- Recording Service ----------------------------# -#____________________The variable below can be set to enable __________________# -#________________________the birdnet_recording.service ________________________# - -# Keep this EMPTY if you do not want this device to perform the recording. # - -## DO_RECORDING is simply a setting for enabling the 24/7 -## birdnet_recording.service. -## Set this to Y or y to enable recording. - -DO_RECORDING=${DO_RECORDING} - -################################################################################ -#----------------------- Web-hosting/Caddy File-server -----------------------# -#________The four variables below can be set to enable internet access_________# -#____________to your data,(e.g., extractions, raw data, live___________________# -#______________audio stream, BirdNET.selection.txt files)______________________# - -# Leave these EMPTY if you do not want to enable web access # - -## BIRDNETPI_URL is the URL where the extractions, data-set, and live-stream -## will be web-hosted. If you do not own a domain, or would just prefer to keep -## BirdNET-Pi on your local network, you can set this to http://localhost. -## Setting this (even to http://localhost) will also allow you to enable the -## GoTTY web logging features below. - -BIRDNETPI_URL=${BIRDNETPI_URL} -EXTRACTIONLOG_URL=${EXTRACTIONLOG_URL} -BIRDNETLOG_URL=${BIRDNETLOG_URL} +#----------------------- Web Interface User Password ------------------------# +#____________________The variable below sets the 'birdnet'_____________________# +#___________________user password for the live audio stream,___________________# +#_________________web tools, system info, and processed files__________________# ## CADDY_PWD is the plaintext password (that will be hashed) and used to access -## the "Processed" directory and live audio stream. This MUST be set if you -## choose to enable this feature. +## certain parts of the web interface CADDY_PWD=${CADDY_PWD} -################################################################################ +#------------------------- MariaDB User Passwords ---------------------------# +#_____________The variable below sets the password for the_____________________# +#_______________________'birder' user on the MariaDB___________________________# + +## DB_PWD is for the 'birder' user +DB_PWD=${DB_PWD} + #------------------------- Live Audio Stream --------------------------------# #_____________The variable below configures/enables the live___________________# #_____________________________audio stream.____________________________________# -# Keep this EMPTY if you do not wish to enable the live stream # -# or if this device is not doing the recording # ## ICE_PWD is the password that icecast2 will use to authenticate ffmpeg as a ## trusted source for the stream. You will never need to enter this manually @@ -260,7 +226,21 @@ CADDY_PWD=${CADDY_PWD} ICE_PWD=${ICE_PWD} -################################################################################ +#----------------------- Web-hosting/Caddy File-server -----------------------# +#________The four variables below can be set to enable internet access_________# +#____________to your data,(e.g., extractions, raw data, live___________________# +#______________audio stream, BirdNET.selection.txt files)______________________# + + +## BIRDNETPI_URL is the URL where the extractions, data-set, and live-stream +## will be web-hosted. If you do not own a domain, or would just prefer to keep +## the BirdNET-Pi on your local network, keep this EMPTY. + +BIRDNETPI_URL=${BIRDNETPI_URL} +EXTRACTIONLOG_URL${EXTRACTIONLOG_URL} +BIRDNETLOG_URL=${BIRDNETLOG_URL} + + #------------------- Mobile Notifications via Pushed.co ---------------------# #____________The two variables below enable mobile notifications_______________# #_____________See https://pushed.co/quick-start-guide to get___________________# @@ -274,6 +254,9 @@ PUSHED_APP_KEY=${PUSHED_APP_KEY} PUSHED_APP_SECRET=${PUSHED_APP_SECRET} ################################################################################ +#-------------------------------- Defaults ----------------------------------# +################################################################################ + #------------------------------- NoMachine ----------------------------------# #_____________The variable below can be set include NoMachine__________________# #_________________remote desktop software to be installed._____________________# @@ -284,14 +267,27 @@ PUSHED_APP_SECRET=${PUSHED_APP_SECRET} ## NoMachine alongside the BirdNET-Pi for remote desktop access. This in- ## staller assumes personal use. Please reference the LICENSE file included ## in this repository for more information. -## Set this to Y or y to install NoMachine alongside the BirdNET-Pi +## Set this to Y or y to install NoMachine alongside the BirdNET-Lite INSTALL_NOMACHINE=${INSTALL_NOMACHINE} -################################################################################ -#-------------------------------- Defaults ----------------------------------# -#________The seven variables below are default settings that you (probably)____# -#__________________don't need to change at all, but can._______________________# +# +#------------------------------ Extraction Service ---------------------------# + +## DO_EXTRACTIONS is simply a setting for enabling the extraction.service. +## Set this to Y or y to enable extractions. + +DO_EXTRACTIONS=${DO_EXTRACTIONS} + +#----------------------------- Recording Service ----------------------------# +#____________________The variable below can be set to enable __________________# +#________________________the birdnet_recording.service ________________________# + +## DO_RECORDING is simply a setting for enabling the 24/7 +## birdnet_recording.service. +## Set this to Y or y to enable recording. + +DO_RECORDING=${DO_RECORDING} ## REC_CARD is the sound card you would want the birdnet_recording.service to ## use. This setting is irrelevant if you are not planning on doing data @@ -309,11 +305,11 @@ REC_CARD=${REC_CARD} ## after extractions have been made from them. This includes both WAVE and ## BirdNET.selection.txt files. -PROCESSED=${RECS_DIR}/Processed +PROCESSED=${PROCESSED} ## EXTRACTED is the directory where the extracted audio selections are moved. -EXTRACTED=${RECS_DIR}/Extracted +EXTRACTED=${EXTRACTED} ## IDFILE is the file that keeps a complete list of every spececies that ## BirdNET has identified from your data-set. It is persistent across @@ -324,70 +320,61 @@ EXTRACTED=${RECS_DIR}/Extracted ## change this variable between data-sets to preserve records of disparate ## data-sets according to name. -IDFILE=${HOME}/BirdNET-Pi/IdentifiedSoFar.txt +IDFILE=${IDFILE} ## OVERLAP is the value in seconds which BirdNET should use when analyzing ## the data. The values must be between 0.0-2.9. -OVERLAP=0.0 +OVERLAP=${OVERLAP} ## CONFIDENCE is the minimum confidence level from 0.0-1.0 BirdNET's analysis ## should reach before creating an entry in the BirdNET.selection.txt file. ## Don't set this to 1.0 or you won't have any results. -CONFIDENCE=0.7 +CONFIDENCE=${CONFIDENCE} ## SENSITIVITY is the detection sensitivity from 0.5-1.5. -SENSITIVITY=1.25 - -################################################################################ -#------------------------------ Auto-Generated ------------------------------# -#_____________________The variables below are auto-generated___________________# -#______________________________during installation_____________________________# +SENSITIVITY=${SENSITIVITY} ## CHANNELS holds the variabel that corresponds to the number of channels the ## sound card supports. CHANNELS=${CHANNELS} -# Don't touch the variables below - -## SYSTEMD_MOUNT is created from the RECS_DIR variable to comply with systemd -## mount naming requirements. - -SYSTEMD_MOUNT=$(echo ${RECS_DIR#/} | tr / -).mount - ## VENV is the virtual environment where the the BirdNET python build is found, ## i.e, VENV is the virtual environment miniforge built for BirdNET. -VENV=$(dirname ${my_dir})/birdnet +VENV=/home/pi/BirdNET-Pi/birdnet -################################################################################ -#---------------------------------- Testing -----------------------------------# -#_____________These variables are for testing. Please don't touch______________# -#_______________them if you are not testing these features.____________________# +## RECORDING_LENGTH sets the length of the recording that BirdNET-Lite will analyze. +RECORDING_LENGTH=${RECORDING_LENGTH} +## EXTRACTION_LENGTH sets the length of the audio extractions that will be made +## from each BirdNET-Lite detection. +EXTRACTION_LENGTH=${EXTRACTION_LENGTH} -RECORDING_LENGTH= +## BIRDNET_USER should be the non-root user systemd should use to execute each +## service. -EXTRACTION_LENGTH= +BIRDNET_USER=pi -DB_PWD=${DB_PWD} - -LAST_RUN=$(dirname ${my_dir})/lastrun.txt -THIS_RUN=$(dirname ${my_dir})/thisrun.txt +## These are just for debugging +LAST_RUN=${LAST_RUN} +THIS_RUN=${THIS_RUN} EOF - [ -d /etc/birdnet ] || sudo mkdir /etc/birdnet - sudo ln -sf $(dirname ${my_dir})/birdnet.conf /etc/birdnet/birdnet.conf } # Checks for a birdnet.conf file in the BirdNET-Pi directory for a # non-interactive installation. Otherwise,the installation is interactive. if [ -f ${BIRDNET_CONF} ];then source ${BIRDNET_CONF} - install_birdnet_conf + #install_birdnet_conf + [ -d /etc/birdnet ] || sudo mkdir /etc/birdnet + sudo ln -sf $(dirname ${my_dir})/birdnet.conf /etc/birdnet/birdnet.conf else configure install_birdnet_conf + [ -d /etc/birdnet ] || sudo mkdir /etc/birdnet + sudo ln -sf $(dirname ${my_dir})/birdnet.conf /etc/birdnet/birdnet.conf fi