chore: Apply shellcheck/shfmt suggestions
This commit is contained in:
parent
e3962133f0
commit
59be4584d5
5 changed files with 32 additions and 42 deletions
|
@ -5,50 +5,39 @@ IFS="
|
||||||
folder=/var/www/friendica
|
folder=/var/www/friendica
|
||||||
storagefolder=storage
|
storagefolder=storage
|
||||||
|
|
||||||
loop_1(){
|
loop_1() {
|
||||||
t=$(file "${p}")
|
t=$(file "${p}")
|
||||||
if [[ "${t}" =~ JPEG ]]
|
if [[ "${t}" =~ JPEG ]]; then
|
||||||
then
|
|
||||||
nice -n 10 jpegoptim -m 76 "${p}" #&> /dev/null
|
nice -n 10 jpegoptim -m 76 "${p}" #&> /dev/null
|
||||||
elif [[ "${t}" =~ GIF ]]
|
elif [[ "${t}" =~ 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
|
|
||||||
nice -n 10 gifsicle "${p}" $(seq -f "#%g" 0 2 99) -O3 --lossy=80 --colors=255 -o "${p}" #&> /dev/null
|
nice -n 10 gifsicle "${p}" $(seq -f "#%g" 0 2 99) -O3 --lossy=80 --colors=255 -o "${p}" #&> /dev/null
|
||||||
done
|
done
|
||||||
elif [[ "${t}" =~ PNG ]]
|
elif [[ "${t}" =~ PNG ]]; then
|
||||||
then
|
|
||||||
nice -n 10 oxipng -o max "${p}" #&> /dev/null
|
nice -n 10 oxipng -o max "${p}" #&> /dev/null
|
||||||
elif [[ "${p}" =~ Web/P ]]
|
elif [[ "${p}" =~ Web/P ]]; then
|
||||||
then
|
#If file is not animated
|
||||||
#If file is not animated
|
if grep -v -q -e "ANIM" -e "ANMF" "${p}"; then
|
||||||
if [[ $(grep -v -q -e "ANIM" -e "ANMF" "${p}") ]]
|
nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
|
||||||
then
|
if [[ -f /tmp/temp.webp ]]; then
|
||||||
nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
|
size_new=$(stat -c%s "/tmp/temp.webp" || 0)
|
||||||
if [[ -f /tmp/temp.webp ]]
|
size_original=$(stat -c%s "${p}")
|
||||||
then
|
if [[ "${size_original}" -gt "${size_new}" ]]; then
|
||||||
size_new=$(stat -c%s "/tmp/temp.webp" || 0 )
|
mv /tmp/temp.webp "${p}" #&> /dev/null
|
||||||
size_original=$(stat -c%s "${p}")
|
else
|
||||||
if [[ "${size_original}" -gt "${size_new}" ]]
|
rm /tmp/temp.webp #&> /dev/null
|
||||||
then
|
fi
|
||||||
mv /tmp/temp.webp "${p}" #&> /dev/null
|
fi
|
||||||
else
|
fi
|
||||||
rm /tmp/temp.webp #&> /dev/null
|
fi
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c=0
|
find "${folder}/${storagefolder}" -depth -mindepth 2 -type f -size +50k -not -iname "index.html" | (
|
||||||
find "${folder}/${storagefolder}" -depth -mindepth 2 -type f -size +300k -not -iname "index.html" | (
|
while read -r p; do
|
||||||
while read -r p
|
|
||||||
do
|
|
||||||
loop_1 "${p}" &
|
loop_1 "${p}" &
|
||||||
until [[ $(jobs -r -p | wc -l) -lt $(( $(getconf _NPROCESSORS_ONLN) / 2 )) ]]
|
until [[ $(jobs -r -p | wc -l) -lt $(($(getconf _NPROCESSORS_ONLN) / 2)) ]]; do
|
||||||
do
|
|
||||||
wait -n
|
wait -n
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
db="friendica"
|
db="friendica"
|
||||||
idsdownfile="/tmp/idsdown.txt"
|
|
||||||
url=friendica.example.net
|
url=friendica.example.net
|
||||||
avatarfolder=/var/www/friendica/avatar
|
avatarfolder=/var/www/friendica/avatar
|
||||||
avatarfolderescaped=${avatarfolder////\\/}
|
avatarfolderescaped=${avatarfolder////\\/}
|
||||||
|
@ -11,7 +10,7 @@ loop() {
|
||||||
#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; do
|
"${dbengine}" "${db}" -N -B -q -e "select \`photo\`, \`thumb\`, \`micro\` from \`contact\` where \`id\` = ${lineb}" | while read -r photo thumb micro; do
|
||||||
#If stored in avatar folder
|
#If stored in avatar folder
|
||||||
if [[ -z $(echo "${photo}" | grep "${url}/avatar") ]]; then
|
if ! grep -v -q "${url}/avatar" <(echo "${photo}"); 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")
|
||||||
rm -rfv "${phototrimmed}"
|
rm -rfv "${phototrimmed}"
|
||||||
thumbtrimmed=$(echo "${thumb}" | sed -e "s/https:\/\/${url}\/avatar/${avatarfolderescaped}/g" -e "s/\?ts.*//g")
|
thumbtrimmed=$(echo "${thumb}" | sed -e "s/https:\/\/${url}\/avatar/${avatarfolderescaped}/g" -e "s/\?ts.*//g")
|
||||||
|
|
|
@ -25,7 +25,7 @@ loop_3() {
|
||||||
#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; do
|
"${dbengine}" "${db}" -N -B -q -e "select \`photo\`, \`thumb\`, \`micro\` from \`contact\` where \`id\` = ${lineb}" | while read -r photo thumb micro; do
|
||||||
#If stored in avatar folder
|
#If stored in avatar folder
|
||||||
if $(echo "${photo}" | grep -q "${url}/avatar"); then #isavatar=$(grep -q "${url}/avatar" <<< "${photo}")
|
if grep -v -q "${url}/avatar" <(echo "${photo}"); then
|
||||||
#if [[ -z "${isavatar}" ]]
|
#if [[ -z "${isavatar}" ]]
|
||||||
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}"
|
||||||
|
|
|
@ -42,7 +42,6 @@ until [[ $((nt + limit)) -gt ${dbcount} ]]; do
|
||||||
batch=$(("${batch}" + 1))
|
batch=$(("${batch}" + 1))
|
||||||
#Read lastid outside of the loop with a temporary file
|
#Read lastid outside of the loop with a temporary file
|
||||||
if [[ -f /tmp/lastid && -s /tmp/lastid ]]; then
|
if [[ -f /tmp/lastid && -s /tmp/lastid ]]; then
|
||||||
count=0
|
|
||||||
while read -r n_i nt_i lastid_i; do
|
while read -r n_i nt_i lastid_i; do
|
||||||
if [[ -s "${n_i}" ]]; then
|
if [[ -s "${n_i}" ]]; then
|
||||||
n="${n_i}"
|
n="${n_i}"
|
||||||
|
@ -116,9 +115,11 @@ until [[ $((nt + limit)) -gt ${dbcount} ]]; do
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
error_found=1
|
error_found=1
|
||||||
k_photo_delta=$(echo "${photo}" | sed -e "s/.*?ts=//g")
|
k_photo_delta="${photo//.*?ts=//}"
|
||||||
|
#k_photo_delta=$(echo "${photo}" | sed -e "s/.*?ts=//g")
|
||||||
else
|
else
|
||||||
k_photo_original_time=$(echo "${photo}" | sed -e "s/.*?ts=//g")
|
#k_photo_original_time=$(echo "${photo}" | sed -e "s/.*?ts=//g")
|
||||||
|
k_photo_original_time="${photo//.*?ts=//}"
|
||||||
k_photo_found_time=$(stat -c%W "${k_photo}")
|
k_photo_found_time=$(stat -c%W "${k_photo}")
|
||||||
k_photo_delta=$((k_photo_found_time - k_photo_original_time))
|
k_photo_delta=$((k_photo_found_time - k_photo_original_time))
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -8,6 +8,7 @@ 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
|
||||||
|
folderescaped=${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} ]]; then
|
if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then
|
||||||
|
@ -23,7 +24,7 @@ loop() {
|
||||||
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
|
||||||
|
@ -33,7 +34,7 @@ sudo find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d | while read
|
||||||
#If the directory still exists
|
#If the directory still exists
|
||||||
if [[ -d "${x}" ]]; then
|
if [[ -d "${x}" ]]; 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; do
|
while read -r y; do
|
||||||
|
|
Loading…
Add table
Reference in a new issue