mulle-bootstrap
5de2fbd6
 #! /bin/sh
 #
 #   Copyright (c) 2015 Nat! - Mulle kybernetiK
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
 #   modification, are permitted provided that the following conditions are met:
 #
 #   Redistributions of source code must retain the above copyright notice, this
 #   list of conditions and the following disclaimer.
 #
 #   Redistributions in binary form must reproduce the above copyright notice,
 #   this list of conditions and the following disclaimer in the documentation
 #   and/or other materials provided with the distribution.
 #
 #   Neither the name of Mulle kybernetiK nor the names of its contributors
 #   may be used to endorse or promote products derived from this software
 #   without specific prior written permission.
 #
 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 #   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 #   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 #   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 #   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 #   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 #   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 #   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 #   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 #   POSSIBILITY OF SUCH DAMAGE.
 
512cdf62
 VERSION=0.8.1
5de2fbd6
 
 #
 # This is the main user interface to mulle-bootstrap
 # sorta like git
 #
 BOOTSTRAP_SUBDIR=.bootstrap
 
 PATH="/usr/local/libexec/mulle-bootstrap:$PATH"
 export PATH
 
8e817cc1
 #
 # simple option handling
 #
a7b563e1
 if [ "$1" = "-a" ] # silent
 then
    MULLE_BOOTSTRAP_ANSWER="NO"
    export MULLE_BOOTSTRAP_ANSWER
    shift
 fi
 
8e817cc1
 if [ "$1" = "-n" ]
 then
a7b563e1
    MULLE_BOOTSTRAP_DRY_RUN="YES"
8e817cc1
    export MULLE_BOOTSTRAP_DRY_RUN
    shift
 fi
 
3be635de
 if [ "$1" = "-v" ]
 then
28ed6b30
    if [ -z "${MULLE_BOOTSTRAP_TRACE}" ]
    then
a7b563e1
       MULLE_BOOTSTRAP_TRACE="VERBOSE"
28ed6b30
       export MULLE_BOOTSTRAP_TRACE
    fi
3be635de
    GITFLAGS="-v"
    export GITFLAGS
    shift
28ed6b30
 else
d7f96955
    if [ "$1" = "-V" ]
28ed6b30
    then
d7f96955
       if [ -z "${MULLE_BOOTSTRAP_TRACE}" ]
       then
a7b563e1
          MULLE_BOOTSTRAP_TRACE="ALL"
d7f96955
          export MULLE_BOOTSTRAP_TRACE
       fi
       GITFLAGS="-v"
28ed6b30
       export GITFLAGS
       shift
d7f96955
    else
       if [ "$1" = "-s" ] # silent
       then
          MULLE_BOOTSTRAP_TRACE=
a7b563e1
          MULLE_BOOTSTRAP_TERSE="YES"
d7f96955
          export MULLE_BOOTSTRAP_TERSE
          GITFLAGS="-q"
          export GITFLAGS
          shift
       fi
28ed6b30
    fi
3be635de
 fi
 
 
40fe269d
 usage()
 {
    cat <<EOF
a7b563e1
 usage: mulle-bootstrap [-n][-v|-s][-a] [command] [--help]
fa860fc9
        version ${VERSION}
40fe269d
 
  Specify the -h or --help option after each command to get more help.
 
28ed6b30
  Flags (-n must be first, if present)
a7b563e1
    -a        : always chose default answer to questions
40fe269d
    -n        : do nothing creative or destructive
d7f96955
    -v        : be more verbose (-V even more verbose)
40fe269d
    -s        : be more terse
 
  Common user commands:
    bootstrap : does fetch and build recursively [default]
    nomagic   : does fetch and build, but not recursively
    clean     : cleans mulle-bootstrap produced files.
 
  Common maintainer commands:
    init      : initializes a bootstrap project
    xcode     : sets up the xcodeproj settings
    tag       : tag this project and fetched repositories
 
  Specialized commands:
    build     : builds fetched repositories
    fetch     : fetches required repositories recursively.
    update    : updates repositories (pull).
 EOF
 }
 
 
8ca22e9e
 check_and_usage_and_help()
 {
    cat <<EOF
 usage: bootstrap
    There is nothing more to it.
 EOF
 }
 
 
5de2fbd6
 command=${1:-"bootstrap"}
 shift
 
 
 bootstrap()
 {
40fe269d
    if [ "$1" = "-h" -o "$1" = "--help" ]
    then
        check_and_usage_and_help >&2
        exit 1
    fi
5de2fbd6
 
    #
    # this is run when checking mulle-project itself out
    #
    if [ -f mulle-bootstrap-local-environment.sh -a -x install.sh ]
    then
       . install.sh "$@"
       export MULLE_BOOTSTRAP=mulle-bootstrap
3ed530a3
    else
512cdf62
       mulle-bootstrap-warn-scripts.sh "${BOOTSTRAP_SUBDIR}"  || fail "Ok, aborted."
5de2fbd6
    fi
 
    if [ "${DONT_RECURSE}" = "" ]
    then
40fe269d
       mulle-bootstrap-fetch.sh || exit 1
5de2fbd6
    else
40fe269d
       mulle-bootstrap-fetch.sh nonrecursive  || exit 1
5de2fbd6
    fi
40fe269d
    mulle-bootstrap-build.sh  || exit 1
5de2fbd6
 }
 
 
40fe269d
 main()
 {
28ed6b30
 
    if [ ! -d "${BOOTSTRAP_SUBDIR}" -a "${command}" != "init" ]
    then
       echo "there is no ${BOOTSTRAP_SUBDIR} here, can't continue" >&2
       exit 1
    fi
 
40fe269d
    case "${command}" in
       bootstrap)
          bootstrap "$@" || exit 1
          ;;
 
       nomagic)
          DONT_RECURSE=YES bootstrap "$@" || exit 1
          ;;
 
       build)
          mulle-bootstrap-build.sh "$@" || exit 1
          ;;
 
       clean)
          mulle-bootstrap-clean.sh "$@" || exit 1
          ;;
 
a7b563e1
       dist-clean)
          mulle-bootstrap-clean.sh "dist"  || exit 1
          ;;
 
40fe269d
       fetch)
          mulle-bootstrap-fetch.sh "$@" || exit 1
          ;;
 
       update)
          COMMAND="update" mulle-bootstrap-fetch.sh "$@" || exit 1
          ;;
 
       init)
          mulle-bootstrap-init.sh "$@" || exit 1
          ;;
 
       setup-xcode|xcode)
          mulle-bootstrap-xcode.sh "$@"|| exit 1
          ;;
 
       tag)
          mulle-bootstrap-tag.sh "$@" || exit 1
          ;;
 
fa860fc9
       version)
          echo "${VERSION}" || exit 1
          ;;
 
40fe269d
       *)
          usage >&2
          exit 1
d388168a
          ;;
40fe269d
       esac
 }
 
 main "$@"