]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/autogen.sh
LP2061136 - Stamping 1405 DB upgrade script
[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
109 # ---------------------------------------------------------------------------
110 # Load the command line options and set the global vars
111 # ---------------------------------------------------------------------------
112 while getopts  "u h" flag; do
113     case $flag in    
114         "u")        PROXIMITY="REFRESH";;
115         "h")        usage && exit;;
116     esac
117 done
118 shift $((OPTIND - 1))
119
120 echo "Updating Evergreen organization tree and IDL"
121 echo ""
122
123 OUTFILE="$JSDIR/fmall.js"
124 echo "Updating fieldmapper"
125 perl -MOpenILS::Utils::Configure -e 'print OpenILS::Utils::Configure::fieldmapper();' > "$OUTFILE"
126 cp "$OUTFILE" "$FMDOJODIR/"
127 echo " -> $OUTFILE"
128 OUTFILES="$OUTFILE"
129
130 OUTFILE="$JSDIR/fmcore.js"
131 echo "Updating web_fieldmapper"
132 perl -MOpenILS::Utils::Configure -e 'print OpenILS::Utils::Configure::fieldmapper("web_core");' > "$OUTFILE"
133 echo " -> $OUTFILE"
134 OUTFILES="$OUTFILES $OUTFILE"
135
136 OUTFILE="$JSDIR/*/OrgTree.js"
137 echo "Updating OrgTree"
138 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_js('$JSDIR', 'OrgTree.js');"
139 cp "$JSDIR/en-US/OrgTree.js" "$FMDOJODIR/"
140 echo " -> $OUTFILE"
141 OUTFILES="$OUTFILES $OUTFILE"
142
143 OUTFILE="$SLIMPACDIR/*/lib_list.inc"
144 echo "Updating OrgTree HTML"
145 perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_html_options('$SLIMPACDIR', 'lib_list.inc');"
146 echo " -> $OUTFILE"
147 OUTFILES="$OUTFILES $OUTFILE"
148
149 OUTFILE="$SLIMPACDIR/locales.inc"
150 echo "Updating locales selection HTML"
151 perl -MOpenILS::Utils::Configure -e "print OpenILS::Utils::Configure::locale_html_options();" > "$OUTFILE"
152 echo " -> $OUTFILE"
153 OUTFILES="$OUTFILES $OUTFILE"
154
155 if [ ! -z "$PROXIMITY" ]
156 then
157     echo "Refreshing proximity of org units"
158     perl -MOpenILS::Utils::Configure -e "OpenILS::Utils::Configure::org_tree_proximity();"
159 fi
160
161 # Generate a hash of the generated files
162 (
163     date +%Y%m%d
164     for file in `ls -1 $OUTFILES`; do
165         if [[ -n $file && -f $file ]]
166         then
167             md5sum $file
168         fi
169     done
170 ) | md5sum | cut -f1 -d' ' | cut -b 27-32 > LOCALSTATEDIR/web/eg_cache_hash
171
172 echo
173 echo -n "Current Evergreen cache key: "
174 cat LOCALSTATEDIR/web/eg_cache_hash
175
176 echo "Done"
177
178 )