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