From 7a8aecd64ad2e7b7fb845cf328879a39db0af246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Sol=C3=ADs?= Date: Sat, 1 Feb 2025 23:12:02 +0000 Subject: [PATCH] feat: Make output more clear; add support for MariaDB and MySQL --- LICENSE | 0 README.md | 0 friendica-find-missing-servers.sh | 36 ++++++++++++++++++++----------- 3 files changed, 23 insertions(+), 13 deletions(-) mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/friendica-find-missing-servers.sh b/friendica-find-missing-servers.sh index ec87583..fe58b61 100755 --- a/friendica-find-missing-servers.sh +++ b/friendica-find-missing-servers.sh @@ -13,28 +13,38 @@ loop_1() { } loop_2() { echo "Finding users for ${b}" - mariadb "${db}" -N -B -q -e "select \`id\`, \`name\` from contact c where c.\`id\` not in (select \`contact-id\` from group_member) and (c.baseurl = \"${b}\" or c.url = \"${b}\")" | sudo tee -a "${idsdownfile}" #&> /dev/null + "${dbengine}" "${db}" -N -B -q -e "select \`id\`, \`name\` from contact c where c.\`id\` not in (select \`contact-id\` from group_member) and (c.baseurl = \"${b}\" or c.url = \"${b}\")" | sudo tee -a "${idsdownfile}" #&> /dev/null } loop_3() { - echo "Deleting user ${lineb} - ${username}" - mariadb "${db}" -N -B -q -e "delete from \`post-thread\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}" - mariadb "${db}" -N -B -q -e "delete from \`post-thread-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}" - mariadb "${db}" -N -B -q -e "delete from \`post-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}" - mariadb "${db}" -N -B -q -e "delete from \`post-tag\` where cid = ${lineb}" - mariadb "${db}" -N -B -q -e "delete from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}" - mariadb "${db}" -N -B -q -e "delete from \`photo\` where \`contact-id\` = ${lineb}" - mariadb "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}" + baseurltrimmed=$(echo "${baseurl}" | sed -e "s/http[s]*:\/\///g") + echo "Deleting user ${lineb} - ${nick}@${baseurltrimmed}" + "${dbengine}" "${db}" -N -B -q -e "delete from \`post-thread\` 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-tag\` where cid = ${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 \`photo\` where \`contact-id\` = ${lineb}" + "${dbengine}" "${db}" -N -B -q -e "delete from \`contact\` where \`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 $(type mariadb) && -n $(type date) ]] +if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(type date) ]] then date if [[ ! -f "${tmpfile}" ]] then echo "Listing sites" - sites=($(mariadb "${db}" -N -B -q -e "select distinct baseurl from contact" | sort -n | uniq )) + sites=($("${dbengine}" "${db}" -N -B -q -e "select distinct baseurl from contact" | sort -n | uniq )) echo "Amount of unique sites: ${#sites[@]}" for a in "${sites[@]}" do @@ -66,10 +76,10 @@ then fi #idsdown=() #echo "$idsdownfile" | sort | uniq > "$idsdownfile" - while read -r lineb username; do + while read -r lineb nick baseurl; do #idsdown+=($lineb) #The community no longer exists, delete - loop_3 "${lineb}" & + loop_3 "${lineb}" "${nick}" "${baseurl}" & if [[ $(jobs -r -p | wc -l) -ge $(expr $(getconf _NPROCESSORS_ONLN)/2) ]] then wait -n