]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/extras/autogen.sh
Merge branch 'opac-tt-poc' of git+ssh://yeti.esilibrary.com/home/evergreen/evergreen...
[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 -c SYSCONFDIR/opensrf_core.xml";
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 echo "Updating fieldmapper";
100 perl fieldmapper.pl "$CONFIG"   > "$JSDIR/fmall.js";
101 cp "$JSDIR/fmall.js" "$FMDOJODIR/"
102 echo " -> $JSDIR/fmall.js";
103
104 echo "Updating web_fieldmapper";
105 perl fieldmapper.pl "$CONFIG" "web_core"        > "$JSDIR/fmcore.js";
106 echo " -> $JSDIR/fmcore.js";
107
108 echo "Updating OrgTree";
109 perl org_tree_js.pl "$CONFIG" "$JSDIR" "OrgTree.js";
110 cp "$JSDIR/en-US/OrgTree.js" "$FMDOJODIR/"
111 echo " -> $JSDIR/*/OrgTree.js";
112
113 echo "Updating OrgTree HTML";
114 perl org_tree_html_options.pl "$CONFIG" "$SLIMPACDIR" "lib_list.inc";
115 echo " -> $SLIMPACDIR/*/lib_list.inc";
116
117 echo "Updating locales selection HTML";
118 perl locale_html_options.pl "$CONFIG" "$SLIMPACDIR/locales.inc";
119 echo " -> $SLIMPACDIR/*/locales.inc";
120
121 echo "Updating Search Groups";
122 perl org_lasso_js.pl "$CONFIG" > "$JSDIR/OrgLasso.js";
123 cp "$JSDIR/OrgLasso.js" "$FMDOJODIR/"
124 echo " -> $JSDIR/OrgLasso.js";
125
126 echo "Updating Facet Definitions";
127 perl facet_types_js.pl "$CONFIG" "$JSDIR" "FacetDefs.js";
128 cp "$JSDIR/en-US/FacetDefs.js" "$FMDOJODIR/"
129 echo " -> $JSDIR/*/FacetDefs.js";
130
131 if [ ! -z "$PROXIMITY" ]
132 then
133         echo "Refreshing proximity of org units";
134         perl org_tree_proximity.pl "$CONFIG";
135 fi
136
137 echo "Creating combined JS..."
138 cd $JSDIR;
139
140 for skin in $(ls $SKINDIR); do
141
142     [ ! -f $SKINDIR/$skin/xml/common/js_common.xml ] && continue;
143
144     files=$(sed -n -e "/<\!--START COMPRESSION-->/,/<\!--END COMPRESSION-->/  s/.*\?\/\([^']*\.js\)'.*/\1/p" $SKINDIR/$skin/xml/common/js_common.xml);
145
146     if [ -n "$files" ]; then
147
148         # add the selected files to one combined file
149         COMPRESS_FILE="$SKINDIR/$skin/js/combined.js"
150         cat $files > $COMPRESS_FILE
151
152         # if a compressor is configured, compress and report the size savings
153         if [ -n "$COMPRESSOR" ]; then
154
155             echo -n "before: "; du -h $COMPRESS_FILE;
156
157             $COMPRESSOR $COMPRESS_FILE > $COMPRESS_FILE.t;
158             mv $COMPRESS_FILE.t $COMPRESS_FILE;
159
160             echo -n "after:  "; du -h $COMPRESS_FILE;
161             echo " -> $COMPRESS_FILE";
162         fi;
163     fi;
164 done;
165
166 echo "Done";
167
168 )
169