To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / extra / soundsoftware / extract-docs.sh @ 411:e7ba81c8dc5a

History | View | Annotate | Download (4.07 KB)

1 203:1e55195bca45 chris
#!/bin/bash
2
3
# Run this script from anywhere
4
5
# Enumerate Hg repos; make sure they're up to date; extract docs for
6
# each
7
8
hgdir="/var/hg"
9
docdir="/var/doc"
10 223:c3544e9fd588 chris
logfile="/var/www/test-cannam/log/extract-docs.log"
11
12
redgrp="redmine"
13 203:1e55195bca45 chris
14 218:292cde42265a chris
apikey=""
15
apihost=""
16
apiuser=""
17
apipass=""
18
19 203:1e55195bca45 chris
progdir=$(dirname $0)
20
case "$progdir" in
21
    /*) ;;
22
    *) progdir="$(pwd)/$progdir" ;;
23
esac
24
25 411:e7ba81c8dc5a chris
types="doxygen javadoc matlabdocs" # Do Doxygen first (it can be used for Java too)
26 203:1e55195bca45 chris
27
for x in $types; do
28
    if [ ! -x "$progdir/extract-$x.sh" ]; then
29
	echo "Helper script not available: $progdir/extract-$x.sh"
30
	exit 1
31
    fi
32
done
33
34 218:292cde42265a chris
enable_embedded()
35
{
36
    p="$1"
37 228:3c084a25d8ab chris
    if [ -n "$apikey" ]; then
38
	if [ -n "$apiuser" ]; then
39
	    sudo -u docgen curl -u "$apiuser":"$apipass" "http://$apihost/sys/projects/$p/embedded.xml?enable=1&key=$apikey" -d ""
40
	else
41
	    sudo -u docgen curl "http://$apihost/sys/projects/$p/embedded.xml?enable=1&key=$apikey" -d ""
42
	fi
43
    else
44
	echo "Can't enable Embedded, API not configured" 1>&2
45 218:292cde42265a chris
    fi
46
}
47
48 223:c3544e9fd588 chris
# We want to ensure the doc extraction is done by the unprivileged
49
# user docgen, which is not a member of any interesting group
50
#
51
# To this end, we create the tmpdir with user docgen and group
52
# www-data, and use the www-data user to pull out an archive of the Hg
53
# repo tip into a location beneath that, before using the docgen user
54
# to extract docs from that location and write them into the tmpdir
55
56
# Same tmpdir for each project: we delete and recreate to avoid
57
# cleanup duty from lots of directories being created
58
#
59
tmpdir=$(mktemp -d "$docdir/tmp_XXXXXX")
60
61
fail()
62
{
63
    message="$1"
64
    echo "$message" 1>&2
65
    case "$tmpdir" in
66
	*/tmp*) rm -rf "$tmpdir";;
67
	*);;
68
    esac
69
    exit 1
70
}
71
72
case "$tmpdir" in
73
    /*) ;;
74
    *) fail "Temporary directory creation failed";;
75
esac
76
77
chown docgen.www-data "$tmpdir" || fail "Temporary directory ownership change failed"
78
chmod g+rwx "$tmpdir" || fail "Temporary directory permissions change failed"
79
80 203:1e55195bca45 chris
for projectdir in "$hgdir"/* ; do
81
82
    if [ -d "$projectdir" ] && [ -d "$projectdir/.hg" ]; then
83
84 223:c3544e9fd588 chris
	if ! sudo -u www-data hg -R "$projectdir" -q update; then
85
	    echo "Failed to update Hg in $projectdir, skipping" 1>&2
86
	    continue
87
	fi
88
89 203:1e55195bca45 chris
	project=$(basename "$projectdir")
90
91 223:c3544e9fd588 chris
	tmptargetdir="$tmpdir/doc"
92
	snapshotdir="$tmpdir/hgsnapshot"
93 203:1e55195bca45 chris
94 223:c3544e9fd588 chris
	rm -rf "$tmptargetdir" "$snapshotdir"
95
96 226:5b028aef59a7 chris
	mkdir -m 770 "$tmptargetdir" || fail "Temporary target directory creation failed"
97
	chown docgen.www-data "$tmptargetdir" || fail "Temporary target directory ownership change failed"
98 223:c3544e9fd588 chris
99
	mkdir -m 770 "$snapshotdir" || fail "Snapshot directory creation failed"
100
	chown docgen.www-data "$snapshotdir" || fail "Snapshot directory ownership change failed"
101
102
	hgparents=$(sudo -u www-data hg -R "$projectdir" parents)
103
	if [ -z "$hgparents" ]; then
104
	    echo "Hg repo at $projectdir has no working copy (empty repo?), skipping"
105
	    continue
106
	else
107
	    echo "Found non-empty Hg repo: $projectdir for project $project"
108
	fi
109
110
	if ! sudo -u www-data hg -R "$projectdir" archive -r tip -t files "$snapshotdir"; then
111
	    echo "Failed to pick archive from $projectdir, skipping" 1>&2
112
	    continue
113
	fi
114 203:1e55195bca45 chris
115
	targetdir="$docdir/$project"
116
117 223:c3544e9fd588 chris
	echo "Temporary dir is $tmpdir, temporary doc dir is $tmptargetdir, snapshot dir is $snapshotdir, eventual target is $targetdir"
118 203:1e55195bca45 chris
119
	for x in $types; do
120 226:5b028aef59a7 chris
	    if sudo -u docgen "$progdir/extract-$x.sh" "$project" "$snapshotdir" "$tmptargetdir" >> "$logfile" 2>&1; then
121
		break
122
	    else
123 203:1e55195bca45 chris
		echo "Failed to extract via type $x"
124
	    fi
125
	done
126
127 223:c3544e9fd588 chris
        if [ -f "$tmptargetdir/index.html" ]; then
128 203:1e55195bca45 chris
	    echo "Processing resulted in an index.html being created, looks good!"
129
	    if [ ! -d "$targetdir" ] || [ ! -f "$targetdir/index.html" ]; then
130 223:c3544e9fd588 chris
		echo "This project hasn't had doc extracted before: enabling Embedded"
131 218:292cde42265a chris
		enable_embedded "$project"
132 203:1e55195bca45 chris
	    fi
133
134
	    if [ -d "$targetdir" ]; then
135
		mv "$targetdir" "$targetdir"_"$$" && \
136 223:c3544e9fd588 chris
		    mv "$tmptargetdir" "$targetdir" && \
137 203:1e55195bca45 chris
		    rm -rf "$targetdir"_"$$"
138 223:c3544e9fd588 chris
		chgrp -R "$redgrp" "$targetdir"
139 203:1e55195bca45 chris
	    else
140 223:c3544e9fd588 chris
		mv "$tmptargetdir" "$targetdir"
141
		chgrp -R "$redgrp" "$targetdir"
142 203:1e55195bca45 chris
	    fi
143 228:3c084a25d8ab chris
	else
144
	    echo "Processing did not result in an index.html being created"
145 203:1e55195bca45 chris
	fi
146
    fi
147
done
148
149 223:c3544e9fd588 chris
rm -rf "$tmpdir"