blob: 183399b71d20b1e996940ffe962484f3b72c8de8 (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#!/usr/bin/env bash
# Assemble remote man pages for darwin or windows from markdown files
set -e
PLATFORM=$1 ## linux, windows or darwin
TARGET=${2} ## where to output files
SOURCES=${@:3} ## directories to find markdown files
PODMAN=${PODMAN:-bin/podman-remote} ## location overridden for testing
function usage() {
echo >&2 "$0 PLATFORM TARGET SOURCES..."
echo >&2 "PLATFORM: Is either linux, darwin or windows."
echo >&2 "TARGET: Is the directory where files will be staged. eg, docs/build/remote/linux"
echo >&2 "SOURCES: Are the directories of source files. eg, docs/markdown"
}
function fail() {
echo >&2 -e "$@\n"
usage
exit 1
}
case $PLATFORM in
darwin|linux)
PUBLISHER=man_fn
;;
windows)
PUBLISHER=html_fn
;;
-help)
usage
exit 0
;;
*) fail '"linux", "darwin" and "windows" are the only supported platforms.' ;;
esac
if [[ -z $TARGET ]]; then
fail 'TARGET directory is required'
fi
if [[ -z $SOURCES ]]; then
fail 'At least one SOURCE directory is required'
fi
if [[ ! -x $PODMAN ]]; then
fail "$PODMAN does not exist"
fi
## man_fn copies the man page or link to flattened directory
function man_fn() {
local page=$1
local file=$(basename $page)
local dir=$(dirname $page)
if [[ ! -f $page ]]; then
page=$dir/links/${file%.*}.1
fi
install $page $TARGET/${file%%.*}.1
}
## html_fn converts the markdown page or link to HTML
function html_fn() {
local markdown=$1
local file=$(basename $markdown)
local dir=$(dirname $markdown)
if [[ ! -f $markdown ]]; then
local link=$(sed -e 's?.so man1/\(.*\)?\1?' <$dir/links/${file%.md})
markdown=$dir/$link.md
fi
pandoc --ascii --lua-filter=docs/links-to-html.lua -o $TARGET/${file%%.*}.html $markdown
}
## pub_pages finds and publishes the remote manual pages
function pub_pages() {
local source=$1
local publisher=$2
for f in $(ls $source/podman-remote*); do
$publisher $f
done
for c in "container" "image" "pod" "volume" ""; do
local cmd=${c:+-$c}
for s in $($PODMAN $c --help | sed -n '/^Available Commands:/,/^Flags:/p' | sed -e '1d;$d' -e '/^$/d' | awk '{print $1}'); do
$publisher $(echo $source/podman$cmd-$s.*)
done
done
}
## sed syntax is different on darwin and linux
## sed --help fails on mac, meaning we have to use mac syntax
function sed_os(){
if sed --help > /dev/null 2>&1 ; then
$(sed -i "$@")
else
$(sed -i "" "$@")
fi
}
## rename renames podman-remote.ext to podman.ext, and fixes up contents to reflect change
function rename (){
if [[ "$PLATFORM" != linux ]]; then
local remote=$(echo $TARGET/podman-remote.*)
local ext=${remote##*.}
mv $remote $TARGET/podman.$ext
sed_os "s/podman\\\*-remote/podman/g" $TARGET/podman.$ext
sed_os "s/A\ remote\ CLI\ for\ Podman\:\ //g" $TARGET/podman.$ext
case $PLATFORM in
darwin|linux)
sed_os "s/Podman\\\*-remote/Podman\ for\ Mac/g" $TARGET/podman.$ext
;;
windows)
sed_os "s/Podman\\\*-remote/Podman\ for\ Windows/g" $TARGET/podman.$ext
;;
esac
fi
}
## walk the SOURCES for markdown sources
mkdir -p $TARGET
for s in $SOURCES; do
if [[ -d $s ]]; then
pub_pages $s $PUBLISHER
else
echo >&2 "Warning: $s does not exist"
fi
done
rename
|