chore: Add even more Shellcheck suggestions

This commit is contained in:
Carlos Solís 2025-01-24 19:34:48 +00:00
parent 06356b6d1c
commit efe59ecfbf
6 changed files with 86 additions and 86 deletions

View file

@ -2,14 +2,14 @@
interval=14 interval=14
sudo mariadb friendica --verbose -v -v --show-warnings --execute=\ sudo mariadb friendica --verbose -v -v --show-warnings --execute=\
"DELETE FROM \`post-origin\` WHERE (\`parent-uri-id\`, \`uid\`) IN (SELECT \`uri-id\`, \`uid\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \ "DELETE FROM \`post-origin\` WHERE (\`parent-uri-id\`, \`uid\`) IN (SELECT \`uri-id\`, \`uid\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \
\`deleted\` AND \`edited\` < (CURDATE() - INTERVAL $interval DAY));\ \`deleted\` AND \`edited\` < (CURDATE() - INTERVAL ${interval} DAY));\
DELETE FROM \`post-user\` WHERE \`gravity\` = 0 AND \ DELETE FROM \`post-user\` WHERE \`gravity\` = 0 AND \
\`deleted\` AND \`edited\` < (CURDATE() - INTERVAL $interval DAY);\ \`deleted\` AND \`edited\` < (CURDATE() - INTERVAL ${interval} DAY);\
DELETE FROM \`post\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`);\ DELETE FROM \`post\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`);\
DELETE FROM \`post-content\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`);\ DELETE FROM \`post-content\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`);\
DELETE FROM \`post-thread\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`);\ DELETE FROM \`post-thread\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post-user\`);\
DELETE FROM \`post-user\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post\`);\ DELETE FROM \`post-user\` WHERE \`uri-id\` NOT IN (SELECT \`uri-id\` FROM \`post\`);\
DELETE FROM \`item-uri\` WHERE \`id\` IN (SELECT \`uri-id\` FROM \`post-thread\` WHERE \`received\` < (CURDATE() - INTERVAL $interval DAY) \ DELETE FROM \`item-uri\` WHERE \`id\` IN (SELECT \`uri-id\` FROM \`post-thread\` WHERE \`received\` < (CURDATE() - INTERVAL ${interval} DAY) \
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-thread-user\` \ 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\`) \ WHERE (\`mention\` OR \`starred\` OR \`wall\`) AND \`uri-id\` = \`post-thread\`.\`uri-id\`) \
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-category\` \ AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-category\` \
@ -24,11 +24,11 @@ DELETE FROM \`item-uri\` WHERE \`id\` IN (SELECT \`uri-id\` FROM \`post-thread\`
WHERE (\`origin\` OR \`event-id\` != 0 OR \`post-type\` = 128) AND \`parent-uri-id\` = \`post-thread\`.\`uri-id\`) \ WHERE (\`origin\` OR \`event-id\` != 0 OR \`post-type\` = 128) AND \`parent-uri-id\` = \`post-thread\`.\`uri-id\`) \
AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-content\` \ AND NOT \`uri-id\` IN (SELECT \`uri-id\` FROM \`post-content\` \
WHERE \`resource-id\` != 0 AND \`uri-id\` = \`post-thread\`.\`uri-id\`));\ WHERE \`resource-id\` != 0 AND \`uri-id\` = \`post-thread\`.\`uri-id\`));\
DELETE FROM \`item-uri\` WHERE \`id\` IN (SELECT \`uri-id\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`uid\` = 0 AND \`received\` < (CURDATE() - INTERVAL $interval DAY) \ DELETE FROM \`item-uri\` WHERE \`id\` IN (SELECT \`uri-id\` FROM \`post-user\` WHERE \`gravity\` = 0 AND \`uid\` = 0 AND \`received\` < (CURDATE() - INTERVAL ${interval} DAY) \
AND NOT \`uri-id\` IN (\ 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\`\ 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 (\ ) 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)\ 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)\
)\ )\
);\ );\
DELETE FROM \`attach\` WHERE \`id\` NOT IN (SELECT \`attach-id\` FROM \`post-media\`);\ DELETE FROM \`attach\` WHERE \`id\` NOT IN (SELECT \`attach-id\` FROM \`post-media\`);\

View file

@ -3,43 +3,43 @@ db="friendica"
tmpfile="/tmp/sitesdown.txt" tmpfile="/tmp/sitesdown.txt"
idsdownfile="/tmp/idsdown.txt" idsdownfile="/tmp/idsdown.txt"
loop_1() { loop_1() {
sitereq=$(curl -s -L --head -m 10 --request GET "$a") sitereq=$(curl -s -L --head -m 10 --request GET "${a}")
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
} }
loop_2() { loop_2() {
echo "Finding users for $b" echo "Finding users for ${b}"
mariadb "$db" -N -B -q -e "select \`id\` from contact c where \"$b\" not in (select \`contact-id\` from group_member) and (c.baseurl = \"$b\" or c.url = \"$b\")" | sudo tee -a "$idsdownfile" &> /dev/null mariadb "${db}" -N -B -q -e "select \`id\` from contact c where \"${b}\" not in (select \`contact-id\` from group_member) and (c.baseurl = \"${b}\" or c.url = \"${b}\")" | sudo tee -a "${idsdownfile}" &> /dev/null
} }
loop_3() { loop_3() {
echo "Deleting user $lineb" echo "Deleting user ${lineb}"
mariadb "$db" -N -B -q -e "delete from \`contact\` where \`id\` = $lineb" mariadb "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}"
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\` 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-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-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-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 \`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 \`photo\` where \`contact-id\` = ${lineb}"
mariadb "$db" -N -B -q -e "delete from \`contact\` where \`id\` = $lineb" mariadb "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}"
} }
#Check if our dependencies are installed #Check if our dependencies are installed
if [[ $(type curl) && $(type mariadb) && $(type date) ]] if [[ -n $(type curl) && -n $(type mariadb) && -n $(type date) ]]
then then
date date
if [[ ! -f "$tmpfile" ]] if [[ ! -f "${tmpfile}" ]]
then then
echo "Listing sites" echo "Listing sites"
sites=($(mariadb "$db" -N -B -q -e "select distinct baseurl from contact" | sort -n | uniq )) sites=($(mariadb "${db}" -N -B -q -e "select distinct baseurl from contact" | sort -n | uniq ))
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 $(expr $(getconf _NPROCESSORS_ONLN)*2) ]] if [[ $(jobs -r -p | wc -l) -ge $(expr $(getconf _NPROCESSORS_ONLN)*2) ]]
then then
wait -n wait -n
@ -49,14 +49,14 @@ then
fi fi
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[@]}" for b in "${sitesdown[@]}"
do do
loop_2 "$b" & loop_2 "${b}" &
if [[ $(jobs -r -p | wc -l) -ge $(expr $(getconf _NPROCESSORS_ONLN)/2) ]] if [[ $(jobs -r -p | wc -l) -ge $(expr $(getconf _NPROCESSORS_ONLN)/2) ]]
then then
wait -n wait -n
@ -67,14 +67,14 @@ then
fi fi
while read -r lineb; do while read -r lineb; do
#The community no longer exists, delete #The community no longer exists, delete
loop_3 "$lineb" & loop_3 "${lineb}" &
if [[ $(jobs -r -p | wc -l) -ge $(expr $(getconf _NPROCESSORS_ONLN)/2) ]] if [[ $(jobs -r -p | wc -l) -ge $(expr $(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

@ -11,15 +11,15 @@ folder=/var/www/friendica
folderescaped=${folder////\\/} folderescaped=${folder////\\/}
tmpfile=/tmp/friendica-fix-avatar-permissions.txt tmpfile=/tmp/friendica-fix-avatar-permissions.txt
avatarfolder=avatar avatarfolder=avatar
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/-.*/\*/g" | ( grep -e "https://${site}/${avatarfolder}/" "${tmpfile}" | sed -e "s/.*${site}/${folderescaped}/g" -e "s/-.*/\*/g" | (
while read n while read n
do do
find "$folder/$avatarfolder" -path "$n" -type f | ( find "${folder}/${avatarfolder}" -path "${n}" -type f | (
while read p while read p
do do
if [[ "${p}" =~ ".jpeg" || "${p}" =~ ".jpg" ]] if [[ "${p}" =~ ".jpeg" || "${p}" =~ ".jpg" ]]
@ -58,11 +58,11 @@ grep -e "https://$site/$avatarfolder/" "$tmpfile" | sed -e "s/.*$site/$folderesc
if [[ "${p}" =~ ".webp" ]] if [[ "${p}" =~ ".webp" ]]
then then
cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null 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") size_new=$(stat -c%s "/tmp/temp.webp")
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}" mv /tmp/temp.webp "${p}"
else else
@ -75,10 +75,10 @@ grep -e "https://$site/$avatarfolder/" "$tmpfile" | sed -e "s/.*$site/$folderesc
done done
) )
wait wait
rm "$tmpfile" 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 sudo chown -v $user:$group #&> /dev/null /usr/bin/find "${folder}"/avatar -depth -not -user "${user}" -or -not -group "${group}" -print0 | xargs -0 -r sudo 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 sudo 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 sudo 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 sudo 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 sudo chmod -v "${fileperm}" #&> /dev/null

View file

@ -1,57 +1,57 @@
#!/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}"
#echo "UpdateContact $camax" #echo "UpdateContact $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}"
#echo "ContactDiscovery $cbmax" #echo "ContactDiscovery $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
printf "\rFetchFeaturedPosts\t%s\n\r" "$ccmax" printf "\rFetchFeaturedPosts\t%s\n\r" "${ccmax}"
#echo "FetchFeaturedPosts $ccmax" #echo "FetchFeaturedPosts $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}"
#echo "UpdateGServer $cdmax" #echo "UpdateGServer $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

@ -8,49 +8,49 @@ folder=/var/www/friendica
folderavatar=/var/www/friendica/avatar folderavatar=/var/www/friendica/avatar
loop() { 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}"
return $d return "${d}"
} }
date 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 ]] if [[ -d ${x} ]]
then 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) / 1 )) ]] if [[ $(jobs -r -p | wc -l) -ge $(( $(getconf _NPROCESSORS_ONLN) / 1 )) ]]
then then
wait -n wait -n
fi fi
done < <(sudo find "$x" -type f -mtime -8) done < <(sudo find "${x}" -type f -mtime -8)
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

@ -40,13 +40,13 @@ IFS="
while read s while read s
do do
nice -n 15 cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp nice -n 15 cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp
if [ -f /tmp/"${s##.*\/}"_temp.webp ] if [[ -f /tmp/"${s##.*\/}"_temp.webp ]]
then then
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp) size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp)
size_original=$(stat -c%s "${s}") size_original=$(stat -c%s "${s}")
if [ "$size_original" -gt "$size_new" ] if [[ "${size_original}" -gt "${size_new}" ]]
then then
mv /tmp/"${s##.*\/}"_temp.webp "$s" mv /tmp/"${s##.*\/}"_temp.webp "${s}"
else else
rm /tmp/"${s##.*\/}"_temp.webp rm /tmp/"${s##.*\/}"_temp.webp
fi fi