]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/extras/autogen.sh
LP1825851 Add Perl HTML::Defang dependency
[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 if [ ! -z "$PROXIMITY" ]
113 then
114         echo "Refreshing proximity of org units";
115         perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_proximity();"
116 fi
117
118 # Generate a hash of the generated files
119 (
120         date +%Y%m%d
121         for file in `ls -1 $OUTFILES`; do
122                 if [[ -n $file && -f $file ]]
123                 then
124                         md5sum $file
125                 fi
126         done
127 ) | md5sum | cut -f1 -d' ' | cut -b 27-32 > LOCALSTATEDIR/web/eg_cache_hash
128
129 echo
130 echo -n "Current Evergreen cache key: "
131 cat LOCALSTATEDIR/web/eg_cache_hash
132
133 echo "Done";
134
135 )