feat: Detect MariaDB vs MySQL automatically

This commit is contained in:
Carlos Solís 2025-02-12 21:27:45 +00:00
parent a23f37dbd4
commit 078dd7f335
3 changed files with 35 additions and 13 deletions

View file

@ -4,9 +4,21 @@ limit=1000
folder=/var/www/friendica folder=/var/www/friendica
user=friendica user=friendica
phpversion=php8.2 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 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"} intense_optimizations=${1:-"0"}
bash -c "cd ${folder} && sudo -u ${user} ${phpversion} bin/console.php maintenance 1 \"Database maintenance\"" #&> /dev/null bash -c "cd ${folder} && sudo -u ${user} ${phpversion} bin/console.php maintenance 1 \"Database maintenance\"" #&> /dev/null

View file

@ -1,4 +1,13 @@
#!/bin/bash #!/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" db="friendica"
url=friendica.example.net url=friendica.example.net
avatarfolder=/var/www/friendica/avatar 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-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-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 "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\` 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 \`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 \`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 \`apcontact\` where \`uri-id\` = ${lineb}"
"${dbengine}" "${db}" -N -B -q -e "delete from \`diaspora-contact\` 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 #Check if our dependencies are installed
if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(type date) ]]; then if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(type date) ]]; then
date date

View file

@ -1,6 +1,14 @@
#!/bin/bash #!/bin/bash
IFS=" IFS="
" "
dbengine=""
if [[ -n $(type mariadb) ]]; then
dbengine="mariadb"
elif [[ -n $(type mysql) ]]; then
dbengine="mysql"
else
exit
fi
#Set your parameters here #Set your parameters here
url=friendica.example.net url=friendica.example.net
db=friendica db=friendica
@ -10,7 +18,7 @@ loop() {
#Parse each file in folder #Parse each file in folder
folderescaped=${folder////\\/} folderescaped=${folder////\\/}
ky=$(echo "${y}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g") 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 if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then
rm -rvf "${y}" & rm -rvf "${y}" &
if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then
@ -28,7 +36,7 @@ date
#Go to the Friendica installation #Go to the Friendica installation
cd "${folderavatar}" || exit cd "${folderavatar}" || exit
#indexlength=$((49 + ${#url})) #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 n=0
d=0 d=0
while read -r x; do while read -r x; do
@ -45,5 +53,5 @@ while read -r x; do
done < <(find "${x}" -type f) done < <(find "${x}" -type f)
fi fi
done < <(find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d) 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 date