]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/extras/autogen.sh
Further autogen.sh cleanup
[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] [-c <c_config>]";
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 "  -c\t\tfull path to C configuration file (opensrf_core.xml)";
39         echo -e "    \t\t - defaults to SYSCONFDIR/opensrf_core.xml";
40         echo -e "  -u\t\tupdate proximity of library sites in organization tree";
41         echo -e "    \t\t(this is expensive for a large organization tree)";
42         echo "";
43         echo "Examples:";
44         echo "";
45         echo "  Update organization tree and fieldmapper IDL:";
46         echo "    $0";
47         echo "";
48         echo "  Update organization tree and refresh proximity:";
49         echo "    $0 -u -c SYSCONFDIR/opensrf_core.xml";
50         echo "";
51 }
52
53 (
54
55 cd "BINDIR"
56
57 # Initialize our variables
58 CONFIG="";
59 PROXIMITY="";
60
61 # ---------------------------------------------------------------------------
62 # Load the command line options and set the global vars
63 # ---------------------------------------------------------------------------
64 while getopts  "c:u h" flag; do
65         case $flag in   
66                 "c")            CONFIG="$OPTARG";;
67                 "u")            PROXIMITY="REFRESH";;
68                 "h")            usage && exit;;
69         esac;
70 done
71 shift $((OPTIND - 1))
72
73 if [ -z "$CONFIG" ] && [[ ! -z "${1:-}" ]]; then
74         # Support "autogen.sh /path/to/opensrf_core.xml" for legacy invocation
75         CONFIG="$1";
76 fi
77 if [ -z "$CONFIG" ]; then
78         # Fall back to the configured default
79         CONFIG="SYSCONFDIR/opensrf_core.xml";
80 fi
81 if [ ! -f "$CONFIG" ]; then
82         echo "ERROR: could not find configuration file '$CONFIG'";
83         echo "";
84         usage;
85         exit 1;
86 fi;
87
88 JSDIR="LOCALSTATEDIR/web/opac/common/js/";
89 FMDOJODIR="LOCALSTATEDIR/web/js/dojo/fieldmapper/";
90 SLIMPACDIR="LOCALSTATEDIR/web/opac/extras/slimpac/";
91 SKINDIR='LOCALSTATEDIR/web/opac/skin';
92
93 COMPRESSOR="" # TODO: set via ./configure
94 #COMPRESSOR="java -jar /opt/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar"
95
96 echo "Updating Evergreen organization tree and IDL using '$CONFIG'"
97 echo ""
98
99 OUTFILE="$JSDIR/fmall.js"
100 echo "Updating fieldmapper";
101 perl -MOpenILS::Utils::Configure -e 'print OpenILS::Utils::Configure::fieldmapper();' > "$OUTFILE"
102 cp "$OUTFILE" "$FMDOJODIR/"
103 echo " -> $OUTFILE"
104 OUTFILES="$OUTFILE"
105
106 OUTFILE="$JSDIR/fmcore.js"
107 echo "Updating web_fieldmapper";
108 perl -MOpenILS::Utils::Configure -e 'print OpenILS::Utils::Configure::fieldmapper("web_core");' > "$OUTFILE"
109 echo " -> $OUTFILE"
110 OUTFILES="$OUTFILES $OUTFILE"
111
112 OUTFILE="$JSDIR/*/OrgTree.js"
113 echo "Updating OrgTree";
114 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_js('$JSDIR', 'OrgTree.js');"
115 cp "$JSDIR/en-US/OrgTree.js" "$FMDOJODIR/"
116 echo " -> $OUTFILE"
117 OUTFILES="$OUTFILES $OUTFILE"
118
119 OUTFILE="$SLIMPACDIR/*/lib_list.inc"
120 echo "Updating OrgTree HTML";
121 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_html_options('$SLIMPACDIR', 'lib_list.inc');"
122 echo " -> $OUTFILE"
123 OUTFILES="$OUTFILES $OUTFILE"
124
125 OUTFILE="$SLIMPACDIR/locales.inc"
126 echo "Updating locales selection HTML";
127 perl -MOpenILS::Utils::Configure -e "print OpenILS::Utils::Configure::locale_html_options();" > "$OUTFILE"
128 echo " -> $OUTFILE"
129 OUTFILES="$OUTFILES $OUTFILE"
130
131 OUTFILE="$JSDIR/OrgLasso.js"
132 echo "Updating Search Groups";
133 perl -MOpenILS::Utils::Configure -e "print OpenILS::Utils::Configure::org_lasso();" > "$OUTFILE";
134 cp "$OUTFILE" "$FMDOJODIR/"
135 echo " -> $OUTFILE"
136 OUTFILES="$OUTFILES $OUTFILE"
137
138 OUTFILE="$JSDIR/*/FacetDefs.js"
139 echo "Updating Facet Definitions";
140 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::facet_types('$JSDIR', 'FacetDefs.js');"
141 cp "$JSDIR/en-US/FacetDefs.js" "$FMDOJODIR/"
142 echo " -> $OUTFILE"
143 OUTFILES="$OUTFILES $OUTFILE"
144
145 if [ ! -z "$PROXIMITY" ]
146 then
147         echo "Refreshing proximity of org units";
148         perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_proximity();"
149 fi
150
151 echo "Creating combined JS..."
152 cd $JSDIR;
153
154 for skin in $(ls $SKINDIR); do
155
156     [ ! -f $SKINDIR/$skin/xml/common/js_common.xml ] && continue;
157
158     files=$(sed -n -e "/<\!--START COMPRESSION-->/,/<\!--END COMPRESSION-->/  s/.*\?\/\([^']*\.js\)'.*/\1/p" $SKINDIR/$skin/xml/common/js_common.xml);
159
160     if [ -n "$files" ]; then
161
162         # add the selected files to one combined file
163         COMPRESS_FILE="$SKINDIR/$skin/js/combined.js"
164         cat $files > $COMPRESS_FILE
165
166         # if a compressor is configured, compress and report the size savings
167         if [ -n "$COMPRESSOR" ]; then
168
169             echo -n "before: "; du -h $COMPRESS_FILE;
170
171             $COMPRESSOR $COMPRESS_FILE > $COMPRESS_FILE.t;
172             mv $COMPRESS_FILE.t $COMPRESS_FILE;
173
174             echo -n "after:  "; du -h $COMPRESS_FILE;
175             echo " -> $COMPRESS_FILE";
176         fi;
177     fi;
178 done;
179
180 # Generate a hash of the generated files
181 (
182         date +%Y%m%d
183         for file in `ls -1 $OUTFILES`; do
184                 if [[ -n $file && -f $file ]]
185                 then
186                         md5sum $file
187                 fi
188         done
189 ) | md5sum | cut -f1 -d' ' | colrm 1 26 > LOCALSTATEDIR/web/eg_cache_hash
190
191 echo
192 echo -n "Current Evergreen cache key: "
193 cat LOCALSTATEDIR/web/eg_cache_hash
194
195 echo "Done";
196
197 )