chore: Clean with shfmt/shellcheck

This commit is contained in:
Carlos Solís 2025-02-05 14:59:57 +00:00
parent 255f98fd18
commit 39c4369f12
6 changed files with 286 additions and 413 deletions

View file

@ -1,225 +1,186 @@
#!/bin/bash #!/bin/bash
interval=7 interval=7
limit=1000 limit=1000
tmpfile=/tmp/fcb
dbengine=mariadb
db=friendica
touch /tmp/fcb touch "${tmpfile}"
echo "tmp_post_origin_deleted" echo "tmp_post_origin_deleted"
tmp_post_origin_deleted_q="${limit}" tmp_post_origin_deleted_q="${limit}"
tmp_post_origin_deleted_current_uri_id=0 tmp_post_origin_deleted_current_uri_id=0
until [[ "${tmp_post_origin_deleted_q}" -lt "${limit}" ]] until [[ "${tmp_post_origin_deleted_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_post_origin_deleted=$(sudo mariadb friendica -N -B -q -e \ tmp_post_origin_deleted=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`uri-id\`, \`uid\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`deleted\` AND \`edited\` < (CURDATE() - INTERVAL ${interval} DAY) \ "SELECT \`uri-id\`, \`uid\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`deleted\` AND \`edited\` < (CURDATE() - INTERVAL ${interval} DAY) \
AND ( \`uri-id\` > ${tmp_post_origin_deleted_current_uri_id} ) \ AND ( \`uri-id\` > ${tmp_post_origin_deleted_current_uri_id} ) \
ORDER BY \`uri-id\`, \`uid\` LIMIT ${limit}"); ORDER BY \`uri-id\`, \`uid\` LIMIT ${limit}")
tmp_post_origin_deleted_q=$(echo "${tmp_post_origin_deleted}" | grep -c '.') tmp_post_origin_deleted_q=$(echo "${tmp_post_origin_deleted}" | grep -c '.')
#echo "${tmp_post_origin_deleted_q}" #echo "${tmp_post_origin_deleted_q}"
if [[ "${tmp_post_origin_deleted_q}" -gt 0 ]] if [[ "${tmp_post_origin_deleted_q}" -gt 0 ]]; then
then echo "${tmp_post_origin_deleted}" | while read -r uri_id uid; do
echo "${tmp_post_origin_deleted}" | while read -r uri_id uid if [[ -n "${uri_id}" && -n "${uid}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${uri_id}" && -n "${uid}" ]] "DELETE FROM \`post-origin\` WHERE \`parent-uri-id\` = ${uri_id} AND \`uid\` = ${uid}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-origin\` WHERE \`parent-uri-id\` = ${uri_id} AND \`uid\` = ${uid}"
#echo "${uri_id} ${uid}" #echo "${uri_id} ${uid}"
echo "${uri_id}" > /tmp/fcb echo "${uri_id}" >"${tmpfile}"
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_post_origin_deleted}") && "${tmp_post_origin_deleted_current_uid}" -le $(tac $(echo "${tmp_post_origin_deleted}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_post_origin_deleted_current_uri_id=$(cat "${tmpfile}")
tmp_post_origin_deleted_current_uid=$(tac $(echo "${tmp_post_origin_deleted}") | grep -m 1 '.')
fi fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]] final_i=$(($(date +%s) - initial_i))
then echo "${tmp_post_origin_deleted_q} item(s) deleted until ${tmp_post_origin_deleted_current_uri_id} in ${final_i}s"
tmp_post_origin_deleted_current_uid=$(cat /tmp/fcb)
fi
echo "${tmp_post_origin_deleted_q} item(s) deleted until ${tmp_post_origin_deleted_current_uri_id} ${tmp_post_origin_deleted_current_uid}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_post_user_deleted" echo "tmp_post_user_deleted"
tmp_post_user_deleted_q="${limit}" tmp_post_user_deleted_q="${limit}"
tmp_post_user_deleted_current_uri_id=0 tmp_post_user_deleted_current_uri_id=0
until [[ "${tmp_post_user_deleted_q}" -lt "${limit}" ]] until [[ "${tmp_post_user_deleted_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_post_user_deleted=$(sudo mariadb friendica -N -B -q -e \ tmp_post_user_deleted=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`deleted\` AND \`edited\` < (CURDATE() - INTERVAL ${interval} DAY) \ "SELECT \`uri-id\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`deleted\` AND \`edited\` < (CURDATE() - INTERVAL ${interval} DAY) \
AND \`uri-id\` > ${tmp_post_user_deleted_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}"); AND \`uri-id\` > ${tmp_post_user_deleted_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}")
tmp_post_user_deleted_q=$(echo "${tmp_post_user_deleted}" | grep -c '.') tmp_post_user_deleted_q=$(echo "${tmp_post_user_deleted}" | grep -c '.')
#echo "${tmp_post_user_deleted_q}" #echo "${tmp_post_user_deleted_q}"
if [[ "${tmp_post_user_deleted_q}" -gt 0 ]] if [[ "${tmp_post_user_deleted_q}" -gt 0 ]]; then
then echo "${tmp_post_user_deleted}" | while read -r uri_id; do
echo "${tmp_post_user_deleted}" | while read -r uri_id if [[ -n "${uri_id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${uri_id}" ]] "DELETE FROM \`post-user\` WHERE \`uri-id\` = ${uri_id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-user\` WHERE \`uri-id\` = ${uri_id}"
#echo "${uri_id}" #echo "${uri_id}"
echo "${uri_id}" > /tmp/fcb echo "${uri_id}" >"${tmpfile}"
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_post_user_deleted}") && "${tmp_post_user_deleted_current_uri_id}" -lt $(tac $(echo "${tmp_post_user_deleted}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_post_user_deleted_current_uri_id=$(cat "${tmpfile}")
tmp_post_user_deleted_current_uri_id=$(tac $(echo "${tmp_post_user_deleted}") | grep -m 1 '.')
fi fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]] final_i=$(($(date +%s) - initial_i))
then echo "${tmp_post_user_deleted_q} item(s) deleted until ${tmp_post_user_deleted_current_uri_id} in ${final_i}s"
tmp_post_user_deleted_current_uri_id=$(cat /tmp/fcb)
fi
echo "${tmp_post_user_deleted_q} item(s) deleted until ${tmp_post_user_deleted_current_uri_id}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_post_uri_id_not_in_post_user" echo "tmp_post_uri_id_not_in_post_user"
tmp_post_uri_id_not_in_post_user_q="${limit}" tmp_post_uri_id_not_in_post_user_q="${limit}"
tmp_post_uri_id_not_in_post_user_current_uri_id=0 tmp_post_uri_id_not_in_post_user_current_uri_id=0
until [[ "${tmp_post_uri_id_not_in_post_user_q}" -lt "${limit}" ]] until [[ "${tmp_post_uri_id_not_in_post_user_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_post_uri_id_not_in_post_user=$(sudo mariadb friendica -N -B -q -e \ tmp_post_uri_id_not_in_post_user=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`uri-id\` FROM \`post\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) \ "SELECT \`uri-id\` FROM \`post\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) \
AND \`uri-id\` > ${tmp_post_uri_id_not_in_post_user_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}"); AND \`uri-id\` > ${tmp_post_uri_id_not_in_post_user_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}")
tmp_post_uri_id_not_in_post_user_q=$(echo "${tmp_post_uri_id_not_in_post_user}" | grep -c '.') tmp_post_uri_id_not_in_post_user_q=$(echo "${tmp_post_uri_id_not_in_post_user}" | grep -c '.')
#echo "${tmp_post_uri_id_not_in_post_user_q}" #echo "${tmp_post_uri_id_not_in_post_user_q}"
if [[ "${tmp_post_uri_id_not_in_post_user_q}" -gt 0 ]] if [[ "${tmp_post_uri_id_not_in_post_user_q}" -gt 0 ]]; then
then echo "${tmp_post_uri_id_not_in_post_user}" | while read -r uri_id; do
echo "${tmp_post_uri_id_not_in_post_user}" | while read -r uri_id if [[ -n "${uri_id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${uri_id}" ]] "DELETE FROM \`post\` WHERE \`uri-id\` = ${uri_id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post\` WHERE \`uri-id\` = ${uri_id}"
#echo "${uri_id}" #echo "${uri_id}"
echo "${uri_id}" > /tmp/fcb echo "${uri_id}" >"${tmpfile}"
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_post_uri_not_in_post_user}") && "${tmp_post_uri_id_not_in_post_user_current_uri_id}" -lt $(tac $(echo "${tmp_post_uri_id_not_in_post_user}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_post_uri_id_not_in_post_user_current_uri_id=$(cat "${tmpfile}")
tmp_post_uri_id_not_in_post_user_current_uri_id=$(tac $(echo "${tmp_post_uri_id_not_in_post_user}") | grep -m 1 '.')
fi fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]] final_i=$(($(date +%s) - initial_i))
then echo "${tmp_post_uri_id_not_in_post_user_q} item(s) deleted until ${tmp_post_uri_id_not_in_post_user_current_uri_id} in ${final_i}s"
tmp_post_uri_id_not_in_post_user_current_uri_id=$(cat /tmp/fcb)
fi
echo "${tmp_post_uri_id_not_in_post_user_q} item(s) deleted until ${tmp_post_uri_id_not_in_post_user_current_uri_id}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_post_content_uri_id_not_in_post_user" echo "tmp_post_content_uri_id_not_in_post_user"
tmp_post_content_uri_id_not_in_post_user_q="${limit}" tmp_post_content_uri_id_not_in_post_user_q="${limit}"
tmp_post_content_uri_id_not_in_post_user_current_uri_id=0 tmp_post_content_uri_id_not_in_post_user_current_uri_id=0
until [[ "${tmp_post_content_uri_id_not_in_post_user_q}" -lt "${limit}" ]] until [[ "${tmp_post_content_uri_id_not_in_post_user_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_post_content_uri_id_not_in_post_user=$(sudo mariadb friendica -N -B -q -e \ tmp_post_content_uri_id_not_in_post_user=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-content\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) \ "SELECT \`uri-id\` FROM \`post-content\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) \
AND \`uri-id\` > ${tmp_post_content_uri_id_not_in_post_user_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}"); AND \`uri-id\` > ${tmp_post_content_uri_id_not_in_post_user_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}")
tmp_post_content_uri_id_not_in_post_user_q=$(echo "${tmp_post_content_uri_id_not_in_post_user}" | grep -c '.') tmp_post_content_uri_id_not_in_post_user_q=$(echo "${tmp_post_content_uri_id_not_in_post_user}" | grep -c '.')
#echo "${tmp_post_content_uri_id_not_in_post_user_q}" #echo "${tmp_post_content_uri_id_not_in_post_user_q}"
if [[ "${tmp_post_content_uri_id_not_in_post_user_q}" -gt 0 ]] if [[ "${tmp_post_content_uri_id_not_in_post_user_q}" -gt 0 ]]; then
then echo "${tmp_post_content_uri_id_not_in_post_user}" | while read -r uri_id; do
echo "${tmp_post_content_uri_id_not_in_post_user}" | while read -r uri_id if [[ -n "${uri_id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${uri_id}" ]] "DELETE FROM \`post-content\` WHERE \`uri-id\` = ${uri_id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-content\` WHERE \`uri-id\` = ${uri_id}"
#echo "${uri_id}" #echo "${uri_id}"
echo "${uri_id}" > /tmp/fcb echo "${uri_id}" >"${tmpfile}"
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_post_content_uri_not_in_post_user}") && "${tmp_post_content_uri_id_not_in_post_user_current_uri_id}" -lt $(tac $(echo "${tmp_post_content_uri_id_not_in_post_user}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_post_content_uri_id_not_in_post_user_current_uri_id=$(cat "${tmpfile}")
tmp_post_content_uri_id_not_in_post_user_current_uri_id=$(tac $(echo "${tmp_post_content_uri_id_not_in_post_user}") | grep -m 1 '.')
fi fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]] final_i=$(($(date +%s) - initial_i))
then echo "${tmp_post_content_uri_id_not_in_post_user_q} item(s) deleted until ${tmp_post_content_uri_id_not_in_post_user_current_uri_id} in ${final_i}s"
tmp_post_content_uri_id_not_in_post_user_current_uri_id=$(cat /tmp/fcb)
fi
echo "${tmp_post_content_uri_id_not_in_post_user_q} item(s) deleted until ${tmp_post_content_uri_id_not_in_post_user_current_uri_id}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_post_thread_uri_id_not_in_post_user" echo "tmp_post_thread_uri_id_not_in_post_user"
tmp_post_thread_uri_id_not_in_post_user_q="${limit}" tmp_post_thread_uri_id_not_in_post_user_q="${limit}"
tmp_post_thread_uri_id_not_in_post_user_current_uri_id=0 tmp_post_thread_uri_id_not_in_post_user_current_uri_id=0
until [[ "${tmp_post_thread_uri_id_not_in_post_user_q}" -lt "${limit}" ]] until [[ "${tmp_post_thread_uri_id_not_in_post_user_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_post_thread_uri_id_not_in_post_user=$(sudo mariadb friendica -N -B -q -e \ tmp_post_thread_uri_id_not_in_post_user=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-thread\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) \ "SELECT \`uri-id\` FROM \`post-thread\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`) \
AND \`uri-id\` > ${tmp_post_thread_uri_id_not_in_post_user_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}"); AND \`uri-id\` > ${tmp_post_thread_uri_id_not_in_post_user_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}")
tmp_post_thread_uri_id_not_in_post_user_q=$(echo "${tmp_post_thread_uri_id_not_in_post_user}" | grep -c '.') tmp_post_thread_uri_id_not_in_post_user_q=$(echo "${tmp_post_thread_uri_id_not_in_post_user}" | grep -c '.')
#echo "${tmp_post_thread_uri_id_not_in_post_user_q}" #echo "${tmp_post_thread_uri_id_not_in_post_user_q}"
if [[ "${tmp_post_thread_uri_id_not_in_post_user_q}" -gt 0 ]] if [[ "${tmp_post_thread_uri_id_not_in_post_user_q}" -gt 0 ]]; then
then echo "${tmp_post_thread_uri_id_not_in_post_user}" | while read -r uri_id; do
echo "${tmp_post_thread_uri_id_not_in_post_user}" | while read -r uri_id if [[ -n "${uri_id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${uri_id}" ]] "DELETE FROM \`post-thread\` WHERE \`uri-id\` = ${uri_id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-thread\` WHERE \`uri-id\` = ${uri_id}"
#echo "${uri_id}" #echo "${uri_id}"
echo "${uri_id}" > /tmp/fcb echo "${uri_id}" >"${tmpfile}"
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_post_thread_uri_id_not_in_post_user}") && "${tmp_post_thread_uri_id_not_in_post_user_current_uri_id}" -lt $(tac $(echo "${tmp_post_thread_uri_id_not_in_post_user}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_post_thread_uri_id_not_in_post_user_current_uri_id=$(cat "${tmpfile}")
tmp_post_thread_uri_id_not_in_post_user_current_uri_id=$(tac $(echo "${tmp_post_thread_uri_id_not_in_post_user}") | grep -m 1 '.')
fi fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]] final_i=$(($(date +%s) - initial_i))
then echo "${tmp_post_thread_uri_id_not_in_post_user_q} item(s) deleted until ${tmp_post_thread_uri_id_not_in_post_user_current_uri_id} in ${final_i}s"
tmp_post_thread_uri_id_not_in_post_user_current_uri_id=$(cat /tmp/fcb)
fi
echo "${tmp_post_thread_uri_id_not_in_post_user_q} item(s) deleted until ${tmp_post_thread_uri_id_not_in_post_user_current_uri_id}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_post_user_uri_id_not_in_post" echo "tmp_post_user_uri_id_not_in_post"
tmp_post_user_uri_id_not_in_post_q="${limit}" tmp_post_user_uri_id_not_in_post_q="${limit}"
tmp_post_user_uri_id_not_in_post_current_uri_id=0 tmp_post_user_uri_id_not_in_post_current_uri_id=0
until [[ "${tmp_post_user_uri_id_not_in_post_q}" -lt "${limit}" ]] until [[ "${tmp_post_user_uri_id_not_in_post_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_post_user_uri_id_not_in_post=$(sudo mariadb friendica -N -B -q -e \ tmp_post_user_uri_id_not_in_post=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-user\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post\`) \ "SELECT \`uri-id\` FROM \`post-user\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post\`) \
AND \`uri-id\` > ${tmp_post_user_uri_id_not_in_post_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}"); AND \`uri-id\` > ${tmp_post_user_uri_id_not_in_post_current_uri_id} ORDER BY \`uri-id\` LIMIT ${limit}")
tmp_post_user_uri_id_not_in_post_q=$(echo "${tmp_post_user_uri_id_not_in_post}" | grep -c '.') tmp_post_user_uri_id_not_in_post_q=$(echo "${tmp_post_user_uri_id_not_in_post}" | grep -c '.')
#echo "${tmp_post_user_uri_id_not_in_post_q}" #echo "${tmp_post_user_uri_id_not_in_post_q}"
if [[ "${tmp_post_user_uri_id_not_in_post_q}" -gt 0 ]] if [[ "${tmp_post_user_uri_id_not_in_post_q}" -gt 0 ]]; then
then echo "${tmp_post_user_uri_id_not_in_post}" | while read -r uri_id; do
echo "${tmp_post_user_uri_id_not_in_post}" | while read -r uri_id if [[ -n "${uri_id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${uri_id}" ]] "DELETE FROM \`post-user\` WHERE \`uri-id\` = ${uri_id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-user\` WHERE \`uri-id\` = ${uri_id}"
#echo "${uri_id}" #echo "${uri_id}"
echo "${uri_id}" > /tmp/fcb echo "${uri_id}" >"${tmpfile}"
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_post_user_uri_id_not_in_post}") && "${tmp_post_user_uri_id_not_in_post_current_uri_id}" -lt $(tac $(echo "${tmp_post_user_uri_id_not_in_post}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_post_user_uri_id_not_in_post_current_uri_id=$(cat "${tmpfile}")
tmp_post_user_uri_id_not_in_post_current_uri_id=$(tac $(echo "${tmp_post_user_uri_id_not_in_post}") | grep -m 1 '.')
fi fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]] final_i=$(($(date +%s) - initial_i))
then echo "${tmp_post_user_uri_id_not_in_post_q} item(s) deleted until ${tmp_post_user_uri_id_not_in_post_current_uri_id} in ${final_i}s"
tmp_post_user_uri_id_not_in_post_current_uri_id=$(cat /tmp/fcb)
fi
echo "${tmp_post_user_uri_id_not_in_post_q} item(s) deleted until ${tmp_post_user_uri_id_not_in_post_current_uri_id}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_item_uri_not_in_valid_post_thread" echo "tmp_item_uri_not_in_valid_post_thread"
tmp_item_uri_not_in_valid_post_thread_q="${limit}" tmp_item_uri_not_in_valid_post_thread_q="${limit}"
tmp_item_uri_not_in_valid_post_thread_current_id=0 tmp_item_uri_not_in_valid_post_thread_current_id=0
until [[ "${tmp_item_uri_not_in_valid_post_thread_q}" -lt "${limit}" ]] until [[ "${tmp_item_uri_not_in_valid_post_thread_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_item_uri_not_in_valid_post_thread=$(sudo mariadb friendica -N -B -q -e \ tmp_item_uri_not_in_valid_post_thread=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-thread\` WHERE \`received\` < (CURDATE() - INTERVAL ${interval} DAY) \ "SELECT \`uri-id\` FROM \`post-thread\` WHERE \`received\` < (CURDATE() - INTERVAL ${interval} DAY) \
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-thread-user\` WHERE (\`mention\` OR \`starred\` OR \`wall\`) \ AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-thread-user\` WHERE (\`mention\` OR \`starred\` OR \`wall\`) \
AND \`uri-id\` = \`post-thread\`.\`uri-id\`) \ AND \`uri-id\` = \`post-thread\`.\`uri-id\`) \
@ -231,115 +192,94 @@ do
AND NOT \`uri-id\` IN (SELECT \`parent-uri-id\` FROM \`post-user\` WHERE (\`origin\` OR \`event-id\` != 0 OR \`post-type\` = 128) \ AND NOT \`uri-id\` IN (SELECT \`parent-uri-id\` FROM \`post-user\` WHERE (\`origin\` OR \`event-id\` != 0 OR \`post-type\` = 128) \
AND \`parent-uri-id\` = \`post-thread\`.\`uri-id\`) \ AND \`parent-uri-id\` = \`post-thread\`.\`uri-id\`) \
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-content\` WHERE \`resource-id\` != 0 AND \`uri-id\` = \`post-thread\`.\`uri-id\`) \ AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-content\` WHERE \`resource-id\` != 0 AND \`uri-id\` = \`post-thread\`.\`uri-id\`) \
AND \`uri-id\` > ${tmp_item_uri_not_in_valid_post_thread_current_id} ORDER BY \`uri-id\` LIMIT ${limit}"); AND \`uri-id\` > ${tmp_item_uri_not_in_valid_post_thread_current_id} ORDER BY \`uri-id\` LIMIT ${limit}")
tmp_item_uri_not_in_valid_post_thread_q=$(echo "${tmp_item_uri_not_in_valid_post_thread}" | grep -c '.') tmp_item_uri_not_in_valid_post_thread_q=$(echo "${tmp_item_uri_not_in_valid_post_thread}" | grep -c '.')
#echo "${tmp_item_uri_not_in_valid_post_thread_q}" #echo "${tmp_item_uri_not_in_valid_post_thread_q}"
if [[ "${tmp_item_uri_not_in_valid_post_thread_q}" -gt 0 ]] if [[ "${tmp_item_uri_not_in_valid_post_thread_q}" -gt 0 ]]; then
then echo "${tmp_item_uri_not_in_valid_post_thread}" | while read -r id; do
echo "${tmp_item_uri_not_in_valid_post_thread}" | while read -r id if [[ -n "${id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${id}" ]] "DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
#echo "${id}" #echo "${id}"
echo "${id}" > /tmp/fcb echo "${id}" >"${tmpfile}"
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_item_uri_not_in_valid_post_thread}") && "${tmp_item_uri_not_in_valid_post_thread_current_id}" -lt $(tac $(echo "${tmp_item_uri_not_in_valid_post_thread}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_item_uri_not_in_valid_post_thread_current_id=$(cat "${tmpfile}")
tmp_item_uri_not_in_valid_post_thread_current_id=$(tac $(echo "${tmp_item_uri_not_in_valid_post_thread}") | grep -m 1 '.')
fi fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]] final_i=$(($(date +%s) - initial_i))
then echo "${tmp_item_uri_not_in_valid_post_thread_q} item(s) deleted until ${tmp_item_uri_not_in_valid_post_thread_current_id} in ${final_i}s"
tmp_item_uri_not_in_valid_post_thread_current_id=$(cat /tmp/fcb)
fi
echo "${tmp_item_uri_not_in_valid_post_thread_q} item(s) deleted until ${tmp_item_uri_not_in_valid_post_thread_current_id}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_item_uri_not_in_valid_post_user" echo "tmp_item_uri_not_in_valid_post_user"
tmp_item_uri_not_in_valid_post_user_q="${limit}" tmp_item_uri_not_in_valid_post_user_q="${limit}"
tmp_item_uri_not_in_valid_post_user_current_id=0 tmp_item_uri_not_in_valid_post_user_current_id=0
until [[ "${tmp_item_uri_not_in_valid_post_user_q}" -lt "${limit}" ]] until [[ "${tmp_item_uri_not_in_valid_post_user_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_item_uri_not_in_valid_post_user=$(sudo mariadb friendica -N -B -q -e \ tmp_item_uri_not_in_valid_post_user=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`uri-id\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`uid\` = 0 \ "SELECT \`uri-id\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`uid\` = 0 \
AND \`received\` < (CURDATE() - INTERVAL ${interval} DAY) AND NOT \`uri-id\` IN ( SELECT \`parent-uri-id\` FROM \`post-user\` AS \`i\` WHERE \`i\`.\`uid\` != 0 \ AND \`received\` < (CURDATE() - INTERVAL ${interval} DAY) AND NOT \`uri-id\` IN ( SELECT \`parent-uri-id\` FROM \`post-user\` AS \`i\` WHERE \`i\`.\`uid\` != 0 \
AND \`i\`.\`parent-uri-id\` = \`post-user\`.\`uri-id\` ) AND NOT \`uri-id\` IN ( SELECT \`parent-uri-id\` FROM \`post-user\` AS \`i\` WHERE \`i\`.\`uid\` = 0 \ AND \`i\`.\`parent-uri-id\` = \`post-user\`.\`uri-id\` ) AND NOT \`uri-id\` IN ( SELECT \`parent-uri-id\` FROM \`post-user\` AS \`i\` WHERE \`i\`.\`uid\` = 0 \
AND \`i\`.\`parent-uri-id\` = \`post-user\`.\`uri-id\` AND \`i\`.\`received\` > (CURDATE() - INTERVAL ${interval} DAY) ) \ AND \`i\`.\`parent-uri-id\` = \`post-user\`.\`uri-id\` AND \`i\`.\`received\` > (CURDATE() - INTERVAL ${interval} DAY) ) \
AND \`uri-id\` > ${tmp_item_uri_not_in_valid_post_user_current_id} ORDER BY \`uri-id\` LIMIT ${limit}"); AND \`uri-id\` > ${tmp_item_uri_not_in_valid_post_user_current_id} ORDER BY \`uri-id\` LIMIT ${limit}")
tmp_item_uri_not_in_valid_post_user_q=$(echo "${tmp_item_uri_not_in_valid_post_user}" | grep -c '.') tmp_item_uri_not_in_valid_post_user_q=$(echo "${tmp_item_uri_not_in_valid_post_user}" | grep -c '.')
#echo "${tmp_item_uri_not_in_valid_post_user_q}" #echo "${tmp_item_uri_not_in_valid_post_user_q}"
if [[ "${tmp_item_uri_not_in_valid_post_user_q}" -gt 0 ]] if [[ "${tmp_item_uri_not_in_valid_post_user_q}" -gt 0 ]]; then
then echo "${tmp_item_uri_not_in_valid_post_user}" | while read -r id; do
echo "${tmp_item_uri_not_in_valid_post_user}" | while read -r id if [[ -n "${id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${id}" ]] "DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
#echo "${id}" #echo "${id}"
echo "${id}" > /tmp/fcb echo "${id}" >"${tmpfile}"
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_item_uri_not_in_valid_post_user}") && "${tmp_item_uri_not_in_valid_post_user_current_id}" -lt $(tac $(echo "${tmp_item_uri_not_in_valid_post_user}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_item_uri_not_in_valid_post_user_current_id=$(cat "${tmpfile}")
tmp_item_uri_not_in_valid_post_user_current_id=$(tac $(echo "${tmp_item_uri_not_in_valid_post_user}") | grep -m 1 '.')
fi fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]] final_i=$(($(date +%s) - initial_i))
then echo "${tmp_item_uri_not_in_valid_post_user_q} item(s) deleted until ${tmp_item_uri_not_in_valid_post_user_current_id} in ${final_i}s"
tmp_item_uri_id_not_in_valid_post_current_id=$(cat /tmp/fcb)
fi
echo "${tmp_item_uri_not_in_valid_post_user_q} item(s) deleted until ${tmp_item_uri_not_in_valid_post_user_current_id}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_attach_not_in_post_media" echo "tmp_attach_not_in_post_media"
tmp_attach_not_in_post_media_q="${limit}" tmp_attach_not_in_post_media_q="${limit}"
tmp_attach_not_in_post_media_current_id=0 tmp_attach_not_in_post_media_current_id=0
until [[ "${tmp_attach_not_in_post_media_q}" -lt "${limit}" ]] until [[ "${tmp_attach_not_in_post_media_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_attach_not_in_post_media=$(sudo mariadb friendica -N -B -q -e \ tmp_attach_not_in_post_media=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`id\` FROM \`attach\` WHERE \`id\` NOT IN (SELECT \`attach-id\` FROM \`post-media\`) \ "SELECT \`id\` FROM \`attach\` WHERE \`id\` NOT IN (SELECT \`attach-id\` FROM \`post-media\`) \
AND \`id\` > ${tmp_attach_not_in_post_media_current_id} ORDER BY \`id\` LIMIT ${limit}"); AND \`id\` > ${tmp_attach_not_in_post_media_current_id} ORDER BY \`id\` LIMIT ${limit}")
tmp_attach_not_in_post_media_q=$(echo "${tmp_attach_not_in_post_media}" | grep -c '.') tmp_attach_not_in_post_media_q=$(echo "${tmp_attach_not_in_post_media}" | grep -c '.')
#echo "${tmp_attach_not_in_post_media_q}" #echo "${tmp_attach_not_in_post_media_q}"
if [[ "${tmp_attach_not_in_post_media_q}" -gt 0 ]] if [[ "${tmp_attach_not_in_post_media_q}" -gt 0 ]]; then
then echo "${tmp_attach_not_in_post_media}" | while read -r id; do
echo "${tmp_attach_not_in_post_media}" | while read -r id if [[ -n "${id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${id}" ]] "DELETE FROM \`attach\` WHERE \`id\` = ${id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`attach\` WHERE \`id\` = ${id}"
#echo "${id}" #echo "${id}"
echo "${id}" > /tmp/fcb echo "${id}" >"${tmpfile}"
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_attach_not_in_post_media}") && "${tmp_attach_not_in_post_media_current_id}" -lt $(tac $(echo "${tmp_attach_not_in_post_media}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_attach_not_in_post_media_current_id=$(cat "${tmpfile}")
tmp_attach_not_in_post_media_current_id=$(tac $(echo "${tmp_attach_not_in_post_media}") | grep -m 1 '.')
fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]]
then
tmp_attach_not_in_post_media_current_id=$(cat /tmp/fcb)
fi fi
final_i=$(($(date +%s) - initial_i))
echo "${tmp_attach_not_in_post_media_q} item(s) deleted until ${tmp_attach_not_in_post_media_current_id}" echo "${tmp_attach_not_in_post_media_q} item(s) deleted until ${tmp_attach_not_in_post_media_current_id}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_item_uri_not_valid" echo "tmp_item_uri_not_valid"
tmp_item_uri_not_valid_q="${limit}" tmp_item_uri_not_valid_q="${limit}"
tmp_item_uri_not_valid_current_id=0 tmp_item_uri_not_valid_current_id=0
tmp_item_uri_not_valid_last_id=$(sudo mariadb friendica -N -B -q -e \ tmp_item_uri_not_valid_last_id=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`uri-id\` FROM \`post\` WHERE \`received\` < CURDATE() - INTERVAL 1 DAY ORDER BY \`received\` DESC LIMIT 1") "SELECT \`uri-id\` FROM \`post\` WHERE \`received\` < CURDATE() - INTERVAL 1 DAY ORDER BY \`received\` DESC LIMIT 1")
until [[ "${tmp_item_uri_not_valid_q}" -lt "${limit}" ]] until [[ "${tmp_item_uri_not_valid_q}" -lt "${limit}" ]]; do
do initial_i=$(date +%s)
tmp_item_uri_not_valid=$(sudo mariadb friendica -N -B -q -e \ tmp_item_uri_not_valid=$("${dbengine}" "${db}" -N -B -q -e \
"SELECT \`id\` FROM \`item-uri\` WHERE ( \`id\` < ${tmp_item_uri_not_valid_last_id} ) \ "SELECT \`id\` FROM \`item-uri\` WHERE ( \`id\` < ${tmp_item_uri_not_valid_last_id} ) \
AND NOT EXISTS ( SELECT \`uri-id\` FROM \`post-user\` WHERE \`uri-id\` = \`item-uri\`.\`id\` ) \ AND NOT EXISTS ( SELECT \`uri-id\` FROM \`post-user\` WHERE \`uri-id\` = \`item-uri\`.\`id\` ) \
AND NOT EXISTS ( SELECT \`parent-uri-id\` FROM \`post-user\` WHERE \`parent-uri-id\` = \`item-uri\`.\`id\` ) \ AND NOT EXISTS ( SELECT \`parent-uri-id\` FROM \`post-user\` WHERE \`parent-uri-id\` = \`item-uri\`.\`id\` ) \
@ -359,50 +299,39 @@ do
AND NOT EXISTS ( SELECT \`uri-id\` FROM \`post-delivery\` WHERE \`inbox-id\` = \`item-uri\`.\`id\` ) \ AND NOT EXISTS ( SELECT \`uri-id\` FROM \`post-delivery\` WHERE \`inbox-id\` = \`item-uri\`.\`id\` ) \
AND NOT EXISTS ( SELECT \`parent-uri-id\` FROM \`mail\` WHERE \`parent-uri-id\` = \`item-uri\`.\`id\` ) \ AND NOT EXISTS ( SELECT \`parent-uri-id\` FROM \`mail\` WHERE \`parent-uri-id\` = \`item-uri\`.\`id\` ) \
AND NOT EXISTS ( SELECT \`thr-parent-id\` FROM \`mail\` WHERE \`thr-parent-id\` = \`item-uri\`.\`id\` ) \ AND NOT EXISTS ( SELECT \`thr-parent-id\` FROM \`mail\` WHERE \`thr-parent-id\` = \`item-uri\`.\`id\` ) \
AND (\`id\` > ${tmp_item_uri_not_valid_current_id} ) ORDER BY \`id\` LIMIT ${limit}"); AND (\`id\` > ${tmp_item_uri_not_valid_current_id} ) ORDER BY \`id\` LIMIT ${limit}")
tmp_item_uri_not_valid_q=$(echo "${tmp_item_uri_not_valid}" | grep -c '.') tmp_item_uri_not_valid_q=$(echo "${tmp_item_uri_not_valid}" | grep -c '.')
#echo "${tmp_item_uri_not_valid_q}" #echo "${tmp_item_uri_not_valid_q}"
if [[ "${tmp_item_uri_not_valid_q}" -gt 0 ]] if [[ "${tmp_item_uri_not_valid_q}" -gt 0 ]]; then
then echo "${tmp_item_uri_not_valid}" | while read -r id; do
echo "${tmp_item_uri_not_valid}" | while read -r id if [[ -n "${id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${id}" ]] "DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
then echo "${id}" >"${tmpfile}"
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
#echo "${id}"
echo "${id}" > /tmp/fcb
fi fi
done done
fi fi
if [[ -s $(echo "${tmp_item_uri_not_valid_current_id}") && "${tmp_item_uri_not_valid_current_id}" -lt $(tac $(echo "${tmp_item_uri_not_valid}") | grep -m 1 '.') ]] if [[ -f "${tmpfile}" && -s "${tmpfile}" ]]; then
then tmp_item_uri_not_valid_current_id=$(cat "${tmpfile}")
tmp_item_uri_not_valid_current_id=$(tac $(echo "${tmp_item_uri_not_valid}") | grep -m 1 '.')
fi fi
if [[ -f /tmp/fcb && -s /tmp/fcb ]] final_i=$(($(date +%s) - initial_i))
then echo "${tmp_item_uri_not_valid_q} item(s) deleted until ${tmp_item_uri_not_valid_current_id} in ${final_i}s"
tmp_item_uri_id_not_valid_current_id=$(cat /tmp/fcb)
fi
echo "${tmp_item_uri_not_valid_q} item(s) deleted until ${tmp_item_uri_not_valid_current_id}"
done done
rm /tmp/fcb && touch /tmp/fcb rm "${tmpfile}" && touch "${tmpfile}"
echo "tmp_item_uri_duplicate" echo "tmp_item_uri_duplicate"
tmp_item_uri_duplicate_q="${limit}" tmp_item_uri_duplicate_q="${limit}"
until [[ "${tmp_item_uri_duplicate_q}" -lt "${limit}" ]] until [[ "${tmp_item_uri_duplicate_q}" -lt "${limit}" ]]; do
do tmp_item_uri_duplicate=$("${dbengine}" "${db}" -N -B -q -e \
tmp_item_uri_duplicate=$(sudo mariadb friendica -N -B -q -e \
"SELECT t1.\`id\` FROM \`item-uri\` t1 INNER JOIN \`item-uri\` t2 WHERE t1.\`id\` < t2.\`id\` AND t1.\`uri\` = t2.\`uri\` LIMIT ${limit}") "SELECT t1.\`id\` FROM \`item-uri\` t1 INNER JOIN \`item-uri\` t2 WHERE t1.\`id\` < t2.\`id\` AND t1.\`uri\` = t2.\`uri\` LIMIT ${limit}")
tmp_item_uri_duplicate_q=$(echo "${tmp_item_uri_duplicate}" | grep -c '.') tmp_item_uri_duplicate_q=$(echo "${tmp_item_uri_duplicate}" | grep -c '.')
final_i=$(($(date +%s) - initial_i))
echo "${tmp_item_uri_duplicate_q}" echo "${tmp_item_uri_duplicate_q}"
if [[ "${tmp_item_uri_duplicate_q}" -gt 0 ]] if [[ "${tmp_item_uri_duplicate_q}" -gt 0 ]]; then
then echo "${tmp_item_uri_duplicate}" | while read -r id; do
echo "${tmp_item_uri_duplicate}" | while read -r id if [[ -n "${id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${id}" ]] "DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`item-uri\` WHERE \`id\` = ${id}"
echo "${id}" echo "${id}"
fi fi
done done
@ -411,20 +340,17 @@ done
echo "tmp_post_media_duplicate" echo "tmp_post_media_duplicate"
tmp_post_media_duplicate_q="${limit}" tmp_post_media_duplicate_q="${limit}"
until [[ "${tmp_post_media_duplicate_q}" -lt "${limit}" ]] until [[ "${tmp_post_media_duplicate_q}" -lt "${limit}" ]]; do
do tmp_post_media_duplicate=$("${dbengine}" "${db}" -N -B -q -e \
tmp_post_media_duplicate=$(sudo mariadb friendica -N -B -q -e \
"SELECT u1.\`id\` FROM \`post-media\` u1 INNER JOIN \`post-media\` u2 WHERE u1.\`id\` < u2.\`id\` AND u1.\`uri-id\` = u2.\`uri-id\` AND u1.\`url\`= u2.\`url\` LIMIT ${limit}") "SELECT u1.\`id\` FROM \`post-media\` u1 INNER JOIN \`post-media\` u2 WHERE u1.\`id\` < u2.\`id\` AND u1.\`uri-id\` = u2.\`uri-id\` AND u1.\`url\`= u2.\`url\` LIMIT ${limit}")
tmp_post_media_duplicate_q=$(echo "${tmp_post_media_duplicate}" | grep -c '.') tmp_post_media_duplicate_q=$(echo "${tmp_post_media_duplicate}" | grep -c '.')
final_i=$(($(date +%s) - initial_i))
echo "${tmp_post_media_duplicate_q}" echo "${tmp_post_media_duplicate_q}"
if [[ "${tmp_post_media_duplicate_q}" -gt 0 ]] if [[ "${tmp_post_media_duplicate_q}" -gt 0 ]]; then
then echo "${tmp_post_media_duplicate}" | while read -r id; do
echo "${tmp_post_media_duplicate}" | while read -r id if [[ -n "${id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${id}" ]] "DELETE FROM \`post-media\` WHERE \`id\` = ${id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-media\` WHERE \`id\` = ${id}"
echo "${id}" echo "${id}"
fi fi
done done
@ -433,20 +359,17 @@ done
echo "tmp_post_user_duplicate" echo "tmp_post_user_duplicate"
tmp_post_user_duplicate_q="${limit}" tmp_post_user_duplicate_q="${limit}"
until [[ "${tmp_post_user_duplicate_q}" -lt "${limit}" ]] until [[ "${tmp_post_user_duplicate_q}" -lt "${limit}" ]]; do
do tmp_post_user_duplicate=$("${dbengine}" "${db}" -N -B -q -e \
tmp_post_user_duplicate=$(sudo mariadb friendica -N -B -q -e \
"SELECT v1.\`id\` FROM \`post-user\` v1 INNER JOIN \`post-media\` v2 WHERE v1.\`id\` = v2.\`id\` AND v1.\`uri-id\` = v2.\`uri-id\` LIMIT ${limit}") "SELECT v1.\`id\` FROM \`post-user\` v1 INNER JOIN \`post-media\` v2 WHERE v1.\`id\` = v2.\`id\` AND v1.\`uri-id\` = v2.\`uri-id\` LIMIT ${limit}")
tmp_post_user_duplicate_q=$(echo "${tmp_post_user_duplicate}" | grep -c '.') tmp_post_user_duplicate_q=$(echo "${tmp_post_user_duplicate}" | grep -c '.')
final_i=$(($(date +%s) - initial_i))
echo "${tmp_post_user_duplicate_q}" echo "${tmp_post_user_duplicate_q}"
if [[ "${tmp_post_user_duplicate_q}" -gt 0 ]] if [[ "${tmp_post_user_duplicate_q}" -gt 0 ]]; then
then echo "${tmp_post_user_duplicate}" | while read -r id; do
echo "${tmp_post_user_duplicate}" | while read -r id if [[ -n "${id}" ]]; then
do "${dbengine}" "${db}" -N -B -q -e \
if [[ -n "${id}" ]] "DELETE FROM \`post-user\` WHERE \`id\` = ${id}"
then
sudo mariadb friendica -N -B -q -e \
"DELETE FROM \`post-user\` WHERE \`id\` = ${id}"
echo "${id}" echo "${id}"
fi fi
done done

View file

@ -9,9 +9,8 @@ loop_1() {
sitereq=$(curl -s -L --head -m 30 --request GET "${a}") sitereq=$(curl -s -L --head -m 30 --request GET "${a}")
#Skip check if the message contains a reference to Cloudflare #Skip check if the message contains a reference to Cloudflare
status=$(echo "${sitereq}" | grep -e "200" -e "cloudflare") status=$(echo "${sitereq}" | grep -e "200" -e "cloudflare")
if [[ -z ${status} ]] if [[ -z ${status} ]]; then
then echo "${a}" >>"${tmpfile}"
echo "${a}" >> "${tmpfile}"
echo "Added ${a}" echo "Added ${a}"
fi fi
} }
@ -24,13 +23,10 @@ loop_3() {
baseurltrimmed=$(echo "${baseurl}" | sed -e "s/http[s]*:\/\///g") baseurltrimmed=$(echo "${baseurl}" | sed -e "s/http[s]*:\/\///g")
echo "Deleting user ${lineb} - ${nick}@${baseurltrimmed}" echo "Deleting user ${lineb} - ${nick}@${baseurltrimmed}"
#Find the pictures in the avatar folders and delete them #Find the pictures in the avatar folders and delete them
"${dbengine}" "${db}" -N -B -q -e "select \`photo\`, \`thumb\`, \`micro\` from \`contact\` where \`id\` = ${lineb}" | while read -r photo thumb micro "${dbengine}" "${db}" -N -B -q -e "select \`photo\`, \`thumb\`, \`micro\` from \`contact\` where \`id\` = ${lineb}" | while read -r photo thumb micro; do
do
#If stored in avatar folder #If stored in avatar folder
if $(echo "${photo}" | grep -q "${url}/avatar") if $(echo "${photo}" | grep -q "${url}/avatar"); then #isavatar=$(grep -q "${url}/avatar" <<< "${photo}")
#isavatar=$(grep -q "${url}/avatar" <<< "${photo}") #if [[ -z "${isavatar}" ]]
#if [[ -z "${isavatar}" ]]
then
phototrimmed=$(echo "${photo}" | sed -e "s/https:\/\/${url}\/avatar/${avatarfolderescaped}/g" -e "s/\?ts.*//g") phototrimmed=$(echo "${photo}" | sed -e "s/https:\/\/${url}\/avatar/${avatarfolderescaped}/g" -e "s/\?ts.*//g")
echo "${phototrimmed}" echo "${phototrimmed}"
rm -rfv "${phototrimmed}" rm -rfv "${phototrimmed}"
@ -51,29 +47,23 @@ loop_3() {
#Check for mariadb vs. mysql #Check for mariadb vs. mysql
dbengine="" dbengine=""
if [[ -n $(type mariadb) ]] if [[ -n $(type mariadb) ]]; then
then dbengine="mariadb"
dbengine="mariadb" elif [[ -n $(type mysql) ]]; then
elif [[ -n $(type mysql) ]] dbengine="mysql"
then
dbengine="mysql"
fi 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) ]] if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(type date) ]]; then
then
date date
if [[ ! -f "${tmpfile}" ]] if [[ ! -f "${tmpfile}" ]]; then
then
echo "Listing sites" echo "Listing sites"
#sites=($("${dbengine}" "${db}" -N -B -q -e "select distinct baseurl from contact where baseurl != \"\"" | sort -n | uniq )) #sites=($("${dbengine}" "${db}" -N -B -q -e "select distinct baseurl from contact where baseurl != \"\"" | sort -n | uniq ))
sites=() sites=()
mapfile -t sites < <("${dbengine}" "${db}" -N -B -q -e "select distinct baseurl from contact where baseurl != \"\"" | sort -b -f -n | uniq -i ) mapfile -t sites < <("${dbengine}" "${db}" -N -B -q -e "select distinct baseurl from contact where baseurl != \"\"" | sort -b -f -n | uniq -i)
echo "Amount of unique sites: ${#sites[@]}" echo "Amount of unique sites: ${#sites[@]}"
for a in "${sites[@]}" for a in "${sites[@]}"; do
do
loop_1 "${a}" & loop_1 "${a}" &
if [[ $(jobs -r -p | wc -l) -ge $(( $(getconf _NPROCESSORS_ONLN) * 2 )) ]] if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then
then
wait -n wait -n
fi fi
done done
@ -82,15 +72,12 @@ then
sitesdown=() sitesdown=()
while read -r line; do while read -r line; do
sitesdown+=("${line}") sitesdown+=("${line}")
done < "${tmpfile}" done <"${tmpfile}"
echo "Amount of sites down: ${#sitesdown[@]} / ${#sites[@]}" echo "Amount of sites down: ${#sitesdown[@]} / ${#sites[@]}"
if [[ ! -f "${idsdownfile}" ]] if [[ ! -f "${idsdownfile}" ]]; then
then for b in "${sitesdown[@]}"; do
for b in "${sitesdown[@]}"
do
loop_2 "${b}" & loop_2 "${b}" &
if [[ $(jobs -r -p | wc -l) -ge $(( $(getconf _NPROCESSORS_ONLN) / 2 )) ]] if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) / 2)) ]]; then
then
wait -n wait -n
fi fi
done done
@ -103,13 +90,12 @@ then
#idsdown+=($lineb) #idsdown+=($lineb)
#The community no longer exists, delete #The community no longer exists, delete
loop_3 "${lineb}" "${nick}" "${baseurl}" & loop_3 "${lineb}" "${nick}" "${baseurl}" &
if [[ $(jobs -r -p | wc -l) -ge $(( $(getconf _NPROCESSORS_ONLN) / 2 )) ]] if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) / 2)) ]]; then
then
wait -n wait -n
fi fi
wait wait
done < "${idsdownfile}" done <"${idsdownfile}"
rm "${tmpfile}" 2> /dev/null rm "${tmpfile}" 2>/dev/null
rm "${idsdownfile}" 2> /dev/null rm "${idsdownfile}" 2>/dev/null
date date
fi fi

View file

@ -12,34 +12,26 @@ folderescaped=${folder////\\/}
tmpfile=/tmp/friendica-fix-avatar-permissions.txt tmpfile=/tmp/friendica-fix-avatar-permissions.txt
avatarfolder=avatar avatarfolder=avatar
loop_1(){ loop_1() {
if [[ "${p}" =~ .jpeg || "${p}" =~ .jpg ]] if [[ "${p}" =~ .jpeg || "${p}" =~ .jpg ]]; then
then
nice -n 10 jpegoptim -m 76 "${p}" #&> /dev/null nice -n 10 jpegoptim -m 76 "${p}" #&> /dev/null
elif [[ "${p}" =~ .gif ]] elif [[ "${p}" =~ .gif ]]; then
then
nice -n 10 gifsicle --batch -O3 --lossy=80 --colors=255 "${p}" #&> /dev/null nice -n 10 gifsicle --batch -O3 --lossy=80 --colors=255 "${p}" #&> /dev/null
#Specific compression for large GIF files #Specific compression for large GIF files
while [[ $(stat -c%s "${p}" || 0) -ge 512000 ]] while [[ $(stat -c%s "${p}" || 0) -ge 512000 ]]; do
do
frameamount=$(exiftool -b -FrameCount "${p}" || 1) frameamount=$(exiftool -b -FrameCount "${p}" || 1)
nice -n 10 gifsicle "${p}" $(seq -f "#%g" 0 2 "${frameamount}") -O3 --lossy=80 --colors=255 -o "${p}" #&> /dev/null nice -n 10 gifsicle "${p}" $(seq -f "#%g" 0 2 "${frameamount}") -O3 --lossy=80 --colors=255 -o "${p}" #&> /dev/null
done done
elif [[ "${p}" =~ .png ]] elif [[ "${p}" =~ .png ]]; then
then
nice -n 10 oxipng -o max "${p}" #&> /dev/null nice -n 10 oxipng -o max "${p}" #&> /dev/null
elif [[ "${p}" =~ .webp ]] elif [[ "${p}" =~ .webp ]]; then
then
#If file is not animated #If file is not animated
if ! grep -v -q -e "ANIM" -e "ANMF" "${p}" if ! grep -v -q -e "ANIM" -e "ANMF" "${p}"; then
then
nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
if [[ -f /tmp/temp.webp ]] if [[ -f /tmp/temp.webp ]]; then
then size_new=$(stat -c%s "/tmp/temp.webp" || 0)
size_new=$(stat -c%s "/tmp/temp.webp" || 0 )
size_original=$(stat -c%s "${p}") size_original=$(stat -c%s "${p}")
if [[ "${size_original}" -gt "${size_new}" ]] if [[ "${size_original}" -gt "${size_new}" ]]; then
then
mv /tmp/temp.webp "${p}" #&> /dev/null mv /tmp/temp.webp "${p}" #&> /dev/null
else else
rm /tmp/temp.webp #&> /dev/null rm /tmp/temp.webp #&> /dev/null
@ -50,18 +42,14 @@ loop_1(){
} }
cd "${folder}" || exit cd "${folder}" || exit
if [[ ! -f "${tmpfile}" ]] if [[ ! -f "${tmpfile}" ]]; then
then
sudo -u "${user}" bin/console movetoavatarcache | sudo tee "${tmpfile}" #&> /dev/null sudo -u "${user}" bin/console movetoavatarcache | sudo tee "${tmpfile}" #&> /dev/null
fi fi
grep -e "https://${site}/${avatarfolder}/" "${tmpfile}" | sed -e "s/.*${site}/${folderescaped}/g" -e "s/?ts=.*//g" | ( grep -e "https://${site}/${avatarfolder}/" "${tmpfile}" | sed -e "s/.*${site}/${folderescaped}/g" -e "s/?ts=.*//g" | (
while read -r i while read -r i; do
do for p in "${i}" "${i//-320/-80}" "${i//-320/-48}"; do
for p in "${i}" "${i//-320/-80}" "${i//-320/-48}"
do
loop_1 "${p}" & loop_1 "${p}" &
if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]] if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]]; then
then
wait -n wait -n
fi fi
done done
@ -72,6 +60,6 @@ rm "${tmpfile}"
/usr/bin/find "${folder}"/avatar -type d -empty -delete /usr/bin/find "${folder}"/avatar -type d -empty -delete
/usr/bin/chmod "${folderperm}" "${folder}"/avatar /usr/bin/chmod "${folderperm}" "${folder}"/avatar
/usr/bin/chown -R "${user}":"${group}" "${folder}"/avatar /usr/bin/chown -R "${user}":"${group}" "${folder}"/avatar
/usr/bin/find "${folder}"/avatar -depth -not -user "${user}" -or -not -group "${group}" -print0 | xargs -0 -r chown -v "${user}":"${group}" #&> /dev/null /usr/bin/find "${folder}"/avatar -depth -not -user "${user}" -or -not -group "${group}" -print0 | xargs -0 -r chown -v "${user}":"${group}" #&> /dev/null
/usr/bin/find "${folder}"/avatar -depth -type d -and -not -type f -and -not -perm "${folderperm}" -print0 | xargs -0 -r chmod -v "${folderperm}" #&> /dev/null /usr/bin/find "${folder}"/avatar -depth -type d -and -not -type f -and -not -perm "${folderperm}" -print0 | xargs -0 -r chmod -v "${folderperm}" #&> /dev/null
/usr/bin/find "${folder}"/avatar -depth -type f -and -not -type d -and -not -perm "${fileperm}" -print0 | xargs -0 -r chmod -v "${fileperm}" #&> /dev/null /usr/bin/find "${folder}"/avatar -depth -type f -and -not -type d -and -not -perm "${fileperm}" -print0 | xargs -0 -r chmod -v "${fileperm}" #&> /dev/null

View file

@ -1,10 +1,9 @@
#!/bin/bash #!/bin/bash
ca=100 ca=100
camax=0 camax=0
while [[ ${ca} -gt 0 ]] while [[ ${ca} -gt 0 ]]; do
do
ca=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where regexp_replace(regexp_replace(\`parameter\`, '\\\[', ''), '\\\]', '') not in (select \`id\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \`command\` = \"UpdateContact\" limit ${ca}; select row_count();") ca=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where regexp_replace(regexp_replace(\`parameter\`, '\\\[', ''), '\\\]', '') not in (select \`id\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \`command\` = \"UpdateContact\" limit ${ca}; select row_count();")
camax=$(( camax + ca )) camax=$((camax + ca))
printf "\rUpdateContact\t\t%s\r" "${camax}" printf "\rUpdateContact\t\t%s\r" "${camax}"
done done
printf "\rUpdateContact\t\t%s\n\r" "${camax}" printf "\rUpdateContact\t\t%s\n\r" "${camax}"
@ -12,10 +11,9 @@ printf "\rUpdateContact\t\t%s\n\r" "${camax}"
cb=100 cb=100
cbmax=0 cbmax=0
while [[ ${cb} -gt 0 ]] while [[ ${cb} -gt 0 ]]; do
do
cb=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where regexp_replace(regexp_replace(\`parameter\`, '\\\[', ''), '\\\]', '') not in (select \`id\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \`command\` = \"ContactDiscovery\" limit ${cb}; select row_count();") cb=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where regexp_replace(regexp_replace(\`parameter\`, '\\\[', ''), '\\\]', '') not in (select \`id\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \`command\` = \"ContactDiscovery\" limit ${cb}; select row_count();")
cbmax=$(( cbmax + cb )) cbmax=$((cbmax + cb))
printf "\rContactDiscovery\t%s\r" "${cbmax}" printf "\rContactDiscovery\t%s\r" "${cbmax}"
done done
printf "\rContactDiscovery\t%s\n\r" "${cbmax}" printf "\rContactDiscovery\t%s\n\r" "${cbmax}"
@ -23,10 +21,9 @@ printf "\rContactDiscovery\t%s\n\r" "${cbmax}"
cc=100 cc=100
ccmax=0 ccmax=0
while [[ ${cc} -gt 0 ]] while [[ ${cc} -gt 0 ]]; do
do
cc=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where regexp_replace(substring_index(substring_index(\`parameter\`, '\\\"', -2), '\\\"', 1), '\\\\\\\\', '') not in (select \`url\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \`command\` = \"FetchFeaturedPosts\" limit ${cc}; select row_count();") cc=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where regexp_replace(substring_index(substring_index(\`parameter\`, '\\\"', -2), '\\\"', 1), '\\\\\\\\', '') not in (select \`url\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \`command\` = \"FetchFeaturedPosts\" limit ${cc}; select row_count();")
ccmax=$(( ccmax + cc )) ccmax=$((ccmax + cc))
printf "\rFetchFeaturedPosts\t%s\r" "${ccmax}" printf "\rFetchFeaturedPosts\t%s\r" "${ccmax}"
done done
@ -35,10 +32,9 @@ printf "\rFetchFeaturedPosts\t%s\n\r" "${ccmax}"
cd=100 cd=100
cdmax=0 cdmax=0
while [[ ${cd} -gt 0 ]] while [[ ${cd} -gt 0 ]]; do
do
cd=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where regexp_replace(substring_index(substring_index(\`parameter\`, '\\\"', -2), '\\\"', 1), '\\\\\\\\', '') not in (select \`url\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \`command\` = \"UpdateGServer\" limit ${cd}; select row_count();") cd=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where regexp_replace(substring_index(substring_index(\`parameter\`, '\\\"', -2), '\\\"', 1), '\\\\\\\\', '') not in (select \`url\` from \`contact\` where \`id\` in (select \`contact-id\` from \`group_member\`)) and \`command\` = \"UpdateGServer\" limit ${cd}; select row_count();")
cdmax=$(( cdmax + cd )) cdmax=$((cdmax + cd))
printf "\rUpdateGServer\t\t%s\r" "${cdmax}" printf "\rUpdateGServer\t\t%s\r" "${cdmax}"
done done
printf "\rUpdateGServer\t\t%s\n\r" "${cdmax}" printf "\rUpdateGServer\t\t%s\n\r" "${cdmax}"
@ -46,12 +42,10 @@ printf "\rUpdateGServer\t\t%s\n\r" "${cdmax}"
ce=100 ce=100
cemax=0 cemax=0
while [[ ${ce} -gt 0 ]] while [[ ${ce} -gt 0 ]]; do
do
ce=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where command=\"ProcessQueue\" and pid=0 and done=0 limit ${ce}; select row_count();") ce=$(sudo mariadb friendica -B -N -q -e "delete from workerqueue where command=\"ProcessQueue\" and pid=0 and done=0 limit ${ce}; select row_count();")
cemax=$(( cemax + ce )) cemax=$((cemax + ce))
printf "\rProcessQueue\t\t%s\r" "${cemax}" printf "\rProcessQueue\t\t%s\r" "${cemax}"
done done
printf "\rProcessQueue\t\t%s\n\r" "${cemax}" printf "\rProcessQueue\t\t%s\n\r" "${cemax}"
#echo "ProcessQueue $cemax" #echo "ProcessQueue $cemax"

View file

@ -10,11 +10,10 @@ loop() {
#Parse each file in folder #Parse each file in 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=$(sudo mariadb "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1") f=$(sudo mariadb "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1")
if [[ $? -eq 0 && -z ${f} && -f ${y} ]] if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then
then
ls -lh "${y}" ls -lh "${y}"
sudo rm -rf "${y}" sudo rm -rf "${y}"
d=$(( d + 1 )) d=$((d + 1))
fi fi
#printf "\rPhotos: %s\tFolder %s\tEntry %s " "$d" "$n" "$m" #printf "\rPhotos: %s\tFolder %s\tEntry %s " "$d" "$n" "$m"
printf "\rFolder %s\tEntry %s " "${n}" "${m}" printf "\rFolder %s\tEntry %s " "${n}" "${m}"
@ -25,33 +24,28 @@ date
#Go to the Friendica installation #Go to the Friendica installation
cd "${folderavatar}" || exit cd "${folderavatar}" || exit
let "indexlength=37+${#url}" let "indexlength=37+${#url}"
(( indexlength=49+${#url} )) ((indexlength = 49 + ${#url}))
sudo mariadb "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))" sudo mariadb "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))"
n=0 n=0
d=0 d=0
sudo find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d | while read -r x sudo find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d | while read -r x; do
do n=$((n + 1))
n=$(( n + 1 ))
#If the directory still exists #If the directory still exists
if [[ -d "${x}" ]] if [[ -d "${x}" ]]; then
then folderescaped=${folder////\\/}
folderescaped=${folder////\\/} kx=$(echo "${x}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g")
kx=$(echo "${x}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g") if [[ -d ${x} ]]; then
if [[ -d ${x} ]]
then
m=0 m=0
while read -r y while read -r y; do
do m=$((m + 1))
m=$(( m + 1 ))
loop "${x}" "${m}" "${n}" "${d}" & loop "${x}" "${m}" "${n}" "${d}" &
if [[ $(jobs -r -p | wc -l) -ge $(( $(getconf _NPROCESSORS_ONLN) * 2 )) ]] if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then
then wait -n
wait -n fi
fi #done < <(sudo find "${x}" -type f -mtime -8)
#done < <(sudo find "${x}" -type f -mtime -8)
done < <(sudo find "${x}" -type f) done < <(sudo find "${x}" -type f)
fi fi
fi fi
done done
sudo mariadb "${db}" -e "alter table contact drop index photo_index" sudo mariadb "${db}" -e "alter table contact drop index photo_index"
date date

View file

@ -3,69 +3,57 @@ IFS="
" "
#media-optimize #media-optimize
find . -type f -iname "*.jp*" -size +50k | ( find . -type f -iname "*.jp*" -size +50k | (
while read p while read p; do
do nice -n 15 jpegoptim -m 76 "${p}" &
nice -n 15 jpegoptim -m 76 "${p}" & if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]]; then
if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]] wait -n
then fi
wait -n done
fi wait
done;
wait
) )
find . -type f -iname "*.gif" -size +500k | ( find . -type f -iname "*.gif" -size +500k | (
while read q while read q; do
do nice -n 15 gifsicle --batch -O3 --lossy=80 --colors=255 "${q}" &
nice -n 15 gifsicle --batch -O3 --lossy=80 --colors=255 "${q}" & if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]]; then
if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]] wait -n
then fi
wait -n done
fi wait
done;
wait
) )
#Specific compression for large GIF files: halving the frame rate #Specific compression for large GIF files: halving the frame rate
find . -type f -size +500k -iname "*-320.gif" -or -iname "*-80.gif" -or -iname "*-48.gif" | ( find . -type f -size +500k -iname "*-320.gif" -or -iname "*-80.gif" -or -iname "*-48.gif" | (
while read p while read p; do
do while [[ $(stat -c%s "${p}" || 0) -ge 512000 ]]; do
while [[ $(stat -c%s "${p}" || 0) -ge 512000 ]] frameamount=$(($(exiftool -b -FrameCount "${p}" || 1) - 1))
do nice -n 15 gifsicle "${p}" $(seq -f "#%g" 0 2 "${frameamount}") -O3 --lossy=80 --colors=255 -o "${p}"
frameamount=$(( $(exiftool -b -FrameCount "${p}" || 1) - 1 )) done
nice -n 15 gifsicle "${p}" $(seq -f "#%g" 0 2 "${frameamount}") -O3 --lossy=80 --colors=255 -o "${p}" done
done
done
) )
find . -type f -iname "*.png" -size +500k | ( find . -type f -iname "*.png" -size +500k | (
while read r while read r; do
do nice -n 15 oxipng -o max "${r}" &
nice -n 15 oxipng -o max "${r}" & if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]]; then
if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]] wait -n
then fi
wait -n done
fi wait
done;
wait
) )
#compress-webp #compress-webp
find . -type f -iname "*.webp" -size +50k | ( find . -type f -iname "*.webp" -size +50k | (
while read s while read s; do
do #If file is not animated
#If file is not animated if ! grep -v -q -e "ANIM" -e "ANMF" "${s}"; then
if ! grep -v -q -e "ANIM" -e "ANMF" "${s}" cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp
then if [[ -f /tmp/"${s##.*\/}"_temp.webp ]]; then
cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp || 0)
if [ -f /tmp/"${s##.*\/}"_temp.webp ] size_original=$(stat -c%s "${s}" || 0)
then if [[ "${size_original}" -gt "${size_new}" ]]; then
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp || 0) mv /tmp/"${s##.*\/}"_temp.webp "${s}"
size_original=$(stat -c%s "${s}" || 0) else
if [ "$size_original" -gt "$size_new" ] rm /tmp/"${s##.*\/}"_temp.webp
then fi
mv /tmp/"${s##.*\/}"_temp.webp "$s" fi
else fi
rm /tmp/"${s##.*\/}"_temp.webp done
fi wait
fi
fi
done;
wait
) )