##    Licensed to the Apache Software Foundation (ASF) under one or more
##    contributor license agreements.  See the NOTICE file distributed with
##    this work for additional information regarding copyright ownership.
##    The ASF licenses this file to You under the Apache License, Version 2.0
##    (the "License"); you may not use this file except in compliance with
##    the License.  You may obtain a copy of the License at
##
##      http://www.apache.org/licenses/LICENSE-2.0
##
##    Unless required by applicable law or agreed to in writing, software
##    distributed under the License is distributed on an "AS IS" BASIS,
##    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##    See the License for the specific language governing permissions and
##    limitations under the License.

## EXPERIMENTAL script to generate the markdown snippet describing
## the download; currently hardwired for full Jackrabbit releases,
## with the version string below. Feel free to work on parameter
## support and extensions for Oak releases as well.

#!/bin/sh
set -e

site="https://www.apache.org/dist/jackrabbit"
version=$1
dl1="https://www.apache.org/dyn/closer.lua/jackrabbit/$version"
dl2="https://www.apache.org/dist/jackrabbit/$version"

function dumpone {
  printf "\n* [%s]($dl1/%s)\n" "$1" "$1"
  size=$(du -m $version/"$1" | cut -f 1)
  printf "    (%dM, %s, [pgp]($dl2/%s.asc), [sha512]($dl2/%s.sha512))\n" $size "$2" "$1" "$1"
}

function usage {
    echo "sh create-download-md.sh <jr-version>"
    echo "sh create-download-md.sh oak/<oak-version>"
    echo "Example:"
    echo "sh create-download-md.sh 2.12.3"
}

if [ -z "$version" ]
then
   usage
   exit 1
fi

printf "See the [full release notes](%s/%s/RELEASE-NOTES.txt) for more details.\n" $site $version

case $version in
oak*)
  v=$(echo $version | tr '/' '-')
  dumpone "jackrabbit-$v-src.zip" "source zip"
  ;;
*)
  dumpone "jackrabbit-$version-src.zip" "source zip"
  dumpone "jackrabbit-standalone-$version.jar" "standalone server"
  dumpone "jackrabbit-webapp-$version.war" "web application"
  dumpone "jackrabbit-jca-$version.rar" "JCA resource adapter"
  ;;
esac

