update script and add cronjob

This commit is contained in:
VirtuBox 2018-07-28 22:55:16 +02:00
parent 1fa54b67b7
commit 8cc9749423
4 changed files with 37 additions and 5 deletions

20
cron/optimize-cron.sh Normal file
View File

@ -0,0 +1,20 @@
input="sites.csv"
while IFS='|' read -r f1 f2
do
imagepath="$f2"
# optimize jpg images created in the last 24 hours
find $imagepath -iname "*.jp*" -ctime 0 -print0 | xargs -0 jpegoptim --quiet --strip-all -m76
# optimize png images created in the last 24 hours
find $imagepath -iname '*.png' -ctime 0 -print0 | xargs -0 optipng -o7 -quiet -preserve
# convert png to webp
find $imagepath -iname "*.png" -ctime 0 -print0 | xargs -0 -I {} \
bash -c 'webp_version="$0".webp
if [ ! -f "$webp_version" ]; then
{ cwebp -quiet -lossless {} -o {}.webp; }
fi'
find $imagepath -iname "*.jp*" -ctime 0 -print0 | xargs -0 -I {} \
bash -c 'webp_version="$0".webp
if [ ! -f "$webp_version" ]; then
{ cwebp -quiet -lossless {} -o {}.webp; }
fi'
done < "$input"

2
cron/sites.csv Normal file
View File

@ -0,0 +1,2 @@
1|/var/www/yoursite.tld/htdocs/wp-content/uploads
2|/var/www/yourothersite.tld/htdocs/wp-content/uploads
1 1 /var/www/yoursite.tld/htdocs/wp-content/uploads
2 2 /var/www/yourothersite.tld/htdocs/wp-content/uploads

13
install-optipng.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
sudo apt-get install build-essential libpng-dev -y
cd /usr/local/src
OPTIPNGLATEST=$(wget http://optipng.sourceforge.net/ -O - | grep tar.gz | awk -F "[\"]" '{print $4}')
wget $OPTIPNGLATEST -O optipng.tar.gz
tar -xf optipng.tar.gz
cd optipng-*
./configure --prefix=/usr
make -j "$(nproc)"
sudo make install

View File

@ -46,8 +46,7 @@ find $imagepath -iname '*.png' -print0 | xargs -0 optipng -o7 -quiet -preserve
# convert png to webp
webpconvert() {
find $imagepath -iname "*.png" -print0 | xargs -0 -I {} \
bash -c '
webp_version="$0".webp
bash -c 'webp_version="$0".webp
if [ ! -f "$webp_version" ]; then
{ cwebp -quiet -lossless {} -o {}.webp; }
fi'
@ -57,9 +56,7 @@ fi'
# convert jpg to webp
find $imagepath -iname "*.jp*" -print0 | xargs -0 -I {} \
bash -c '
webp_version="$0".webp
bash -c 'webp_version="$0".webp
if [ ! -f "$webp_version" ]; then
{ cwebp -quiet -lossless {} -o {}.webp; }
fi'