LP1054322 - libparent-perl not needed for Ubuntu Precise
[working/Evergreen.git] / Open-ILS / src / extras / autogen.sh
1 #!/bin/bash
2 # -----------------------------------------------------------------------
3 # Copyright (C) 2005-2008  Georgia Public Library Service
4 # Bill Erickson <billserickson@gmail.com>
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 # -----------------------------------------------------------------------
16
17 # vim:noet:ts=4
18
19 # Exit script if any statement returns a non-true return value
20 set -e
21 # Throw an error for uninitialized variables
22 set -u
23
24 # ---------------------------------------------------------------------------
25 # Make sure we're running as the correct user
26 # ---------------------------------------------------------------------------
27 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
28
29 function usage {
30         echo "";
31         echo "usage: $0 [-u]";
32         echo "";
33         echo "Updates the Evergreen organization tree and fieldmapper IDL.";
34         echo "Run this every time you change the Evergreen organization tree";
35         echo "or update fm_IDL.xml";
36         echo "";
37         echo "Optional parameters:";
38         echo -e "  -u\t\tupdate proximity of library sites in organization tree";
39         echo -e "    \t\t(this is expensive for a large organization tree)";
40         echo "";
41         echo "Examples:";
42         echo "";
43         echo "  Update organization tree and fieldmapper IDL:";
44         echo "    $0";
45         echo "";
46         echo "  Update organization tree and refresh proximity:";
47         echo "    $0 -u";
48         echo "";
49 }
50
51 (
52
53 cd "BINDIR"
54
55 # Initialize our variables
56 PROXIMITY="";
57
58 # ---------------------------------------------------------------------------
59 # Load the command line options and set the global vars
60 # ---------------------------------------------------------------------------
61 while getopts  "u h" flag; do
62         case $flag in   
63                 "u")            PROXIMITY="REFRESH";;
64                 "h")            usage && exit;;
65         esac;
66 done
67 shift $((OPTIND - 1))
68
69 JSDIR="LOCALSTATEDIR/web/opac/common/js/";
70 FMDOJODIR="LOCALSTATEDIR/web/js/dojo/fieldmapper/";
71 SLIMPACDIR="LOCALSTATEDIR/web/opac/extras/slimpac/";
72 SKINDIR='LOCALSTATEDIR/web/opac/skin';
73
74 COMPRESSOR="" # TODO: set via ./configure
75 #COMPRESSOR="java -jar /opt/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar"
76
77 echo "Updating Evergreen organization tree and IDL"
78 echo ""
79
80 OUTFILE="$JSDIR/fmall.js"
81 echo "Updating fieldmapper";
82 perl -MOpenILS::Utils::Configure -e 'print OpenILS::Utils::Configure::fieldmapper();' > "$OUTFILE"
83 cp "$OUTFILE" "$FMDOJODIR/"
84 echo " -> $OUTFILE"
85 OUTFILES="$OUTFILE"
86
87 OUTFILE="$JSDIR/fmcore.js"
88 echo "Updating web_fieldmapper";
89 perl -MOpenILS::Utils::Configure -e 'print OpenILS::Utils::Configure::fieldmapper("web_core");' > "$OUTFILE"
90 echo " -> $OUTFILE"
91 OUTFILES="$OUTFILES $OUTFILE"
92
93 OUTFILE="$JSDIR/*/OrgTree.js"
94 echo "Updating OrgTree";
95 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_js('$JSDIR', 'OrgTree.js');"
96 cp "$JSDIR/en-US/OrgTree.js" "$FMDOJODIR/"
97 echo " -> $OUTFILE"
98 OUTFILES="$OUTFILES $OUTFILE"
99
100 OUTFILE="$SLIMPACDIR/*/lib_list.inc"
101 echo "Updating OrgTree HTML";
102 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_html_options('$SLIMPACDIR', 'lib_list.inc');"
103 echo " -> $OUTFILE"
104 OUTFILES="$OUTFILES $OUTFILE"
105
106 OUTFILE="$SLIMPACDIR/locales.inc"
107 echo "Updating locales selection HTML";
108 perl -MOpenILS::Utils::Configure -e "print OpenILS::Utils::Configure::locale_html_options();" > "$OUTFILE"
109 echo " -> $OUTFILE"
110 OUTFILES="$OUTFILES $OUTFILE"
111
112 OUTFILE="$JSDIR/OrgLasso.js"
113 echo "Updating Search Groups";
114 perl -MOpenILS::Utils::Configure -e "print OpenILS::Utils::Configure::org_lasso();" > "$OUTFILE";
115 cp "$OUTFILE" "$FMDOJODIR/"
116 echo " -> $OUTFILE"
117 OUTFILES="$OUTFILES $OUTFILE"
118
119 OUTFILE="$JSDIR/*/FacetDefs.js"
120 echo "Updating Facet Definitions";
121 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::facet_types('$JSDIR', 'FacetDefs.js');"
122 cp "$JSDIR/en-US/FacetDefs.js" "$FMDOJODIR/"
123 echo " -> $OUTFILE"
124 OUTFILES="$OUTFILES $OUTFILE"
125
126 if [ ! -z "$PROXIMITY" ]
127 then
128         echo "Refreshing proximity of org units";
129         perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_proximity();"
130 fi
131
132 echo "Creating combined JS..."
133 cd $JSDIR;
134
135 for skin in $(ls $SKINDIR); do
136
137     [ ! -f $SKINDIR/$skin/xml/common/js_common.xml ] && continue;
138
139     files=$(sed -n -e "/<\!--START COMPRESSION-->/,/<\!--END COMPRESSION-->/  s/.*\?\/\([^']*\.js\)'.*/\1/p" $SKINDIR/$skin/xml/common/js_common.xml);
140
141     if [ -n "$files" ]; then
142
143         # add the selected files to one combined file
144         COMPRESS_FILE="$SKINDIR/$skin/js/combined.js"
145         cat $files > $COMPRESS_FILE
146
147         # if a compressor is configured, compress and report the size savings
148         if [ -n "$COMPRESSOR" ]; then
149
150             echo -n "before: "; du -h $COMPRESS_FILE;
151
152             $COMPRESSOR $COMPRESS_FILE > $COMPRESS_FILE.t;
153             mv $COMPRESS_FILE.t $COMPRESS_FILE;
154
155             echo -n "after:  "; du -h $COMPRESS_FILE;
156             echo " -> $COMPRESS_FILE";
157         fi;
158     fi;
159 done;
160
161 # Generate a hash of the generated files
162 (
163         date +%Y%m%d
164         for file in `ls -1 $OUTFILES`; do
165                 if [[ -n $file && -f $file ]]
166                 then
167                         md5sum $file
168                 fi
169         done
170 ) | md5sum | cut -f1 -d' ' | cut -b 27-32 > LOCALSTATEDIR/web/eg_cache_hash
171
172 echo
173 echo -n "Current Evergreen cache key: "
174 cat LOCALSTATEDIR/web/eg_cache_hash
175
176 echo "Done";
177
178 )