To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / extra / soundsoftware / extract-docs.sh @ 400:4ad6499d7998
History | View | Annotate | Download (4.06 KB)
| 1 |
#!/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 |
logfile="/var/www/test-cannam/log/extract-docs.log" |
| 11 |
|
| 12 |
redgrp="redmine" |
| 13 |
|
| 14 |
apikey="" |
| 15 |
apihost="" |
| 16 |
apiuser="" |
| 17 |
apipass="" |
| 18 |
|
| 19 |
progdir=$(dirname $0) |
| 20 |
case "$progdir" in |
| 21 |
/*) ;; |
| 22 |
*) progdir="$(pwd)/$progdir" ;; |
| 23 |
esac |
| 24 |
|
| 25 |
types="doxygen javadoc" # Do Doxygen first (it can be used for Java too) |
| 26 |
|
| 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 |
enable_embedded() |
| 35 |
{
|
| 36 |
p="$1" |
| 37 |
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 |
fi |
| 46 |
} |
| 47 |
|
| 48 |
# 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 |
for projectdir in "$hgdir"/* ; do |
| 81 |
|
| 82 |
if [ -d "$projectdir" ] && [ -d "$projectdir/.hg" ]; then |
| 83 |
|
| 84 |
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 |
project=$(basename "$projectdir") |
| 90 |
|
| 91 |
tmptargetdir="$tmpdir/doc" |
| 92 |
snapshotdir="$tmpdir/hgsnapshot" |
| 93 |
|
| 94 |
rm -rf "$tmptargetdir" "$snapshotdir" |
| 95 |
|
| 96 |
mkdir -m 770 "$tmptargetdir" || fail "Temporary target directory creation failed" |
| 97 |
chown docgen.www-data "$tmptargetdir" || fail "Temporary target directory ownership change failed" |
| 98 |
|
| 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 |
|
| 115 |
targetdir="$docdir/$project" |
| 116 |
|
| 117 |
echo "Temporary dir is $tmpdir, temporary doc dir is $tmptargetdir, snapshot dir is $snapshotdir, eventual target is $targetdir" |
| 118 |
|
| 119 |
for x in $types; do |
| 120 |
if sudo -u docgen "$progdir/extract-$x.sh" "$project" "$snapshotdir" "$tmptargetdir" >> "$logfile" 2>&1; then |
| 121 |
break |
| 122 |
else |
| 123 |
echo "Failed to extract via type $x" |
| 124 |
fi |
| 125 |
done |
| 126 |
|
| 127 |
if [ -f "$tmptargetdir/index.html" ]; then |
| 128 |
echo "Processing resulted in an index.html being created, looks good!" |
| 129 |
if [ ! -d "$targetdir" ] || [ ! -f "$targetdir/index.html" ]; then |
| 130 |
echo "This project hasn't had doc extracted before: enabling Embedded" |
| 131 |
enable_embedded "$project" |
| 132 |
fi |
| 133 |
|
| 134 |
if [ -d "$targetdir" ]; then |
| 135 |
mv "$targetdir" "$targetdir"_"$$" && \ |
| 136 |
mv "$tmptargetdir" "$targetdir" && \ |
| 137 |
rm -rf "$targetdir"_"$$" |
| 138 |
chgrp -R "$redgrp" "$targetdir" |
| 139 |
else |
| 140 |
mv "$tmptargetdir" "$targetdir" |
| 141 |
chgrp -R "$redgrp" "$targetdir" |
| 142 |
fi |
| 143 |
else |
| 144 |
echo "Processing did not result in an index.html being created" |
| 145 |
fi |
| 146 |
fi |
| 147 |
done |
| 148 |
|
| 149 |
rm -rf "$tmpdir" |