summaryrefslogtreecommitdiffstats
path: root/bin/build-docs
blob: ee8811e02736c0b562a7ef1d9a645c2f44a4320c (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
#!/bin/sh
#
# Copyright (c) 2013 Nagios Plugins Development Team
#
# Originally written by Holger Weiss <holger@zedat.fu-berlin.de>.
#
# This file is free software; the Nagios Plugins Development Team gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY, to the extent permitted by law; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

set -e
set -u

export PATH='/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin'

prefix='/home/plugins'
repository="$prefix/repositories/nagios-plugins.git"
branch='master'
guidelines="$prefix/web/work/guidelines.html"
man_dir="$prefix/web/work/man"
myself=${0##*/}

build_plugins()
{
	src_dir=$1
	dst_dir=$2

	cd "$src_dir"
	tools/setup
	./configure --prefix="$dst_dir"
	make install
	make install-root
	cd "$OLDPWD"
}

build_manpages()
{
	dst_dir=$1
	man_dir=$2

	for pattern in 'check_*' 'negate' 'urlize'
	do
		find "$man_dir" -name "$pattern" -exec rm -f '{}' '+'
		find "$dst_dir/libexec" -name "$pattern" | while read path
		do
			name=${path##*/}
			man_file="$man_dir/${name}.md"

			{
				echo "title: $name"
				echo 'parent: Manpages'
				echo '---'
				echo "# The $name Plugin"
				echo
				$path --help | sed 's/./    &/'
			} >"$man_file"
		done
	done
}

if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ]
then
	echo "Usage: $myself"
	exit 0
fi

temp_dir=$(mktemp -d "/tmp/$myself.XXXXXX")
log_file="$temp_dir/log"
exec >"$log_file" 3>&2 2>&1
trap 'tail -n 25 "$log_file" >&3; rm -rf "$temp_dir"' EXIT
set -x

src_dir="$temp_dir/src"
dst_dir="$temp_dir/dst"

git --git-dir="$repository" rev-parse --git-dir >'/dev/null'
git --git-dir="$repository" archive --prefix="$src_dir/" "$branch" | tar -x -P -f -
build_plugins "$src_dir" "$dst_dir"
build_manpages "$dst_dir" "$man_dir"
cp -p "$src_dir/doc/developer-guidelines.html" "$guidelines"

trap - EXIT
rm -rf "$temp_dir"