2025-01-24 19:16:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
IFS="
|
|
|
|
"
|
2025-02-12 21:27:45 +00:00
|
|
|
dbengine=""
|
|
|
|
if [[ -n $(type mariadb) ]]; then
|
|
|
|
dbengine="mariadb"
|
|
|
|
elif [[ -n $(type mysql) ]]; then
|
|
|
|
dbengine="mysql"
|
|
|
|
else
|
|
|
|
exit
|
|
|
|
fi
|
2025-01-24 19:16:21 +00:00
|
|
|
#Set your parameters here
|
2025-02-03 03:47:09 +00:00
|
|
|
url=friendica.example.net
|
2025-01-24 19:16:21 +00:00
|
|
|
db=friendica
|
|
|
|
folder=/var/www/friendica
|
|
|
|
folderavatar=/var/www/friendica/avatar
|
|
|
|
loop() {
|
|
|
|
#Parse each file in folder
|
2025-02-07 16:21:07 +00:00
|
|
|
folderescaped=${folder////\\/}
|
2025-01-24 19:34:48 +00:00
|
|
|
ky=$(echo "${y}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g")
|
2025-02-12 21:27:45 +00:00
|
|
|
f=$("${dbengine}" "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1")
|
2025-02-05 14:59:57 +00:00
|
|
|
if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then
|
2025-02-09 02:30:01 +00:00
|
|
|
rm -rvf "${y}" &
|
2025-02-07 19:00:48 +00:00
|
|
|
if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then
|
|
|
|
wait -n
|
|
|
|
fi
|
2025-02-07 18:59:25 +00:00
|
|
|
|
2025-02-05 14:59:57 +00:00
|
|
|
d=$((d + 1))
|
2025-01-24 19:16:21 +00:00
|
|
|
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-02-09 02:30:01 +00:00
|
|
|
#indexlength=$((49 + ${#url}))
|
2025-02-12 21:27:45 +00:00
|
|
|
#"${dbengine}" "${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-02-09 02:30:01 +00:00
|
|
|
while read -r x; do
|
2025-02-05 14:59:57 +00:00
|
|
|
n=$((n + 1))
|
2025-01-24 19:16:21 +00:00
|
|
|
#If the directory still exists
|
2025-02-05 14:59:57 +00:00
|
|
|
if [[ -d "${x}" ]]; then
|
2025-02-09 02:30:01 +00:00
|
|
|
m=0
|
|
|
|
while read -r y; do
|
|
|
|
m=$((m + 1))
|
|
|
|
loop "${x}" "${m}" "${n}" "${d}" "${y}" &
|
|
|
|
if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then
|
|
|
|
wait -n
|
|
|
|
fi
|
|
|
|
done < <(find "${x}" -type f)
|
2025-02-05 14:59:57 +00:00
|
|
|
fi
|
2025-02-09 02:30:01 +00:00
|
|
|
done < <(find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d)
|
2025-02-12 21:27:45 +00:00
|
|
|
#"${dbengine}" "${db}" -e "alter table contact drop index photo_index"
|
2025-01-24 19:16:21 +00:00
|
|
|
date
|