1#!/bin/bash
  2
  3# check if slimit is installed since it is required by this script
  4command -v slimit >/dev/null 2>&1 || { echo >&2 "slimit is not installed.  Aborting."; exit -1; }
  5
  6SLIMIT=cat
  7
  8# Configuration for our packages
  9BOOTSTRAP=bootstrap-3.3.0-dist
 10BOOTSTRAP_SELECT=silviomoreto-bootstrap-select-v1.6.3-0-g3b5cfe0
 11BOOTSTRAP_DATEPICKER=bootstrap-datepicker-1.3.0
 12BOOTSTRAP_MULTISELECT=jQuery-Multiple-Select-Plugin-For-Bootstrap-Bootstrap-Multiselect
 13BOOTSTRAP_DIALOG=bootstrap3-dialog-master
 14CKEDITOR=ckeditor_4.2_full
 15COLOR_PICKER=laktek-really-simple-color-picker-d3c634d
 16# currrently we use both because eventviewer1 and jobviewer need 1.9, eventviewer2 needs 1.10
 17# DATATABLES=DataTables-1.9.3
 18# DATATABLES=DataTables-1.10.12
 19DATATABLES=datatables
 20COL_REORDER=colreorder-1.5.2
 21DATEJS=date
 22DROPDOWN_CHECK_LIST=dropdown-check-list.1.4  # used only in eventviewer for column visiibility selection
 23DYNATREE=dynatree-1.2.4
 24JGLOBEE=jglobee
 25# used by most of the website
 26JQUERY3=jquery-3.7.0
 27# lightbox used in reports requires jquery 1.
 28# all reports have v1.7.1 hardcoded in them
 29JQUERY1_FAKE=jquery-1.7.1
 30# bootstrap requires min v1.9.1
 31JQUERY1=jquery-1.9.1
 32
 33# CHART used v0.8.3 for a long time. It works fine but has some visual artifacts
 34# including low-quality fonts in axis labels, and very thick lines in plots
 35# FLOT=flot-0.8.3
 36
 37# v3.2.10 gives better visual quality and, with patching as below and in the application code,
 38# is a drop-in replacement
 39FLOT=flot-3.2.10
 40# FLOT=flot-4.2.1
 41# Be aware the v3.2.10 unpack code below uses 2 files from inside the 0.8.10 directory
 42# so don't delete it
 43# Also v4.2 (the latest at time of writing) appears to have broken the mouse drag
 44# function so we avoid it
 45JQUERY_FLOT=flot-0.8.3
 46JQUERY_FLOT_PATCH=jquery.flot.patch
 47JQUERY_FLOT_NAVIGATE_PATCH=jquery.flot.navigate.patch
 48JQUERY_FLOT_AXIS_LABELS=jquery.flot.axislabels
 49JQUERY_FLOT_AXIS_LABELS_PATCH=jquery.flot.axislabels.patch
 50JQUERY_FLOT_FILLAREA=jquery.flot.fillarea
 51JQUERY_ACTUAL=jquery.actual-1.0.15
 52JQUERY_BBQ=jquery-bbq-1.2.1
 53JQUERY_BBQ_PATCH=jquery.ba-bbq.patch
 54JQUERY_FANCYBOX=jquery.fancybox-1.3.4
 55JQUERY_TIMEPICKER=jQuery-Timepicker-Addon-1.5.0
 56# Select theme "Smoothness" when downloading jquery=-ui
 57JQUERY_UI=jquery-ui-1.12.1
 58JSTORAGE=jstorage
 59MODERNIZR=modernizr-2.6.2
 60REQUIRE_JS=require-2.1.4.min
 61SPRINTF=sprintf-0.7-beta1
 62STRFTIME=strftime
 63STRFTIME_PATCH=strftime.patch
 64TIMELINE=timeline_libraries_v2.3.0
 65ANGULARJS=angular-1.2.22
 66PRINTTHIS=printThis-1.15.0
 67
 68patch --help | grep -q gnu
 69rc=$?
 70if [[ $rc != 0 ]] ; then
 71    echo "Non-GNU version of patch detected; cannot continue"
 72    exit -1
 73fi
 74
 75# Reliable way to find directory of the script (has to work when called via relative or
 76# absolute filename)
 77SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
 78echo "Source dir ${SOURCE_DIR}"
 79# Change to target directory (chart/web)
 80DEST_DIR=${SOURCE_DIR}/../static
 81# Make static directory if needed
 82# echo Creating target directory $PWD/static
 83mkdir -p ${DEST_DIR}
 84echo "Dest dir ${DEST_DIR}"
 85
 86# Locate source 3rdparty.packages directory
 87# SOURCE_dir=$PWD/`dirname $0`
 88
 89if [ ! -d "$SOURCE_DIR" ]; then
 90    echo "Cannot locate directory ${SOURCE_DIR}"
 91    echo "If you are using an absolute path to this script try a relative path instead"
 92    echo "E.g. instead of: \~/chart/..."
 93    echo "or: /tcc1/home/.../chart/..."
 94    echo "Try using: cd \~ \&\& chart/chart/web/3rdparty.packages/unpack.sh"
 95    exit -1
 96fi
 97
 98cd $DEST_DIR
 99
100echo "Deleting existing 3rdparty directory ${PWD}/3rdparty"
101rm -rf 3rdparty
102mkdir -p 3rdparty
103cd 3rdparty
104
105echo "Copying jquery"
106cp $SOURCE_DIR/$JQUERY3.min.js .
107cp $SOURCE_DIR/$JQUERY3.min.map .
108cp $SOURCE_DIR/$JQUERY1.min.js $JQUERY1_FAKE.min.js
109
110echo "Unpacking jquery-actual"
111tar xf $SOURCE_DIR/$JQUERY_ACTUAL.tar.gz
112
113echo "Unpacking jquery-ui: ${JQUERY_UI}.zip"
114unzip -qq $SOURCE_DIR/$JQUERY_UI.zip
115
116echo "Unpacking timeline"
117unzip -qq $SOURCE_DIR/$TIMELINE.zip
118
119echo "Minifying Datejs"
120${SLIMIT} $SOURCE_DIR/$DATEJS.js > $DATEJS.min.js 2> /dev/null
121
122echo "Unpacking DataTables-1.9.3"
123unzip -qq $SOURCE_DIR/$DATATABLES/DataTables-1.9.3.zip
124
125echo "Unpacking DataTables-1.10.12"
126unzip -qq $SOURCE_DIR/$DATATABLES/DataTables-1.10.12.zip
127# copy colReorder stuff to DataTables-1.10.12
128cp $SOURCE_DIR/$DATATABLES/$COL_REORDER/colReorder.dataTables.*.css DataTables-1.10.12/media/css/
129cp $SOURCE_DIR/$DATATABLES/$COL_REORDER/dataTables.colReorder.*.js DataTables-1.10.12/media/js/
130
131echo "Unpacking dropdown-check-list"
132mkdir dropdown-check-list
133cd dropdown-check-list
134unzip -qq $SOURCE_DIR/$DROPDOWN_CHECK_LIST.zip
135cd ..
136
137echo "Unpacking dynatree"
138mkdir dynatree
139cd dynatree
140unzip -qq $SOURCE_DIR/$DYNATREE.zip
141cd ..
142
143echo "Unpacking, patching and merging ${FLOT}"
144# rm ${FLOT} flot.merge.js -rf
145if [[ "$FLOT" != "flot-0.8.3" ]]; then
146    tar xf ${SOURCE_DIR}/${FLOT}/${FLOT}.tar.gz
147    # for complicated reasons, we can't use the navigation plugin from v3.2.10
148    # so instead we extract it from 0.8.10, apply a special CHART patch, then use it
149    unzip -qqo ${SOURCE_DIR}/flot-0.8.3/flot-0.8.3.zip
150    cat ${SOURCE_DIR}/flot-0.8.3/jquery.flot.navigate.patch | patch -p0
151    cat ${FLOT}/source/jquery.canvaswrapper.js <(echo) \
152        ${FLOT}/source/jquery.colorhelpers.js <(echo) \
153        ${FLOT}/source/jquery.flot.js <(echo) \
154        ${FLOT}/source/jquery.flot.saturated.js <(echo) \
155        ${FLOT}/source/jquery.flot.browser.js <(echo) \
156        ${FLOT}/source/jquery.flot.drawSeries.js <(echo) \
157        ${FLOT}/source/jquery.flot.uiConstants.js <(echo) \
158        ${FLOT}/source/jquery.flot.selection.js <(echo) \
159        ${FLOT}/source/jquery.flot.legend.js <(echo) \
160        ${FLOT}/source/jquery.flot.axislabels.js <(echo) \
161        ${FLOT}/source/jquery.flot.resize.js <(echo) \
162        flot/jquery.flot.navigate.js <(echo) \
163        ${FLOT}/source/jquery.flot.time.js <(echo) \
164        ${FLOT}/source/jquery.flot.hover.js <(echo) \
165        ${FLOT}/source/jquery.flot.symbol.js <(echo) \
166        ${SOURCE_DIR}/${FLOT}/jquery.flot.fillarea.js > flot.merge.js
167    rm ${FLOT} -rf
168else
169    unzip -qq ${SOURCE_DIR}/${FLOT}/${FLOT}.zip
170    cat ${SOURCE_DIR}/${FLOT}/jquery.flot.patch | patch -p0
171    cat ${SOURCE_DIR}/${FLOT}/jquery.flot.navigate.patch | patch -p0
172    # Note - do not minimise orderBars
173    cp $SOURCE_DIR/${FLOT}/jquery.flot.orderBars.js flot/jquery.flot.orderBars.js
174    cp ${SOURCE_DIR}/${FLOT}/jquery.flot.axislabels.js .
175    cat ${SOURCE_DIR}/${FLOT}/jquery.flot.axislabels.patch | patch -p0
176    cat flot/jquery.flot.min.js <(echo) \
177        flot/jquery.flot.selection.min.js <(echo) \
178        flot/jquery.flot.time.min.js <(echo) \
179        flot/jquery.flot.canvas.min.js <(echo) \
180        flot/jquery.flot.resize.min.js <(echo) \
181        flot/jquery.flot.navigate.min.js <(echo) \
182        flot/jquery.flot.crosshair.min.js <(echo) \
183        jquery.flot.axislabels.js <(echo) \
184        ${SOURCE_DIR}/${FLOT}/jquery.flot.fillarea.js <(echo) \
185        ${SOURCE_DIR}/${FLOT}/flot_symbol.js <(echo) \
186        ${SOURCE_DIR}/${FLOT}/flot_dashes.js > flot.merge.js
187    # enabling orderBars causes js console errors
188    # flot/jquery.flot.orderBars.js <(echo) \
189    rm flot jquery.flot.axislabels.js -rf
190fi
191
192echo "Unpacking COLOR_PICKER"
193unzip -qq $SOURCE_DIR/$COLOR_PICKER.zip
194mv $COLOR_PICKER simple-color-picker
195# Do not minimise simple color picker as slimit throws an error
196# (inserted into the output minimised file!)
197# ${SLIMIT} simple-color-picker/jquery.simple-color-picker.js > simple-color-picker/jquery.simple-color-picker.min.js
198# rm simple-color-picker/jquery.simple-color-picker.js
199
200echo "Unpacking and patching jquery-bbq"
201unzip -qq $SOURCE_DIR/$JQUERY_BBQ.zip
202mv $JQUERY_BBQ jquery-bbq
203echo Patching jquery-bbq
204cat $SOURCE_DIR/jquery.ba-bbq.patch| patch -p0
205
206echo "Copying, patching and minifying strftime"
207cp $SOURCE_DIR/$STRFTIME.js .
208cat $SOURCE_DIR/$STRFTIME_PATCH | patch -p0
209${SLIMIT} $STRFTIME.js > $STRFTIME.min.js 2> /dev/null
210rm -f $STRFTIME.js
211
212echo "Unpacking CKEditor"
213unzip -qq $SOURCE_DIR/$CKEDITOR.zip
214
215echo "Minifying sprintf"
216${SLIMIT} $SOURCE_DIR/$SPRINTF.js > $SPRINTF.min.js 2> /dev/null
217
218echo "Minifying jstorage"
219${SLIMIT} $SOURCE_DIR/$JSTORAGE.js > $JSTORAGE.min.js 2> /dev/null
220
221echo "Copying timepicker"
222unzip -qq $SOURCE_DIR/$JQUERY_TIMEPICKER.zip
223cp $JQUERY_TIMEPICKER/dist/jquery-ui-timepicker-addon.min.js .
224# Skip timepicker patch for now
225#cat $SOURCE_DIR/$JQUERY_TIMEPICKER.patch | patch -p0
226rm -rf $JQUERY_TIMEPICKER
227
228# Just testing
229# java -jar compiler.jar --js ../chart/static/3rdparty/jquery-ui-1.8.13/ui/jquery-ui.js --js_output_file jquery-ui.js
230# uglify --lift-vars --unsafe chart/plots/static/plot.js > chart/plots/static/plot.min.js
231# yuicompressor chart/web/static/cart.css > chart/web/static/chart.min.css
232# ${SLIMIT} a.js > a.min.js
233
234echo "Unpacking fancybox"
235unzip -qq $SOURCE_DIR/$JQUERY_FANCYBOX.zip
236cd $JQUERY_FANCYBOX
237# make the hit boxes on the left and right side of the expanded pictures bigger
238cat $SOURCE_DIR/$JQUERY_FANCYBOX-width.patch | patch -p0
239# compatibility with the latest jquery 1.x releases
240cat $SOURCE_DIR/$JQUERY_FANCYBOX-compat.patch | patch -p0
241${SLIMIT} fancybox/$JQUERY_FANCYBOX.js > fancybox/$JQUERY_FANCYBOX.min.js 2> /dev/null
242cd fancybox
243rm -f $JQUERY_FANCYBOX.pack.js
244ln -s $JQUERY_FANCYBOX.min.js $JQUERY_FANCYBOX.pack.js
245cd ..
246mv fancybox ..
247# All EPS reports look for static/3rdparty/fancybox/jquery.fancybox-1.3.4.pack.js
248# so make sure they find the patched version.
249# For other projects or EPS in future we fcould clean things up a bit by changing them
250# to look for fancybox.min.js (and clean the jquery import too) but this link must always
251# remain, because there are legacy reports all over the place
252cd ..
253rm -rf $JQUERY_FANCYBOX
254
255echo "Copying require.js"
256cp $SOURCE_DIR/$REQUIRE_JS.js .
257
258echo "Copying modernizr.js"
259cp $SOURCE_DIR/$MODERNIZR.js .
260
261echo "Copying three"
262mkdir three
263cp $SOURCE_DIR/three/{three.min.js,OrbitControls.js} three
264
265echo "Unpacking jglobee"
266bunzip2 -c $SOURCE_DIR/$JGLOBEE.tar.bz2 | tar xf -
267# mv $JGLOBEE jglobee  # enable when we are using a proper release again
268
269echo "Unpacking bootstrap"
270unzip -qq $SOURCE_DIR/$BOOTSTRAP.zip
271mv dist bootstrap
272
273echo "Unpacking bootstrap-select"
274# we could probably use jquery selectmenu now instead
275gunzip -c $SOURCE_DIR/$BOOTSTRAP_SELECT.tar.gz | tar xf -
276mv silviomoreto-bootstrap-select-* bootstrap-select
277
278echo "Unpacking bootstrap-dialog"
279unzip -qq $SOURCE_DIR/$BOOTSTRAP_DIALOG.zip
280
281echo "Unpacking bootstrap-multiselect"
282unzip -qq $SOURCE_DIR/$BOOTSTRAP_MULTISELECT.zip
283cp $BOOTSTRAP_MULTISELECT/js/bootstrap-multiselect.js .
284rm -rf $BOOTSTRAP_MULTISELECT
285${SLIMIT} bootstrap-multiselect.js > bootstrap-multiselect.min.js 2> /dev/null
286
287echo "Unpacking bootstrap-datepicker"
288gunzip -c $SOURCE_DIR/$BOOTSTRAP_DATEPICKER.tar.gz | tar xf -
289mv $BOOTSTRAP_DATEPICKER bootstrap-datepicker
290
291echo "Copying angular.js"
292cp $SOURCE_DIR/$ANGULARJS/angular.min.js .
293
294echo "Unpacking printThis"
295gunzip -c ${SOURCE_DIR}/${PRINTTHIS}.tar.gz | tar xf -
296mv ${PRINTTHIS}/printThis.js .
297rm -rf ${PRINTTHIS}