From 0fa4918dbbbcdc447b3918275fcb192349264364 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 29 Mar 2014 02:02:13 -0400 Subject: [PATCH] update dist helpers --- Makefile | 2 +- makedist.sh => dist/makedist.sh | 6 ++-- dist/pngcrush.sh | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) rename makedist.sh => dist/makedist.sh (88%) create mode 100755 dist/pngcrush.sh diff --git a/Makefile b/Makefile index 5e88047..47d1a38 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,6 @@ css-min: $(CSS_FILES:=.min) check: css-min js-min dist: - ./makedist.sh + ./dist/makedist.sh .PHONY: all clean check css-min dist js-min diff --git a/makedist.sh b/dist/makedist.sh similarity index 88% rename from makedist.sh rename to dist/makedist.sh index 1b66c57..fc99c19 100755 --- a/makedist.sh +++ b/dist/makedist.sh @@ -17,9 +17,9 @@ json_value() { manifest.json } -PN=$(json_value name | sed 's:[[:space:]]:_:g' | tr '[:upper:]' '[:lower:]') +PN=$(json_value name | sed 's:[[:space:]/]:_:g' | tr '[:upper:]' '[:lower:]') if [[ ${PN} == "__msg_name__" ]] ; then - PN=$(basename "$(pwd)") + PN=$(basename "$(pwd)") fi PV=$(json_value version) rev=${1:-0} @@ -37,7 +37,7 @@ cp Makefile manifest.files manifest.json "${P}/" make -C "${P}" -j {css,js}-min while read line ; do - mv "${line}.min" "${line}" + mv "${line}.min" "${line}" done < <(find "${P}" -name '*.js' -o -name '*.css') rm "${P}"/{manifest.files,Makefile} diff --git a/dist/pngcrush.sh b/dist/pngcrush.sh new file mode 100755 index 0000000..f302a2e --- /dev/null +++ b/dist/pngcrush.sh @@ -0,0 +1,53 @@ +#!/bin/bash -xe +# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +size() +{ + stat -c %s "$@" +} + +do_apngopt() +{ + local png new + + for png in "$@"; do + new="${png}.new" + apngopt "${png}" "${new}" + if [[ $(size "${png}") -gt $(size "${new}") ]]; then + mv "${new}" "${png}" + else + rm "${new}" + fi + done +} + +do_pngcrush() +{ + local png new + + pngcrush -e .png.new "$@" + for png in "$@"; do + new="${png}.new" + mv "${new}" "${png}" + done +} + +main() +{ + if [ $# -eq 0 ]; then + set -- $(find -name '*.png') + fi + + if type -P apngopt >/dev/null; then + # apngopt likes to corrupt images. + : do_apngopt "$@" + elif type -P pngcrush >/dev/null; then + do_pngcrush "$@" + else + echo "error: could not find apngopt or pngcrush" + exit 1 + fi +} +main "$@" -- 2.39.5