aboutsummaryrefslogtreecommitdiffstats
path: root/makereport
blob: b7b84e1ec5722a4c0f32e65a84357473771025d5 (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
57
58
59
60
61
62
63
#!/bin/sh

SCRIPTPATH="$(readlink -f "$0")"
SCRIPTDIR="$(dirname "$SCRIPTPATH")/"
TEMPLATE=${TEMPLATE:-~/Documents/reports/template/template.md}
SCRIPTNAME="${SCRIPTPATH##*/}"
TODAY=$(date +%d-%m-%4Y)
VIEWPDF=${VIEWPDF:-/usr/bin/firefox}

usage()
{
    echo "Usage: ${SCRIPTNAME} [-h|-t] [-o outfile.pdf] <inputfile.md>"
    echo
    echo "    Positional: <inputfile>, markdown report (input)"
    echo
    echo "    -h|--help      display this message and exit"
    echo "    -t|--template  print out the template"
    echo "    -o|--output    output file to be written (default: report.pdf)"
    echo
    echo "    EXAMPLES"
    echo "    # Save the markdown template to a file"
    echo "    ${SCRIPTNAME} -t > template.md"
    echo "    # After editing the template with your vulnerabilities"
    echo "    # launch ${SCRIPTNAME} directly on it"
    echo "    ${SCRIPTNAME} -o 2022-09-google.pdf template.md"
    echo
}

if ! command -v pandoc pdflatex >/dev/null; then 
    echo "You need to install pandoc and pdflatex"
fi

while [ "$#" -ne 0 ]; do case "$1" in 
    -h|--help)
        usage
        exit
        ;;
    -t|--template)
        cat "${TEMPLATE}"
        exit
        ;;
    -o|--output)
        shift
        export OUTFILE="$1"
        ;;
    *) 
        INPUTFILE="$1"
esac; shift; done

if [ -z "$INPUTFILE" ]; then
    echo "No input file provided"
    exit 1
fi

pandoc --pdf-engine=xelatex \
    --highlight-style=/home/danix/.local/share/pandoc/templates/reports.theme \
    --template reports \
    --variable fontsize=16pt \
    --variable linestretch=1.5 \
    --variable geometry=a4paper \
    -i "${INPUTFILE}" -o "${OUTFILE:-~/Documents/reports/report_$TODAY.pdf}"
# once the file is exported we can preview it in the browser or in a file viewer
# $VIEWPDF $OUTFILE