2 # -----------------------------------------------------------------------
3 # Copyright (C) 2005-2008 Georgia Public Library Service
4 # Bill Erickson <billserickson@gmail.com>
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.
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 # -----------------------------------------------------------------------
19 # Exit script if any statement returns a non-true return value
21 # Throw an error for uninitialized variables
24 # ---------------------------------------------------------------------------
25 # Make sure we're running as the correct user
26 # ---------------------------------------------------------------------------
27 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
31 echo "usage: $0 [-u]";
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";
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)";
43 echo " Update organization tree and fieldmapper IDL:";
46 echo " Update organization tree and refresh proximity:";
55 # Initialize our variables
58 # ---------------------------------------------------------------------------
59 # Load the command line options and set the global vars
60 # ---------------------------------------------------------------------------
61 while getopts "u h" flag; do
63 "u") PROXIMITY="REFRESH";;
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';
74 COMPRESSOR="" # TODO: set via ./configure
75 #COMPRESSOR="java -jar /opt/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar"
77 echo "Updating Evergreen organization tree and IDL"
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/"
87 OUTFILE="$JSDIR/fmcore.js"
88 echo "Updating web_fieldmapper";
89 perl -MOpenILS::Utils::Configure -e 'print OpenILS::Utils::Configure::fieldmapper("web_core");' > "$OUTFILE"
91 OUTFILES="$OUTFILES $OUTFILE"
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/"
98 OUTFILES="$OUTFILES $OUTFILE"
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');"
104 OUTFILES="$OUTFILES $OUTFILE"
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"
110 OUTFILES="$OUTFILES $OUTFILE"
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/"
117 OUTFILES="$OUTFILES $OUTFILE"
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/"
124 OUTFILES="$OUTFILES $OUTFILE"
126 if [ ! -z "$PROXIMITY" ]
128 echo "Refreshing proximity of org units";
129 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_proximity();"
132 echo "Creating combined JS..."
135 for skin in $(ls $SKINDIR); do
137 [ ! -f $SKINDIR/$skin/xml/common/js_common.xml ] && continue;
139 files=$(sed -n -e "/<\!--START COMPRESSION-->/,/<\!--END COMPRESSION-->/ s/.*\?\/\([^']*\.js\)'.*/\1/p" $SKINDIR/$skin/xml/common/js_common.xml);
141 if [ -n "$files" ]; then
143 # add the selected files to one combined file
144 COMPRESS_FILE="$SKINDIR/$skin/js/combined.js"
145 cat $files > $COMPRESS_FILE
147 # if a compressor is configured, compress and report the size savings
148 if [ -n "$COMPRESSOR" ]; then
150 echo -n "before: "; du -h $COMPRESS_FILE;
152 $COMPRESSOR $COMPRESS_FILE > $COMPRESS_FILE.t;
153 mv $COMPRESS_FILE.t $COMPRESS_FILE;
155 echo -n "after: "; du -h $COMPRESS_FILE;
156 echo " -> $COMPRESS_FILE";
161 # Generate a hash of the generated files
164 for file in `ls -1 $OUTFILES`; do
165 if [[ -n $file && -f $file ]]
170 ) | md5sum | cut -f1 -d' ' | colrm 1 26 > LOCALSTATEDIR/web/eg_cache_hash
173 echo -n "Current Evergreen cache key: "
174 cat LOCALSTATEDIR/web/eg_cache_hash