source: misc/scripts/minify_if_changed.sh @ 744

Last change on this file since 744 was 744, checked in by duh, 13 years ago

setting svn properties

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Rev
File size: 1.2 KB
Line 
1#!/bin/sh
2SOURCE=$1
3ONLY_IF_MINIFIED_ALREADY_EXISTS=$2
4DESTINATION=`echo $1|sed 's/\.[A-Za-z]*$/.min\0/g'`
5MD5SUM=`which md5sum`
6MD5_CURRENT=
7MD5_NEW=
8TMP_FILE=~/tmp/minified
9
10# got a parameter?
11if [ ! $1 ]; then
12        echo "Usage: "$0" <input file> [only create if a minified already exists]"
13        echo "Example: "$0" bla.js 1"
14        exit;
15fi
16
17# does the input file exist?
18if [ ! -f $1 ]; then
19        echo "Usage: "$0" <input file> [only create if a minified already exists]"
20        echo "Example: "$0" bla.js 1"
21        echo "error: could not find "$1
22        exit;
23fi
24
25# does the destination exist?
26if [ -f $DESTINATION ]; then
27        # yes, create an MD5 sum
28        MD5_CURRENT=`$MD5SUM -t $DESTINATION | sed 's/ .*$//g'`
29elif [ $ONLY_IF_MINIFIED_ALREADY_EXISTS ]; then
30        # no need to continue
31        exit;
32fi
33
34# minify sourcefile
35java -jar ~/apps/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar $SOURCE > $TMP_FILE
36
37# determine the MD5 hash of the generated file
38MD5_NEW=`$MD5SUM -t $TMP_FILE | sed 's/ .*$//g'`
39
40# do the MD5 hashes differ?
41if [ "$MD5_CURRENT" != "$MD5_NEW" ]; then
42        cp $TMP_FILE $DESTINATION
43        echo ".created minified version of "$SOURCE" ("$MD5_CURRENT" > "$MD5_NEW")"
44fi
45
46# remove temp file
47if [ -f $TMP_FILE ]; then
48        rm $TMP_FILE > /dev/null
49fi
Note: See TracBrowser for help on using the repository browser.