From dede5e97af7106ced55e289ea8240c8e8a209fa4 Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Wed, 10 Nov 2021 14:02:26 -0500 Subject: [PATCH] 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}