#!/bin/sh

set -eu

copy_js_font_files()
{
  # Rspamd web interface doesn't support symlinks and directory traversal
  # copy javascript files from original Debian packages
  RSPAMD_CSS_DIR=/usr/share/rspamd/www/css
  RSPAMD_JS_LIB_DIR=/usr/share/rspamd/www/js/lib
  cp --remove-destination /usr/share/javascript/bootstrap5/js/bootstrap.bundle.min.js $RSPAMD_JS_LIB_DIR/bootstrap.bundle.min.js
  cp --remove-destination /usr/share/javascript/bootstrap5/css/bootstrap.min.css $RSPAMD_CSS_DIR/bootstrap.min.css
  cp --remove-destination /usr/share/javascript/requirejs/require.js $RSPAMD_JS_LIB_DIR/require.min.js

  # remove path of previous versions, if existent
  if [ -f $RSPAMD_JS_LIB_DIR/jquery-3.3.1.min.js ]; then
    rm $RSPAMD_JS_LIB_DIR/jquery-3.3.1.min.js
  fi
  if [ -f $RSPAMD_JS_LIB_DIR/bootstrap.min.js ]; then
    rm $RSPAMD_JS_LIB_DIR/bootstrap.min.js
  fi
}

case "$1" in
    configure)
      copy_js_font_files
    ;;

    triggered)
      copy_js_font_files
    ;;

    abort-*)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

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

#DEBHELPER#
