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