2025-01-24 19:16:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
IFS="
|
|
|
|
"
|
|
|
|
#Set your parameters here
|
|
|
|
url=hub.example.net
|
|
|
|
db=friendica
|
|
|
|
folder=/var/www/friendica
|
|
|
|
folderavatar=/var/www/friendica/avatar
|
|
|
|
loop() {
|
|
|
|
#Parse each file in folder
|
2025-01-24 19:34:48 +00:00
|
|
|
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")
|
|
|
|
if [[ $? -eq 0 && -z ${f} && -f ${y} ]]
|
2025-01-24 19:16:21 +00:00
|
|
|
then
|
2025-01-24 19:34:48 +00:00
|
|
|
ls -lh "${y}"
|
|
|
|
sudo rm -rf "${y}"
|
2025-01-24 19:16:21 +00:00
|
|
|
d=$(( d + 1 ))
|
|
|
|
fi
|
|
|
|
#printf "\rPhotos: %s\tFolder %s\tEntry %s " "$d" "$n" "$m"
|
2025-01-24 19:34:48 +00:00
|
|
|
printf "\rFolder %s\tEntry %s " "${n}" "${m}"
|
|
|
|
return "${d}"
|
2025-01-24 19:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
date
|
|
|
|
#Go to the Friendica installation
|
2025-01-24 19:34:48 +00:00
|
|
|
cd "${folderavatar}" || exit
|
2025-01-24 19:16:21 +00:00
|
|
|
let "indexlength=37+${#url}"
|
|
|
|
(( indexlength=49+${#url} ))
|
2025-01-24 19:34:48 +00:00
|
|
|
sudo mariadb "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))"
|
2025-01-24 19:16:21 +00:00
|
|
|
n=0
|
|
|
|
d=0
|
2025-01-24 19:34:48 +00:00
|
|
|
sudo find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d | while read -r x
|
2025-01-24 19:16:21 +00:00
|
|
|
do
|
|
|
|
n=$(( n + 1 ))
|
|
|
|
#If the directory still exists
|
2025-01-24 19:34:48 +00:00
|
|
|
if [[ -d "${x}" ]]
|
2025-01-24 19:16:21 +00:00
|
|
|
then
|
|
|
|
folderescaped=${folder////\\/}
|
2025-01-24 19:34:48 +00:00
|
|
|
kx=$(echo "${x}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g")
|
|
|
|
if [[ -d ${x} ]]
|
2025-01-24 19:16:21 +00:00
|
|
|
then
|
|
|
|
m=0
|
|
|
|
while read -r y
|
|
|
|
do
|
|
|
|
m=$(( m + 1 ))
|
2025-01-24 19:34:48 +00:00
|
|
|
loop "${x}" "${m}" "${n}" "${d}" &
|
2025-01-24 19:16:21 +00:00
|
|
|
if [[ $(jobs -r -p | wc -l) -ge $(( $(getconf _NPROCESSORS_ONLN) / 1 )) ]]
|
|
|
|
then
|
|
|
|
wait -n
|
|
|
|
fi
|
2025-01-24 19:34:48 +00:00
|
|
|
done < <(sudo find "${x}" -type f -mtime -8)
|
2025-01-24 19:16:21 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2025-01-24 19:34:48 +00:00
|
|
|
sudo mariadb "${db}" -e "alter table contact drop index photo_index"
|
2025-01-24 19:16:21 +00:00
|
|
|
date
|