#!/bin/bash
# postinst script for frodo-stat
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

if [ "$1" == "configure" ]; then
    cur_dir=$PWD
    jquery_script=$(find /var/www/html/js/jquery/jquery-*.js -maxdepth 0 -type f | sed -e 's/.*\///g' | grep -P "^jquery-\d+")
    echo "configure jQuery library: $jquery_script"
    jquery_ui_script=$(find /var/www/html/js/jquery/jquery-ui-*.js -maxdepth 0 -type f | sed -e 's/.*\///g' | grep -P "^jquery-ui-\d+.+\.min\.js")
    echo "configure jQuery UI library: $jquery_ui_script"
    cd /var/www/html/js/jquery
    [ -e "jquery.js" ] && rm -f jquery.js > /dev/null 2>&1
    [ -e "jquery-ui.js" ] && rm -f jquery-ui.js > /dev/null 2>&1
    ln -s $jquery_script jquery.js > /dev/null 2>&1
    ln -s $jquery_ui_script jquery-ui.js > /dev/null 2>&1
    cd $cur_dir
    chmod +x /var/www/html/js && chown www-data:www-data /var/www/html/js
    find /var/www/html/js/* -type f -name *.js | xargs chmod +x
    find /var/www/html/js/* | xargs chown www-data:www-data
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
