From 078dd7f3350170f31c8d44c4e8783cba417d5630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Sol=C3=ADs?= Date: Wed, 12 Feb 2025 21:27:45 +0000 Subject: [PATCH] feat: Detect MariaDB vs MySQL automatically --- friendica-clean-database.sh | 16 ++++++++++++++-- friendica-delete-old-users.sh | 18 ++++++++++-------- friendica-remove-old-photos-parallel.sh | 14 +++++++++++--- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/friendica-clean-database.sh b/friendica-clean-database.sh index 2aa808c..f622cf8 100755 --- a/friendica-clean-database.sh +++ b/friendica-clean-database.sh @@ -4,9 +4,21 @@ limit=1000 folder=/var/www/friendica user=friendica phpversion=php8.2 -dbengine=mariadb +dbengine="" +if [[ -n $(type mariadb) ]]; then + dbengine="mariadb" +elif [[ -n $(type mysql) ]]; then + dbengine="mysql" +else + exit +fi db=friendica -dboptimizer=mariadb-optimize +dboptimizer="" +if [[ -n $(type mariadb-optimize) ]]; then + dboptimizer="mariadb-optimize" +elif [[ -n $(type mysqloptimize) ]]; then + dbengine="mysqloptimize" +fi intense_optimizations=${1:-"0"} bash -c "cd ${folder} && sudo -u ${user} ${phpversion} bin/console.php maintenance 1 \"Database maintenance\"" #&> /dev/null diff --git a/friendica-delete-old-users.sh b/friendica-delete-old-users.sh index 70ddeda..52daa1d 100755 --- a/friendica-delete-old-users.sh +++ b/friendica-delete-old-users.sh @@ -1,4 +1,13 @@ #!/bin/bash +#Check for mariadb vs. mysql +dbengine="" +if [[ -n $(type mariadb) ]]; then + dbengine="mariadb" +elif [[ -n $(type mysql) ]]; then + dbengine="mysql" +else + exit +fi db="friendica" url=friendica.example.net avatarfolder=/var/www/friendica/avatar @@ -23,21 +32,14 @@ loop() { "${dbengine}" "${db}" -N -B -q -e "delete from \`post-thread-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}" "${dbengine}" "${db}" -N -B -q -e "delete from \`post-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}" "${dbengine}" "${db}" -N -B -q -e "delete from \`post-tag\` where cid = ${lineb}" + "${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post (select \`uri-id\` from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete p.* from \`post-content\` p inner join \`tmp_post\` t where p.\`uri-id\` = t.\`uri-id\`;" "${dbengine}" "${db}" -N -B -q -e "delete from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}" - "${dbengine}" "${db}" -N -B -q -e "delete from \`post-content\` where \`uri-id\` = ${lineb}" "${dbengine}" "${db}" -N -B -q -e "delete from \`photo\` where \`contact-id\` = ${lineb}" "${dbengine}" "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}" "${dbengine}" "${db}" -N -B -q -e "delete from \`apcontact\` where \`uri-id\` = ${lineb}" "${dbengine}" "${db}" -N -B -q -e "delete from \`diaspora-contact\` where \`uri-id\` = ${lineb}" } -#Check for mariadb vs. mysql -dbengine="" -if [[ -n $(type mariadb) ]]; then - dbengine="mariadb" -elif [[ -n $(type mysql) ]]; then - dbengine="mysql" -fi #Check if our dependencies are installed if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(type date) ]]; then date diff --git a/friendica-remove-old-photos-parallel.sh b/friendica-remove-old-photos-parallel.sh index dfb7d39..05bc27a 100755 --- a/friendica-remove-old-photos-parallel.sh +++ b/friendica-remove-old-photos-parallel.sh @@ -1,6 +1,14 @@ #!/bin/bash IFS=" " +dbengine="" +if [[ -n $(type mariadb) ]]; then + dbengine="mariadb" +elif [[ -n $(type mysql) ]]; then + dbengine="mysql" +else + exit +fi #Set your parameters here url=friendica.example.net db=friendica @@ -10,7 +18,7 @@ loop() { #Parse each file in folder folderescaped=${folder////\\/} ky=$(echo "${y}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g") - f=$(mariadb "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1") + f=$("${dbengine}" "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1") if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then rm -rvf "${y}" & if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then @@ -28,7 +36,7 @@ date #Go to the Friendica installation cd "${folderavatar}" || exit #indexlength=$((49 + ${#url})) -#mariadb "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))" +#"${dbengine}" "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))" n=0 d=0 while read -r x; do @@ -45,5 +53,5 @@ while read -r x; do done < <(find "${x}" -type f) fi done < <(find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d) -#mariadb "${db}" -e "alter table contact drop index photo_index" +#"${dbengine}" "${db}" -e "alter table contact drop index photo_index" date