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 @ 1575:42618fc5ab46

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