Electrum wrapper: fix probability mistake
[tails.git] / bin / generate-Tor-blog-post
blobf630e02de423bcd0f825e813d88aea32dc287eb9
1 #!/bin/sh
3 set -eu
5 error() {
6 echo "error: ${*}" >&2
7 exit 1
10 USAGE="Usage: $(basename "$0") VERSION TAG DIST RELEASE_DATE"
12 [ $# -eq 4 ] || error "$USAGE"
14 export VERSION="$1"
15 export TAG="$2"
16 export DIST="$3"
17 export RELEASE_DATE="$4"
19 MARKDOWN_TMPFILE=$(mktemp /tmp/tor-blog-post-XXXXXX.md)
21 case "$DIST" in
22 stable)
23 MARKDOWN_SOURCE="wiki/src/news/version_${VERSION:?}.mdwn"
25 alpha)
26 MARKDOWN_SOURCE="wiki/src/news/test_${TAG:?}.mdwn"
29 error "Unsupported DIST: '${DIST}'\n${USAGE}"
31 esac
33 html_body() {
34 ikiwiki --setup ikiwiki.setup \
35 --libdir lib/perl5 \
36 --render "$MARKDOWN_SOURCE" |
37 tidy --quiet yes \
38 --mute MISSING_ENDTAG_BEFORE,INSERTING_TAG,DISCARDING_UNEXPECTED,UNKNOWN_ENTITY,MISSING_ATTRIBUTE,TRIM_EMPTY_ELEMENT,STRING_CONTENT_LOOKS \
39 --wrap 99999 |
40 sed '0,/^<section id="content" role="main">$/d' |
41 sed '/^<footer id="footer" class="pagefooter" role="contentinfo">$/,$d' |
42 sed '/^<div class="toc">$/,+7d' |
43 sed '/^<p><img [^<>]*\/><\/p>$/d' |
44 sed '/^<div[^<>]*\>/d' |
45 sed '/^<\/div>$/d' |
46 sed 's@<img [^<>]*/>@@g' |
47 sed 's@<a name[^<>]*></a>@@g' |
48 sed 's@href="\.\./@href="https://tails.net/@g' |
49 sed 's@src="\./@src="https://tails.net/news/@g' |
50 sed 's@\(\.en\)\?.html@/@g' |
51 perl -pE 'BEGIN{undef $/;}s{<nav class="language-switcher">.*?<\/nav>}{}smg'
53 echo '<h1>Support and feedback</h1>'
54 echo '<p>For support and feedback, visit the <a href="https://tails.net/support/">Support section</a> on the Tails website.</p>'
57 BODY=$(html_body | html2markdown | perl -pE 's{^[#]}{##}') j2 --import-env '' \
58 config/release_management/templates/Tor_blog_post.md.jinja \
59 >"$MARKDOWN_TMPFILE"
61 echo "Done! The draft Tor blog post was written to $MARKDOWN_TMPFILE"