#!/bin/sh

exec 2>&1

set -ex

version=$(dpkg-parsechangelog -SVersion | cut -d - -f 1 | sed 's/~/-/')

main_build="$1"
if [ -z "$main_build" ]; then
  main_build='/usr/share/javascript/jquery/jquery.js'
fi

upstream_cache="$ADTTMP"
if [ -z "$upstream_cache" ]; then
  upstream_cache=$HOME/.cache/jquery-debian
  mkdir -p "$upstream_cache"
fi
upstream_main_build=$upstream_cache/jquery-${version}.js

if [ ! -f "$upstream_main_build" ]; then
  wget --output-document="$upstream_main_build" \
    https://code.jquery.com/jquery-${version}.js
fi

diff --ignore-blank-lines \
  --ignore-matching-lines=Date:.*Z \
  -u "$upstream_main_build" "$main_build"
