Debian Codegraph @

debian/generate-manpages

raw
1 #!/bin/sh
2
3 set -eu
4
5 # Generate manpages from the program invocation. Unfortunately,
6 # help2man is not good enough for the job here.
7
8 # Usage: generate-manpages <output-directory>
9
10 version="$(dpkg-parsechangelog --show-field Version | sed -e 's/+ds.*//')"
11
12 output_dir="$1"
13
14 mkdir -p "$output_dir"
15
16 convert() {
17 local binary program line output_mode
18 binary="$1"
19 line="$2"
20 output_mode="${3-stderr}"
21
22 program="$(basename "$binary")"
23
24 help_output="$output_dir/$program.help"
25 # The programs dump their usage text in different forms ...
26 case "$output_mode" in
27 stdout)
28 "$binary" -? >"$help_output" 2>/dev/null || :
29 ;;
30 stderr)
31 "$binary" -? >/dev/null 2>"$help_output" || :
32 ;;
33 esac
34
35 # Drop everything until and including "Available (options)"
36 sed -n -i -e '/^Available /,$p' "$help_output"
37 sed -i -e '1d' "$help_output"
38
39 scdoc="$output_dir/$program.scd"
40 manpage="$output_dir/$program.1"
41
42 cat <<__EOS__ >"$scdoc"
43 $program(1) "libEST $version" "libEST Documentation"
44
45 # NAME
46
47 $program - $line
48
49 # OPTIONS
50
51 __EOS__
52
53 # Convert usage output into markdown, basically:
54 # * "--option <param> <description>" =>
55 # "*--option* <param>\n\t<description>"
56 # * "--option <description>" =>
57 # "*--option::\n\t<description>"
58 # * Indent following lines with tab
59 sed -e "
60 s/^ *\(--*[a-z][^ ]*\) \{1,\}<\([a-z][^>]\{1,\}\)> */\\n*\1* _\2_\\n\\t/ ;
61 s/^ *\(--*[a-z][^ ]*\) \{1,\}<\([A-Z][^>]\{1,\}\)> */\\n*\1* \2\\n\\t/ ;
62 s/^ *\(--*[a-z6\?][^ ]*\) \{1,\}/\\n*\1*\\n\\t/ ;
63 s/^ */\t/
64 " \
65 <"$help_output" >>"$scdoc"
66
67 cat <<__EOS__ >>"$scdoc"
68
69 # COPYRIGHT & LICENSE
70
71 Copyright (c) 2012-2018 Cisco Systems, Inc. All rights reserved.
72
73 License (BSD-3-Clause):
74
75 \`\`\`
76 Redistribution and use in source and binary forms, with or without
77 modification, are permitted provided that the following conditions
78 are met:
79 Redistributions of source code must retain the above copyright
80 notice, this list of conditions and the following disclaimer.
81 Redistributions in binary form must reproduce the above
82 copyright notice, this list of conditions and the following
83 disclaimer in the documentation and/or other materials provided
84 with the distribution.
85 Neither the name of the Cisco Systems, Inc. nor the names of its
86 contributors may be used to endorse or promote products derived
87 from this software without specific prior written permission.
88
89 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
90 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
91 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
92 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
93 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
94 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
95 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
96 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
98 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
99 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
100 OF THE POSSIBILITY OF SUCH DAMAGE.
101 \`\`\`
102
103 # AUTHOR
104
105 This manpage is based on $program's usage output and the included
106 documentation. It was written for the Debian project by Christoph Biedl
107 <[email protected]> but may be used by others.
108 __EOS__
109
110 scdoc <"$scdoc" >"$manpage"
111 }
112
113 convert \
114 example/client/estclient \
115 'example EST client application using the granular API'
116
117 convert \
118 example/client-simple/estclient_simple \
119 'example EST client application using the easy provision API' \
120 stdout
121
122 convert \
123 example/client-brski/estclient_brski \
124 'example EST client application using Bootstrapping Remote Secure Key Infrastructure' \
125 stdout
126
127 convert \
128 example/proxy/estproxy \
129 'example EST proxy application acting as an RA'
130
131 convert \
132 example/server/estserver \
133 'example EST server application using OpenSSL CA'