~kirkland/ubuntu-manpage-repository/main

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
#!/bin/sh -e

###############################################################################
# This is the Ubuntu manpage repository generator and interface.
# 
# Copyright (C) 2008 Canonical Ltd.
# 
# This code was originally written by Dustin Kirkland <kirkland@ubuntu.com>,
# based on a framework by Kees Cook <kees@ubuntu.com>.
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# 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
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 
# On Debian-based systems, the complete text of the GNU General Public
# License can be found in /usr/share/common-licenses/GPL-3
###############################################################################

. ./config

# Establish some locking, to keep multiple updates from running
mkdir -p "$PUBLIC_HTML_DIR/manpages"
LOCK="$PUBLIC_HTML_DIR/manpages/UPDATE_IN_PROGRESS"
if [ -e "$LOCK" ]; then
	printf "%s\n" "ERROR: Update is currently running"
	printf "%s\n" "Lock: $LOCK"
	cat "$LOCK"
	exit 1
fi
trap "rm -f $LOCK 2>/dev/null || true" EXIT HUP INT QUIT TERM
date > $LOCK

FORCE="$1"

pkg_updated() {
	if [ "$FORCE" = "-f" -o "$FORCE" = "--force" ]; then
		return 0
	fi
	deb="$1"
	#printf "%s\n" "INFO: Looking at package [$deb]"
	name=`basename "$deb" | awk -F_ '{print $1}'`
	cache_modtime=`stat -c %Y "$PUBLIC_HTML_DIR/manpages/$dist/.cache/$name" 2>/dev/null || printf "0"`
	deb_modtime=`stat -c %Y "$DEBDIR/$deb"`
	if [ "$cache_modtime" -ge "$deb_modtime" ]; then
	        #printf "%s\n" "INFO: Skipping non-updated package [$DEBDIR/$deb]"
		return 1
	else
		return 0
	fi
}

handle_deb() {
	dist="$1"
	deb="$2"
	pkg_updated "$deb" && ./fetch-man-pages.sh "$dist" "$deb" || true
}

link_en_locale() {
	dist="$1"
	mkdir -p "$PUBLIC_HTML_DIR/manpages/$dist/en"
	for i in `seq 1 9`; do
		for j in "manpages" "manpages.gz"; do
			mkdir -p "$PUBLIC_HTML_DIR/$j/$dist/en"
			dir="$PUBLIC_HTML_DIR/$j/$dist/en/man$i"
			if [ -L "$dir" ]; then
				# link exists: we're good
				continue
			elif [ -d "$dir" ]; then
				# dir exists: mv, ln, restore
				mv -f "$dir" "$dir.bak"
				ln -s "../man$i" "$dir"
				mv -f "$dir.bak"/* "$dir"
				rmdir "$dir.bak"
			else
				# link does not exist: establish the link
				ln -s "../man$i" "$dir"
			fi
		done
	done
	return 0
}


for dist in $DISTROS; do
	export dist
	mkdir -p "$PUBLIC_HTML_DIR/manpages/$dist/.cache" "$PUBLIC_HTML_DIR/manpages.gz/$dist" || true
	link_en_locale "$dist"
	for repo in $REPOS; do
		zcat "$DEBDIR/dists/$dist/$repo/binary-$ARCH/Packages.gz" | grep "^Filename:.*\.deb$" | awk '{print $2}' | sort -u | \
			while read deb; do
				handle_deb "$dist" "$deb"
			done
	done
done

./make-sitemaps.sh