meso-web

Sources of the |Méso|Star> website
git clone git://git.meso-star.fr/meso-web.git
Log | Files | Refs | README | LICENSE

print_downloads.sh (4457B)


      1 #!/bin/sh
      2 
      3 # Copyright (C) 2017-2025 |Méso|Star> (contact@meso-star.com)
      4 #
      5 # This program is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU General Public License as published by
      7 # the Free Software Foundation, either version 3 of the License, or
      8 # (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13 # GNU General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU General Public License
     16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     17 
     18 set -e
     19 
     20 if [ "$#" -lt 3 ]; then
     21   >&2 printf 'usage: %s section prefix\n' "${0##*/}"
     22   exit 1
     23 fi
     24 
     25 section="$1"
     26 prefix="$2"
     27 
     28 shift 2
     29 
     30 for i in "$@"; do
     31   case "${i}" in
     32     [Ll]inux) os_linux="1" ;;
     33     [Ww]indows) os_windows="1" ;;
     34     *) ;; # Unsuported OS
     35   esac
     36 done
     37 
     38 cd  -- "${section}" || exit 1
     39 
     40 # Table header
     41 echo '<table class="list">'
     42 echo '  <tr>'
     43 echo '    <th>Version</th>'
     44 if [ -n "${os_linux}" ]; then
     45   echo '    <th>GNU/Linux 64-bits</th>'
     46 fi
     47 if [ -n "${os_windows}" ]; then
     48   echo '    <th>Windows 64-bits</th>'
     49 fi
     50 echo '    <th>Sources</th>'
     51 echo '  </tr>'
     52 
     53 # Define the basic regular expression of a version number
     54 version_re="[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}"
     55 version_re="${version_re}\(-r[0-9]\{1,\}\)\{0,1\}"
     56 
     57 # Browse all tarball files in the "downloads" subdirectory. Sort them
     58 # in descending order according to lexicographical order. This may
     59 # result in an incorrect order with regard to the version number. For
     60 # example, version 9 will be considered higher than version 10. Some
     61 # implementations offer an option to process version strings
     62 # naturally, but this is not POSIX-compliant. So let's leave it as is,
     63 # as there are currently no sorting issues.
     64   find downloads -name "${prefix}-*.tar.gz" \
     65 | grep -e "${prefix}-${version_re}-[^\(Sources\)].\{0,\}\.tar\.gz" \
     66 | sort -r \
     67 | while read -r arch; do
     68 
     69   # Extract the version from
     70   version=$(echo "${arch}" \
     71     | sed "s/downloads\/${prefix}-\(${version_re}\).\{0,\}$/\1/g")
     72 
     73   # Setup archive names
     74   linux="${arch}"
     75   windows="downloads/${prefix}-${version}-Win64.zip"
     76   source1="downloads/${prefix}-${version}-Sources.zip"
     77   source2="downloads/${prefix}-${version}-Source.zip"
     78   source3="downloads/${prefix}-${version}-Sources.tar.gz"
     79   source4="downloads/${prefix}-${version}-Source.tar.gz"
     80 
     81   # Define the list to be referenced in each cell of the current
     82   # version: first the GNU/Linux archive, then the Windows archive,
     83   # and finally the corresponding sources. Since sources can have
     84   # multiple names, find the one that matches the archive version,
     85   # otherwise use a default name. The existence of the various
     86   # archives available for download is verified below. The purpose
     87   # here is simply a matter of providing three file names that could
     88   # fill the cells in the row.
     89   dl=""
     90   if   [ -n "${os_linux}"   ]; then dl="${dl} ${linux}";   fi
     91   if   [ -n "${os_windows}" ]; then dl="${dl} ${windows}"; fi
     92   if   [ -f "${source1}"    ]; then dl="${dl} ${source1}";
     93   elif [ -f "${source2}"    ]; then dl="${dl} ${source2}";
     94   elif [ -f "${source3}"    ]; then dl="${dl} ${source3}";
     95   else                              dl="${dl} ${source4}"; fi
     96 
     97   printf '  <tr>\n' # Let's get started on filling the line
     98 
     99   # Print the version in the first cell of the row
    100   printf '    <td>%s</td>\n' "${version}"
    101 
    102   # Iterate over the 3 filenames previously define and provide a link
    103   # to it if their exist onto disk. For instance, a GNU/Linux archive
    104   # can be provided while a Windows version is missing.
    105   for i in ${dl}; do
    106 
    107     printf '    <td>\n'
    108 
    109     if [ -f "${i}" ]; then
    110       # The archive exists. Display a link to it whose label depends
    111       # on the archive type (tarball or zip)
    112       printf '        [<a href="%s">' "${i}"
    113       [ "${i#*tar.gz}" != "${i}" ] && printf 'tarball' || printf 'zip'
    114       printf '</a>]\n'
    115     fi
    116 
    117     # Display a link to the archive signature, if it exists
    118     if [ -f "${i}.sig" ]; then
    119       printf '        [<a href="%s.sig">pgp</a>]\n' "${i}"
    120     fi
    121     printf '    </td>\n'
    122   done
    123 
    124   printf '  </tr>\n' # That's all for this row
    125 done
    126 
    127 # The table is complete. Don't forget to add a line break after it to
    128 # signal to Markdown that the embedded HTML code has ended.
    129 printf '</table>\n'
    130 printf '\n'