aboutsummaryrefslogtreecommitdiff
path: root/make_markdown.sh
blob: 92beed2c398c42da8a8870309e20f596ff7bd7ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh

# Copyright (C) 2022 Wojtek Kosior
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 Universal License as published by
# the Creative Commons Corporation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# CC0 1.0 Universal License for more details.

PLAIN_FILENAME=SBoM_haketilo-1.0_hydrilla-1.0.txt

for WHICH_ONE in haketilo hydrilla; do
    if [ $WHICH_ONE = haketilo ]; then
	OTHER_ONE=hydrilla
    else
	OTHER_ONE=haketilo
    fi
    OTHER_CAP=$(printf $OTHER_ONE | tr h H)

    export NOTE="
[Software Bill of Materials (SBOM)](https://en.wikipedia.org/wiki/Software_bill_of_materials) lists external components used or included in a given software product. 

You may also want to look at the [SBOM of $OTHER_CAP](/projects/hydrilla/wiki/${OTHER_CAP}_Software_Bill_of_Materials) and [a concatenated plain text version](https://git.koszko.org/haketilo-hydrilla-sbom/plain/$PLAIN_FILENAME)."

    AWK_EXTRACT_HALF="
/^#[[:space:]].*Haketilo/ {haketilo_part = 1; hydrilla_part = 0;}
/^#[[:space:]].*Hydrilla/ {hydrilla_part = 1; haketilo_part = 0;}
/^##[[:space:]]/ {
    if (${WHICH_ONE}_part && printed_note && !printed_toc) {
        print \"{{toc}}\\n\"
        printed_toc = 1;
    }
}
{
    if (${WHICH_ONE}_part) {
       	if (!printed_note) {
            print \$0;
	    print ENVIRON[\"NOTE\"];
            printed_note = 1;
        } else {
            print \$0;
        }
    }
}
"

    awk -- "$AWK_EXTRACT_HALF" $PLAIN_FILENAME |
	# email addresses
	sed 's_<\([^[:space:]]\+@[^[:space:]]\+\)>_`<`\1`>`_g' |
	# tables
	sed 's_|\(-\+\)+\(-\+\)_|\1|\2_g' > SBoM_$WHICH_ONE-1.0.md
done