| 1 | #!/bin/bash
|
|---|
| 2 |
|
|---|
| 3 | # GNU MediaGoblin -- federated, autonomous media hosting
|
|---|
| 4 | # Copyright (C) 2011 Free Software Foundation, Inc
|
|---|
| 5 | #
|
|---|
| 6 | # This program is free software: you can redistribute it and/or modify
|
|---|
| 7 | # it under the terms of the GNU Affero General Public License as published by
|
|---|
| 8 | # the Free Software Foundation, either version 3 of the License, or
|
|---|
| 9 | # (at your option) any later version.
|
|---|
| 10 | #
|
|---|
| 11 | # This program is distributed in the hope that it will be useful,
|
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | # GNU Affero General Public License for more details.
|
|---|
| 15 | #
|
|---|
| 16 | # You should have received a copy of the GNU Affero General Public License
|
|---|
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | # Usage: build_docs.sh <path-to-git-repo> <target-dir> [<rev-ish>]
|
|---|
| 21 |
|
|---|
| 22 | # if we encounter errors, bail out
|
|---|
| 23 | set -o errexit
|
|---|
| 24 |
|
|---|
| 25 | # FIXME - need to convert these to absolute paths
|
|---|
| 26 |
|
|---|
| 27 | # check arguments
|
|---|
| 28 | #
|
|---|
| 29 | REPO=`pwd`/$1
|
|---|
| 30 | TARGET=`pwd`/$2
|
|---|
| 31 | REVISH=$3
|
|---|
| 32 |
|
|---|
| 33 | if [[ -z "$REPO" || -z "$TARGET" ]]
|
|---|
| 34 | then
|
|---|
| 35 | echo "Usage: build_docs.sh <path-to-mediagoblin-repo> <target-dir> [<rev-ish>]"
|
|---|
| 36 | exit 1;
|
|---|
| 37 | fi
|
|---|
| 38 |
|
|---|
| 39 | if [[ -z "$REVISH" ]]
|
|---|
| 40 | then
|
|---|
| 41 | REVISH=master
|
|---|
| 42 | fi
|
|---|
| 43 |
|
|---|
| 44 | echo ">>> Testing commands...."
|
|---|
| 45 |
|
|---|
| 46 | # check commands
|
|---|
| 47 | #
|
|---|
| 48 | GIT_CMD=$(which git)
|
|---|
| 49 | if [[ -z $GIT_CMD ]]
|
|---|
| 50 | then
|
|---|
| 51 | echo "Hrmm: I can't find the git command."
|
|---|
| 52 | echo "Is git installed? Is git on your PATH?"
|
|---|
| 53 | exit 1;
|
|---|
| 54 | fi
|
|---|
| 55 |
|
|---|
| 56 | SPHINX_CMD=$(which sphinx-build)
|
|---|
| 57 | if [[ -z $SPHINX_CMD ]]
|
|---|
| 58 | then
|
|---|
| 59 | echo "Hrmm: I can't find the sphinx-build command."
|
|---|
| 60 | echo "Is Sphinx installed? Is sphinx-build on your PATH?"
|
|---|
| 61 | exit 1;
|
|---|
| 62 | fi
|
|---|
| 63 |
|
|---|
| 64 | echo "Woot: Commands tested. OK"
|
|---|
| 65 |
|
|---|
| 66 | echo ">>> Fiddling with the repository...."
|
|---|
| 67 | # create the directory and clone the repository if it doesn't exist
|
|---|
| 68 | #
|
|---|
| 69 | if [[ -d "$REPO" ]]
|
|---|
| 70 | then
|
|---|
| 71 | echo "Woot: $REPO already created."
|
|---|
| 72 | else
|
|---|
| 73 | echo ">>> Creating $REPO...."
|
|---|
| 74 | mkdir -p $REPO
|
|---|
| 75 | cd $REPO
|
|---|
| 76 | "$GIT_CMD" clone git://gitorious.org/mediagoblin/mediagoblin.git mediagoblin
|
|---|
| 77 | echo "Woot: $REPO created."
|
|---|
| 78 | echo "Note: Use $REPO/mediagoblin for <path-to-mediagoblin-repo> next time."
|
|---|
| 79 | fi
|
|---|
| 80 |
|
|---|
| 81 | cd $REPO/mediagoblin
|
|---|
| 82 |
|
|---|
| 83 | # update the repository
|
|---|
| 84 | #
|
|---|
| 85 | echo ">>> Checking out $REVISH...."
|
|---|
| 86 | "$GIT_CMD" checkout "$REVISH"
|
|---|
| 87 | if [[ $? -ne 0 ]]
|
|---|
| 88 | then
|
|---|
| 89 | echo "Hrmm: revish $REVISH does not exist."
|
|---|
| 90 | exit 1;
|
|---|
| 91 | fi
|
|---|
| 92 |
|
|---|
| 93 | echo ">>> Pulling new changes...."
|
|---|
| 94 | echo "$GIT_CMD pull -t origin $REVISH"
|
|---|
| 95 | "$GIT_CMD" pull -t origin $REVISH
|
|---|
| 96 |
|
|---|
| 97 | if [[ $? -ne 0 ]]
|
|---|
| 98 | then
|
|---|
| 99 | echo "Hrmm: Couldn't pull $REVISH."
|
|---|
| 100 | exit 1;
|
|---|
| 101 | fi
|
|---|
| 102 |
|
|---|
| 103 | echo ">>> Building the docs...."
|
|---|
| 104 | cd docs/
|
|---|
| 105 | make clean
|
|---|
| 106 | make html
|
|---|
| 107 |
|
|---|
| 108 | if [[ -d "$TARGET" ]]
|
|---|
| 109 | then
|
|---|
| 110 | echo "Woot: $TARGET exists."
|
|---|
| 111 | else
|
|---|
| 112 | echo "Woot: Creating $TARGET...."
|
|---|
| 113 | mkdir -p "$TARGET"
|
|---|
| 114 | fi
|
|---|
| 115 |
|
|---|
| 116 | echo ">>> Copying all the files over to $TARGET...."
|
|---|
| 117 | cp -r _build/html/* $TARGET
|
|---|
| 118 |
|
|---|
| 119 | echo "Woot: Done!"
|
|---|