feat: Optimize parallelization
This commit is contained in:
parent
3d08dec903
commit
847a6337ad
1 changed files with 39 additions and 47 deletions
|
@ -2,7 +2,7 @@
|
|||
IFS="
|
||||
"
|
||||
#Set your parameters here
|
||||
site=hub.example.net
|
||||
site=friendica.example.net
|
||||
user=friendica
|
||||
group=friendica
|
||||
fileperm=644
|
||||
|
@ -13,12 +13,35 @@ tmpfile=/tmp/friendica-fix-avatar-permissions.txt
|
|||
avatarfolder=avatar
|
||||
|
||||
loop_1(){
|
||||
gifsicle --batch -O3 --lossy=80 --colors=255 "${p}" #&> /dev/null
|
||||
#Specific compression for large GIF files
|
||||
while [[ $(stat -c%s "${p}") -ge 512000 ]]
|
||||
do
|
||||
gifsicle "${p}" $(seq -f "#%g" 0 2 99) -O3 --lossy=80 --colors=255 -o "${p}" #&> /dev/null
|
||||
done
|
||||
if [[ "${p}" =~ .jpeg || "${p}" =~ .jpg ]]
|
||||
then
|
||||
nice -n 10 jpegoptim -m 76 "${p}" #&> /dev/null
|
||||
elif [[ "${p}" =~ .gif ]]
|
||||
then
|
||||
nice -n 10 gifsicle --batch -O3 --lossy=80 --colors=255 "${p}" #&> /dev/null
|
||||
#Specific compression for large GIF files
|
||||
while [[ $(stat -c%s "${p}") -ge 512000 ]]
|
||||
do
|
||||
nice -n 10 gifsicle "${p}" $(seq -f "#%g" 0 2 99) -O3 --lossy=80 --colors=255 -o "${p}" #&> /dev/null
|
||||
done
|
||||
elif [[ "${p}" =~ .png ]]
|
||||
then
|
||||
nice -n 10 oxipng -o max "${p}" #&> /dev/null
|
||||
elif [[ "${p}" =~ .webp ]]
|
||||
then
|
||||
nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
|
||||
if [[ -f /tmp/temp.webp ]]
|
||||
then
|
||||
size_new=$(stat -c%s "/tmp/temp.webp")
|
||||
size_original=$(stat -c%s "${p}")
|
||||
if [[ "${size_original}" -gt "${size_new}" ]]
|
||||
then
|
||||
mv /tmp/temp.webp "${p}"
|
||||
else
|
||||
rm /tmp/temp.webp
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
cd "${folder}" || exit
|
||||
|
@ -26,51 +49,20 @@ if [[ ! -f "${tmpfile}" ]]
|
|||
then
|
||||
sudo -u "${user}" bin/console movetoavatarcache | sudo tee "${tmpfile}" #&> /dev/null
|
||||
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/?ts=.*//g" | (
|
||||
while read -r n
|
||||
do
|
||||
find "${folder}/${avatarfolder}" -path "${n}" -type f | (
|
||||
while read -r p
|
||||
while read -r i
|
||||
do
|
||||
if [[ "${p}" =~ .jpeg || "${p}" =~ .jpg ]]
|
||||
then
|
||||
jpegoptim -m 76 "${p}" & #&> /dev/null
|
||||
for p in "${i}" "${i//-320/-80}" "${i//-320/-48}"
|
||||
do
|
||||
loop_1 "${p}" &
|
||||
if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]]
|
||||
then
|
||||
wait -n
|
||||
fi
|
||||
fi
|
||||
if [[ "${p}" =~ .gif ]]
|
||||
then
|
||||
loop_1 "${n}" & #&> /dev/null
|
||||
if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]]
|
||||
then
|
||||
wait -n
|
||||
fi
|
||||
fi
|
||||
if [[ "${p}" =~ .png ]]
|
||||
then
|
||||
oxipng -o max "${p}" & #&> /dev/null
|
||||
if [[ $(jobs -r -p | wc -l) -ge $(getconf _NPROCESSORS_ONLN) ]]
|
||||
then
|
||||
wait -n
|
||||
fi
|
||||
fi
|
||||
if [[ "${p}" =~ .webp ]]
|
||||
then
|
||||
cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
|
||||
if [[ -f /tmp/temp.webp ]]
|
||||
then
|
||||
size_new=$(stat -c%s "/tmp/temp.webp")
|
||||
size_original=$(stat -c%s "${p}")
|
||||
if [[ "${size_original}" -gt "${size_new}" ]]
|
||||
then
|
||||
mv /tmp/temp.webp "${p}"
|
||||
else
|
||||
rm /tmp/temp.webp
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
)
|
||||
done
|
||||
|
@ -80,6 +72,6 @@ rm "${tmpfile}"
|
|||
/usr/bin/find "${folder}"/avatar -type d -empty -delete
|
||||
/usr/bin/chmod "${folderperm}" "${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 -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 -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 f -and -not -type d -and -not -perm "${fileperm}" -print0 | xargs -0 -r chmod -v "${fileperm}" #&> /dev/null
|
||||
|
|
Loading…
Add table
Reference in a new issue