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 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"
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
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"
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)"
48 echo " Update organization tree and fieldmapper IDL:"
51 echo " Update organization tree and refresh proximity:"
56 function check_dir_writable {
57 if [ ! -d "$1" ] || [ ! -w "$1" ]; then
58 echo "Unable to write to ${1}, please check"
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.
67 # This may be passed a single filename or a glob for simplicity.
68 for F in `ls $1 2>/dev/null`
70 if [ -f "$F" ] && [ ! -w "$F" ]; then
71 echo "Unable to write to ${F}, please check"
79 # Verify we're able to write everywhere we need
80 for DIR in "$JSDIR" "$FMDOJODIR" "$SLIMPACDIR"
82 check_dir_writable "$DIR"
85 # Verify we have cover image directories, creating where needed
86 for DIR in "small/r" "medium/r" "large/r"
88 if [ ! -d "$COVERDIR/$DIR" ]; then
89 mkdir -p "$COVERDIR/$DIR"
91 check_dir_writable "$COVERDIR/$DIR"
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"
96 check_files_writable "$FILE"
100 [ $OHNO -eq 0 ] || exit 1
106 # Initialize our variables
108 OSRF_CORE="SYSCONFDIR/opensrf_core.xml"
110 # ---------------------------------------------------------------------------
111 # Load the command line options and set the global vars
112 # ---------------------------------------------------------------------------
113 while getopts "c:uh" flag; do
115 "c") OSRF_CORE="$OPTARG";;
116 "u") PROXIMITY="REFRESH";;
120 shift $((OPTIND - 1))
122 echo "Updating Evergreen organization tree and IDL"
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/"
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"
136 OUTFILES="$OUTFILES $OUTFILE"
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/"
143 OUTFILES="$OUTFILES $OUTFILE"
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"
149 OUTFILES="$OUTFILES $OUTFILE"
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"
155 OUTFILES="$OUTFILES $OUTFILE"
157 if [ ! -z "$PROXIMITY" ]
159 echo "Refreshing proximity of org units"
160 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_proximity();" -- --osrf-config "$OSRF_CORE"
163 # Generate a hash of the generated files
166 for file in `ls -1 $OUTFILES`; do
167 if [[ -n $file && -f $file ]]
172 ) | md5sum | cut -f1 -d' ' | cut -b 27-32 > LOCALSTATEDIR/web/eg_cache_hash
175 echo -n "Current Evergreen cache key: "
176 cat LOCALSTATEDIR/web/eg_cache_hash