]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/autogen.sh
LP1615805 No inputs after submit in patron search (AngularJS)
[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 JSDIR="LOCALSTATEDIR/web/opac/common/js"
25 FMDOJODIR="LOCALSTATEDIR/web/js/dojo/fieldmapper"
26 SLIMPACDIR="LOCALSTATEDIR/web/opac/extras/slimpac"
27 COVERDIR="LOCALSTATEDIR/web/opac/extras/ac/jacket"
28
29 # ---------------------------------------------------------------------------
30 # Make sure we're not root and are able to write to the destination directory
31 # ---------------------------------------------------------------------------
32 [ `id -u` -eq 0 ] && echo 'Not to be run as root' && exit 1
33
34 function usage {
35     echo ""
36     echo "usage: $0 [-u]"
37     echo ""
38     echo "Updates the Evergreen organization tree and fieldmapper IDL."
39     echo "Run this every time you change the Evergreen organization tree"
40     echo "or update fm_IDL.xml"
41     echo ""
42     echo "Optional parameters:"
43     echo -e "  -u\t\tupdate proximity of library sites in organization tree"
44     echo -e "    \t\t(this is expensive for a large organization tree)"
45     echo ""
46     echo "Examples:"
47     echo ""
48     echo "  Update organization tree and fieldmapper IDL:"
49     echo "    $0"
50     echo ""
51     echo "  Update organization tree and refresh proximity:"
52     echo "    $0 -u"
53     echo ""
54 }
55
56 function check_dir_writable {
57     if [ ! -d "$1" ] || [ ! -w "$1" ]; then
58         echo "Unable to write to ${1}, please check"
59         OHNO=1
60     fi
61 }
62
63 function check_files_writable {
64     # Since we already know the directories are writable there's only
65     # a problem if the file(s) already exist *and* for some reason isn't writable.
66
67     # This may be passed a single filename or a glob for simplicity.
68     for F in `ls $1 2>/dev/null`
69     do
70           if [ -f "$F" ] && [ ! -w "$F" ]; then
71               echo "Unable to write to ${F}, please check"
72               OHNO=1
73           fi
74     done
75 }
76
77 OHNO=0
78
79 # Verify we're able to write everywhere we need
80 for DIR in "$JSDIR" "$FMDOJODIR" "$SLIMPACDIR"
81 do
82     check_dir_writable "$DIR"
83 done
84
85 # Verify we have cover image directories, creating where needed
86 for DIR in "small/r" "medium/r" "large/r"
87 do
88     if [ ! -d "$COVERDIR/$DIR" ]; then
89         mkdir -p "$COVERDIR/$DIR"
90     fi
91     check_dir_writable "$COVERDIR/$DIR"
92 done
93
94 for FILE in "$JSDIR/fmall.js" "$JSDIR/fmcore.js" "$JSDIR/*/OrgTree.js" "$SLIMPACDIR/*/lib_list.inc" "$SLIMPACDIR/locales.inc" "LOCALSTATEDIR/web/eg_cache_hash"
95 do
96     check_files_writable "$FILE"
97 done
98
99 # Bail on badness
100 [ $OHNO -eq 0 ] || exit 1
101
102 (
103
104 cd "BINDIR"
105
106 # Initialize our variables
107 PROXIMITY=""
108 OSRF_CORE="SYSCONFDIR/opensrf_core.xml"
109
110 # ---------------------------------------------------------------------------
111 # Load the command line options and set the global vars
112 # ---------------------------------------------------------------------------
113 while getopts  "c:uh" flag; do
114     case $flag in    
115         "c")        OSRF_CORE="$OPTARG";;
116         "u")        PROXIMITY="REFRESH";;
117         "h")        usage && exit;;
118     esac
119 done
120 shift $((OPTIND - 1))
121
122 echo "Updating Evergreen organization tree and IDL"
123 echo ""
124
125 OUTFILE="$JSDIR/fmall.js"
126 echo "Updating fieldmapper"
127 perl -MOpenILS::Utils::Configure -e 'print OpenILS::Utils::Configure::fieldmapper();' -- --osrf-config "$OSRF_CORE" > "$OUTFILE"
128 cp "$OUTFILE" "$FMDOJODIR/"
129 echo " -> $OUTFILE"
130 OUTFILES="$OUTFILE"
131
132 OUTFILE="$JSDIR/fmcore.js"
133 echo "Updating web_fieldmapper"
134 perl -MOpenILS::Utils::Configure -e 'print OpenILS::Utils::Configure::fieldmapper("web_core");' -- --osrf-config "$OSRF_CORE" > "$OUTFILE"
135 echo " -> $OUTFILE"
136 OUTFILES="$OUTFILES $OUTFILE"
137
138 OUTFILE="$JSDIR/*/OrgTree.js"
139 echo "Updating OrgTree"
140 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_js('$JSDIR', 'OrgTree.js');" -- --osrf-config "$OSRF_CORE"
141 cp "$JSDIR/en-US/OrgTree.js" "$FMDOJODIR/"
142 echo " -> $OUTFILE"
143 OUTFILES="$OUTFILES $OUTFILE"
144
145 OUTFILE="$SLIMPACDIR/*/lib_list.inc"
146 echo "Updating OrgTree HTML"
147 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_html_options('$SLIMPACDIR', 'lib_list.inc');" -- --osrf-config "$OSRF_CORE"
148 echo " -> $OUTFILE"
149 OUTFILES="$OUTFILES $OUTFILE"
150
151 OUTFILE="$SLIMPACDIR/locales.inc"
152 echo "Updating locales selection HTML"
153 perl -MOpenILS::Utils::Configure -e "print OpenILS::Utils::Configure::locale_html_options();" -- --osrf-config "$OSRF_CORE" > "$OUTFILE"
154 echo " -> $OUTFILE"
155 OUTFILES="$OUTFILES $OUTFILE"
156
157 if [ ! -z "$PROXIMITY" ]
158 then
159     echo "Refreshing proximity of org units"
160     perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_proximity();" -- --osrf-config "$OSRF_CORE"
161 fi
162
163 # Generate a hash of the generated files
164 (
165     date +%Y%m%d
166     for file in `ls -1 $OUTFILES`; do
167         if [[ -n $file && -f $file ]]
168         then
169             md5sum $file
170         fi
171     done
172 ) | md5sum | cut -f1 -d' ' | cut -b 27-32 > LOCALSTATEDIR/web/eg_cache_hash
173
174 echo
175 echo -n "Current Evergreen cache key: "
176 cat LOCALSTATEDIR/web/eg_cache_hash
177
178 echo "Done"
179
180 )