Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Added support for working script on MacOS 10.10+ with automatic install dependences
  • Loading branch information
zevilz committed Feb 25, 2018
2 parents b7e34a0 + 189aa81 commit 67de2cd
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 20 deletions.
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# zImageOptimizer [![Version](https://img.shields.io/badge/version-v0.8.1-orange.svg)](https://github.com/zevilz/zImageOptimizer/releases/tag/0.8.1) [![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.paypal.me/zevilz)
# zImageOptimizer [![Version](https://img.shields.io/badge/version-v0.9.0-orange.svg)](https://github.com/zevilz/zImageOptimizer/releases/tag/0.9.0) [![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.paypal.me/zevilz)

Simple bash script for lossless image optimizing JPEG, PNG and GIF images in specified directory include subdirectories on Linux and FreeBSD.
Simple bash script for lossless image optimizing JPEG, PNG and GIF images in specified directory include subdirectories on Linux, MacOS and FreeBSD.

## Features
- lossless image optimization with small image size in output;
Expand Down Expand Up @@ -45,14 +45,14 @@ bash zImageOptimizer.sh --path=/path/to/files
Supported options:
- -h (--help) - shows help,
- -v (--version) - shows script version,
- -p (--path) - specify input directory (usage: `-p <dir> | --path=<dir>`),
- -p (--path) - specify full path to input directory (usage: `-p <dir> | --path=<dir>`),
- -q (--quiet) - execute script without any questions and users actions,
- -l (--less) - don't show optimizing process,
- -c (--check-only) - check tools with an opportunity to install dependences,
- -t (--time) - set period for which to look for files by last modified time (usage: `-t <period> | --time=<period>`),
- -n (--new-only) - use time marker file for looking new images only,
- -m (--time-marker) - set custom path or custom filename of time marker file (usage: `-m <name|path> | --time-marker=<name|path>`),
- -tmp (--tmp-path) - set custom directory path for temporary files (usage: `-tmp <dir> | --tmp-path=<dir>`).
- -m (--time-marker) - set custom full path or custom filename of time marker file (usage: `-m <name|path> | --time-marker=<name|path>`),
- -tmp (--tmp-path) - set custom directory full path for temporary files (usage: `-tmp <dir> | --tmp-path=<dir>`).

Notices:
- you may combine options;
Expand Down Expand Up @@ -152,7 +152,7 @@ bash zImageOptimizer.sh -p /path/to/files -tmp /custom/path/to/temporary/directo
## Automatical installing dependences
Notice: curent user must be root or user with sudo access.

Start script in the optimization mode (-p|--path) or checking tools mode (-c|--check-only, recommended) if you want to install dependences automatically. It check installed tools and printing choise option dialog if one or more tools not found. Select option **Install dependences and exit** by typing appropriate number and press enter. Script install dependences based on your platform, distribution and package manager. After that restart script to recheck installed tools.
Start script in the optimization mode (-p|--path) or checking tools mode (-c|--check-only, recommended) if you want to install dependences automatically. It check installed tools and printing choise option dialog if one or more tools not found. Select option **Install dependences and exit** by typing appropriate number and press enter. Script install dependences based on your platform, distribution and package manager. You may need to enter password and confirm actions during installation dependences. After that restart script to recheck installed tools.

Supported on:
- DEB-based linux distributions (i686/amd64)
Expand All @@ -163,6 +163,7 @@ Supported on:
- CentOS 6+
- Fedora 24+
- FreeBSD 10.3 / 10.4 / 11.1 (i686/amd64)
- MacOS 10.10+

Tested on:
- DEB-based linux distributions
Expand All @@ -183,6 +184,8 @@ Tested on:
- FreeBSD
- 10.3 i686
- 11.1 amd64
- MacOS
- 10.10

If you have errors during installing dependences on supported platforms please contact me or open issue.

Expand Down Expand Up @@ -215,6 +218,18 @@ dnf install epel-release -y
dnf install jpegoptim libjpeg* pngcrush optipng advancecomp gifsicle wget autoconf automake libtool make bc -y
```

MacOS:

Install homebrew if not installed
```bash
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```

Install packages via homebrew
```bash
brew install jpegoptim libjpeg pngcrush optipng advancecomp gifsicle jonof/kenutils/pngout
```

FreeBSD:

Install following ports
Expand Down Expand Up @@ -295,22 +310,31 @@ You have not write access to directory /tmp. Tools djpeg and cjpeg use this dire
- [ ] add option for set quality for more small files in output
- [x] ~~add option for check tools only~~
- [x] ~~add support for optimize gif images~~
- [ ] add support for automatic install dependences on other platforms and distributions with other package managers
- [x] ~~add support for automatic install dependences on other platforms and distributions with other package managers~~
- [ ] add support for automatic install dependences on other linux distributions
- [ ] add support for parallel optimization
- [ ] even more to improve results of compression
- [ ] add SVG support
- [ ] add logging
- [ ] add Ansible playbook

## Contacts
- telegram [@zevilz](https://t.me/zevilz) (EN|RU)
- telegram chat [@zImageOptimizer](https://t.me/zImageOptimizer) (RU)

## Reviews
- [glashkoff.com](https://glashkoff.com/blog/manual/kak-optimizirovat-izobrazheniya-sayta/) (RU)

## Donations
Do you like script? Would you like to support its development? Feel free to donate

[![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.paypal.me/zevilz)

## Changelog
- 25.02.2018 - 0.9.0 - added support for working script on MacOS 10.10+ with automatic install dependences
- 24.02.2018 - 0.8.1 - [added new parameter, updated info after optimizing, small fixes and small code refactoring](https://github.com/zevilz/zImageOptimizer/releases/tag/0.8.1)
- 04.12.2017 - 0.8.0 - [new features, bugfixes and code refactoring](https://github.com/zevilz/zImageOptimizer/releases/tag/0.8.0)
- 30.11.2017 - 0.7.0 - added support for working script on FreeBSD, [bug fixes and more](https://github.com/zevilz/zImageOptimizer/releases/tag/0.7.0)
- 30.11.2017 - 0.7.0 - added support for working script on FreeBSD with automatic install dependences, [bug fixes and more](https://github.com/zevilz/zImageOptimizer/releases/tag/0.7.0)
- 28.11.2017 - 0.6.0 - added support for automatic install dependences on RHEL 6+ and Fedora 24+
- 25.11.2017 - 0.5.0 - bug fixes and code refactoring
- 25.11.2017 - 0.4.0 - added support for automatic install dependences on Debian 7.* and some bugfixes
Expand Down
66 changes: 54 additions & 12 deletions zImageOptimizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
# URL: https://github.com/zevilz/zImageOptimizer
# Author: Alexandr "zEvilz" Emshanov
# License: MIT
# Version: 0.8.1
# Version: 0.9.0

# Define default vars
BINARY_PATHS="/bin /usr/bin /usr/local/bin"
TMP_PATH="/tmp"
TOOLS="jpegoptim jpegtran djpeg cjpeg pngcrush optipng pngout advpng gifsicle"
DEPS_DEBIAN="jpegoptim libjpeg-progs pngcrush optipng advancecomp gifsicle wget autoconf automake libtool make bc"
DEPS_REDHAT="jpegoptim libjpeg* pngcrush optipng advancecomp gifsicle wget autoconf automake libtool make bc"
DEPS_MACOS="jpegoptim libjpeg pngcrush optipng advancecomp gifsicle jonof/kenutils/pngout"
GIT_URL="https://github.com/zevilz/zImageOptimizer"
TIME_MARKER_PATH=""
TIME_MARKER_NAME=".timeMarker"
Expand All @@ -22,6 +23,9 @@ MIN_VERSION_FEDORA=24
MIN_VERSION_RHEL=6
MIN_VERSION_CENTOS=6

# Min version MacOS (second digit; ex. 10.12.2 == 12).
MIN_VERSION_MACOS=10

# Spacese separated supported versions of distributions.
SUPPORTED_VERSIONS_FREEBSD="10.3 10.4 11.1"

Expand Down Expand Up @@ -179,8 +183,18 @@ installDeps()
# PLATFORM_PKG="slackware"
fi

# elif [[ "$OSTYPE" == "darwin"* ]]; then
# PLATFORM="macos"
elif [[ "$OSTYPE" == "darwin"* ]]; then

PLATFORM="macos"
PLATFORM_PKG="dmg"
PLATFORM_DISTRIBUTION="MacOS"

PLATFORM_ARCH=$(getconf LONG_BIT)

PLATFORM_VERSION="$(defaults read loginwindow SystemVersionStampAsString)"
if [[ $(echo $PLATFORM_VERSION | cut -d '.' -f2) -ge $MIN_VERSION_MACOS ]]; then
PLATFORM_SUPPORT=1
fi

elif [[ "$OSTYPE" == "FreeBSD"* ]]; then

Expand Down Expand Up @@ -320,6 +334,23 @@ installDeps()
rm -rf pngout-20150319-linux
fi

elif [ $PLATFORM == "macos" ]; then

# check /usr/local/Homebrew

for p in "${!BINARY_PATHS_ARRAY[@]}" ; do
if [ -f "${BINARY_PATHS_ARRAY[$p]}/brew" ]; then
ISSET_brew=1
else
ISSET_brew=0
fi
done
if [ $ISSET_brew -eq 0 ]; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi

brew install $DEPS_MACOS

elif [ $PLATFORM == "freebsd" ]; then

# for p in "${!BINARY_PATHS_ARRAY[@]}" ; do
Expand Down Expand Up @@ -430,9 +461,20 @@ checkUserTimeMarker()

checkTimeMarkerPermissions()
{
TIME_MARKER_MODIFIED=$(date -r "$1" +%s)
if [[ "$OSTYPE" == "darwin"* ]]; then
TIME_MARKER_MODIFIED=$(stat -t %s -f %m -- "$1")
else
TIME_MARKER_MODIFIED=$(date -r "$1" +%s)
fi

touch -m "$1" 2>/dev/null
TIME_MARKER_MODIFIED_NEW=$(date -r "$1" +%s)

if [[ "$OSTYPE" == "darwin"* ]]; then
TIME_MARKER_MODIFIED_NEW=$(stat -t %s -f %m -- "$1")
else
TIME_MARKER_MODIFIED_NEW=$(date -r "$1" +%s)
fi

if [ $TIME_MARKER_MODIFIED -eq $TIME_MARKER_MODIFIED_NEW ]; then
echo "Current user have no permissions to modify time marker. Exiting..." 1>&2
exit 1
Expand Down Expand Up @@ -543,8 +585,8 @@ usage()
echo
echo " -v, --version Shows script version."
echo
echo " -p <dir>, Specify input directory with or without slash "
echo " --path=<dir> in the end of path."
echo " -p <dir>, Specify full path to input directory with "
echo " --path=<dir> or without slash in the end of path."
echo
echo " -q, --quiet Execute script without any questions and users "
echo " actions."
Expand Down Expand Up @@ -572,10 +614,10 @@ usage()
echo " impossible to use this option with -t|--time "
echo " option. (test)"
echo
echo " -m <name>, Custom path or name of time marker file. Must "
echo " --time-marker=<name>, be name of file (for changes time marker name) "
echo " -m <path>, or full path for custom time marker file in "
echo " --time-marker=<path> custom directory. Working only with "
echo " -m <name>, Custom full path or name of time marker file. "
echo " --time-marker=<name>, Must be name of file (for changes time marker "
echo " -m <path>, name) or full path for custom time marker file "
echo " --time-marker=<path> in custom directory. Working only with "
echo " -n|--new-only option. (test)"
echo
echo " -tmp <dir>, Custom directory path for temporary files. "
Expand Down Expand Up @@ -993,7 +1035,7 @@ if ! [ -z "$IMAGES" ]; then
readableSize $SAVED_SIZE
echo " / $(echo "scale=2; 100-$OUTPUT*100/$INPUT" | bc | sed 's/^\./0./')%"

echo "Optimized/Total: $IMAGES_OPTIMIZED/$IMAGES_TOTAL files"
echo "Optimized/Total: $IMAGES_OPTIMIZED / $IMAGES_TOTAL files"
)
updateTimeMarker

Expand Down

0 comments on commit 67de2cd

Please sign in to comment.