Fix another occurrence of the affected version in the CVE-2018-1050 advisory
[samba-web.git] / generated_news.sh
1 #!/bin/bash
2 #
3
4 LC_ALL=C
5 export LC_ALL
6 LANG=C
7 export LANG
8 LANGUAGE=C
9 export LANGUAGE
10
11 set -u
12 set -e
13 umask 0022
14
15 generate() {
16         local dst="$1"
17         local count="$2"
18         local filter="$3"
19
20         test "${dst}" -nt "posted_news/" && {
21                 echo "${dst}: up to date"
22                 return 0
23         }
24
25         echo "${dst}: regenerating"
26         files=$(find posted_news/ -type f -regex "${filter}" -printf "%f\n" | sort -r | xargs)
27         {
28                 for f in ${files}; do
29                         if [[ "$filter" == *snip* ]] && [[ "$f" == *".body.html"* ]] && [[ "$files" == *"${f%.body.html}.snip.html"* ]]; then
30                                 continue
31                         fi
32                         echo "<!--#include virtual=\"/samba/posted_news/${f}\" -->"
33                         count=$((count-1))
34                         if [[ $count == 0 ]]; then break; fi
35                 done
36         } > ${dst}
37
38         return 0
39 }
40
41 generate_latest_stable_release() {
42         local dst="$1"
43         local download_url="$2"
44
45         pushd history >/dev/null
46         ALL_VERSIONS=$(ls samba-*.html | cut -d '-' -f2- | cut -d '.' -f1-3 | sort -t. -k 1,1n -k 2,2n -k 3,3n -u)
47         LATEST_VERSION=$(echo "${ALL_VERSIONS}" | tail -1)
48         popd >/dev/null
49
50         echo "LATEST_VERSION: ${LATEST_VERSION}"
51
52         local tgz="samba-${LATEST_VERSION}.tar.gz"
53         local asc="samba-${LATEST_VERSION}.tar.asc"
54         local release_notes="history/samba-${LATEST_VERSION}.html"
55
56         test "${dst}" -nt "${release_notes}" && {
57                 echo "${dst}: up to date"
58                 return 0
59         }
60
61         echo "${dst}: regenerating"
62         {
63                 echo "<!-- BEGIN: ${dst} -->"
64                 echo "<p>"
65                 echo "<a href=\"${download_url}/${tgz}\">Samba ${LATEST_VERSION} (gzipped)</a><br>"
66                 echo "<a href=\"/samba/${release_notes}\">Release Notes</a> &middot;"
67                 echo "<a href=\"${download_url}/${asc}\">Signature</a>"
68                 echo "</p>"
69                 echo "<!-- END: ${dst} -->"
70
71         } > ${dst}.tmp
72         mv ${dst}.tmp ${dst}
73 }
74
75 generate "generated_news/latest_10_headlines.html" "10" ".*\.headline\.html"
76 generate "generated_news/latest_10_bodies.html" "10" ".*\.body\.html"
77 generate "generated_news/latest_2_bodies.html" "2" ".*\.\(snip\|body\)\.html"
78
79 download_url="https://download.samba.org/pub/samba/stable"
80 generate_latest_stable_release "generated_news/latest_stable_release.html" "${download_url}"